i have a client and a server using uniform server and im using sockets to connect them.
i would like to be able to input information from say a form on the client side, send it to the server, the server would then input this data and send it back as an html table to view on the client side. how would i go about this?
i have the server sending back basic html but not what is typed into the form.
i have this code for the server

// set some variables
$host = "localhost";
$port = 10010;

// don't timeout!

// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");

// bind socket to port
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");

// start listening for connections
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");

// accept incoming connections
// spawn another socket to handle communication
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");

// read client input
$input = socket_read($spawn, 1024);

// clean up input string
$input = trim($input);

//$output = $input . "\n";

//$output = $input;

$output = "<table colour = &quot; red &quot; border = &quot; 1 &quot;>
<caption> <strong>Table Caption</strong></caption>
<thead> <tr> <th> head col 1 </th> <th> $input  </th>
</tr> </thead> <tfoot> <tr>
<th> Total </th> <th> $input </th>
<tbody> <tr>
<td> Sausage</td> <td> £4.21 </td> </tr>
<tr> <td> Mash </td> <td> £1.13</td>

socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");

// close sockets

and this code client side

if(isset($_POST)) {
$str = $_POST["fname"];
<form action="<?=$_SERVER;?>" method="post">
<input type="text" name="fname" value="" />
<input type="submit" name="submit" value="Click Me">

function do_it($str)
// set some variables
$host = "localhost";
$port = 10010;

// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
$ret = socket_connect($socket, $host, $port);
$str = $str . "\n";
socket_write($socket, $str);
$input = socket_read($socket,1024);
$input = trim($input);

echo $input;





Try to telnet into your socket to see if it is working as expected or not.

telnet host port
type something
see response

It would probably kill the listening socket on the first key press, since its just listening for the first read and telnet will send as you type (unless you specify not to).

But you should get an idea of how its working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.