Jump to content

soket_write


alin19

Recommended Posts

i have a problem with this code, it connects to the server, read's that it is connected, read's 'username' and then the server wait for a username to be inserted,

i have a soket_write there but i think that the server waits for the confirmation that line has ended, and i can't figure it out\

 

this is what i get:

Connected

 

♣User:

sa facut trimiterea de user^C

 

 

 

<?php
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($sock,"127.0.0.1", 9191);
socket_set_block($sock);

if (false === ($line = socket_read($sock, 2048)))                                              //conected
            echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
else
	echo $line."\r\n";

if (false === ($line = socket_read($sock, 2048)))                            //username
            echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
else
	echo $line."\r\n";


sleep(2);
$request = 'GET / HTTP/1.1' . "\r\n" .
           'Host: example.com' . "\r\n\r\n";

if (true ==socket_write($sock, $request)) 
echo "sa facut trimiterea de user";
else 
{
echo "a aparut eroare la trimitere user";
break;
}

if (false === ($line = socket_read($sock, 2048)))    //password
            echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
else
	echo $line."\r\n";


sleep(2);
$parola=""."\r\n";

if (socket_send  ($sock, $user, strlen ($user),0))
echo "sa facut trimiterea";
else 
echo "a aparut eroare la trimitere de parola";


while (true)
{
$line = trim(socket_read($sock, 900));
echo $line."\r\n";

}

?>
?>

Link to comment
https://forums.phpfreaks.com/topic/122991-soket_write/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.