socket programming help
Posted: Wed Jul 16, 2003 7:09 am
Hello everybody,
Its been a while i have'nt worked on my project.Back here again.
I've written a small program where it requests the user to input some text through an HTML form and this creates a connection to the other pc in the network via the ip-address i mentioned in my code.The user i/p is sent from my machine to the other machine and return the value from the other machine(the same string but in reversed order) and is displayed to the user on an HTML page.
Errors: I dont get any text in the reverse order.
Windows NT is the environment.
Heres my code:
Its been a while i have'nt worked on my project.Back here again.
I've written a small program where it requests the user to input some text through an HTML form and this creates a connection to the other pc in the network via the ip-address i mentioned in my code.The user i/p is sent from my machine to the other machine and return the value from the other machine(the same string but in reversed order) and is displayed to the user on an HTML page.
Errors: I dont get any text in the reverse order.
Windows NT is the environment.
Heres my code:
Code: Select all
<html>
<head
</head>
<body>
<?php
//Form not yet submitted
if (!$submit)
{
?>
<form action="<? echo $PHP_SELF; ?>" method="post">
Enter some text:<br>
<input type="Text" name="message" size="15"><input type="submit" name="submit" value="send">
</form>
<?
}
else{
//form submitted
//Where is the socket server?
$host="heres the ip-address of the machine I'm connecting";
$port = portno;
//create a socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die ("could not create socket\n" );
//connect to server
$result = socket_connect($socket, $host, $port) or die ("could not connect to server\n" );
socket_read ($socket, 1024) or die ("could not read server response\n" );
//send string to server
socket_write($socket, $message. strlen($message)) or die ("could not send data to server\n" );
//get server response
socket_read ($socket, 1024) or die ("could not read server response\n" );
//end session
socket_write($socket, "END", 3) or die ("could not end session\n" );
//close socket
socket_close($socket);
//clean up result
$result = trim($result);
$result = substr($result, 0, strlen($result)-1);
//print result to browser
?>
Server said: <b><? echo $result; ?></b>
<?
}
?>
</body>
</html>
Report Post | IP: Logged