Reputation: 65
I need to connect with a server of another company. they send me a manual that says: ........................................................................................................
then send request as
/connectToMe?user=abc&key=539&cid=153648&code=5586
Simply write above line in socket and do not close the socket. for getting the response you must use Buffer reader in socket programming.
sample responce code:
cid::status:description
........................................................................................................
Now, the problem is, I never use buffer reader and I don't have any idea about socket programming. But I have to do this. I've googled for php socket connection and found this:
$host = "10.7.4.30";
$port = 91;
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
$result = socket_listen($socket, SOMAXCONN) or die("Could not set up socket listener\n");
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
$input = socket_read($spawn, 10000, PHP_NORMAL_READ) or die("Could not read input\n");
echo $input;
$output = "Hello PHP";
socket_write($spawn,$output."\n", strlen($output) + 1) or die("Could not write output\n");
socket_close($spawn);
socket_close($socket);
but this shows, unable to bind address[99].
* I need to know how to connect to that server.
* how to request any data in their given format
* how to read the response code.
please help me. give some sample code or concept or some tutorial links.
Thanks.
Upvotes: 1
Views: 2009
Reputation: 65
Thanks,
I got the solution on the following link.
http://www.codeproject.com/Tips/418814/Socket-Programming-in-PHP
Upvotes: 2
Reputation: 359
Have you tried going through the PHP Documentation?
There's a client connection example. It shows how to connect to a socket, and how to read data back from the TCP/IP socket.
Upvotes: 0