Jump to content


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


Connect to a server, send packets, receive packets.

Recommended Posts


I was wondering (since PHP is very powerful) if it was possible to connect to a certain IP and port of a server that accepts connections on that port, send strings of data, and receive data that the server sends. <-- all of course with php.

So I am basically looking to see if there is a Winsock 6.0 (a visual basic control) equivelent with PHP code.

Hope that explains it, thanks!  ;D

Share this post

Link to post
Share on other sites
Sure. Take a look at this tutorial: http://www.phpfreaks.com/tutorials/50/0.php

You need to have the php sockets module compiled with PHP. The tutorial will then show you how to open, connect to, and listen on a socket.

Share this post

Link to post
Share on other sites
Thanks for the help! I have played with this tutorial, and I know I coded my test page correctly, but when I load it the page just sits there. Is this because the php sockets module wasnt compiled as you said it must be?

Here is my code:

$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$connection = socket_connect($socket,'gpcm.gamespy.com',29900);
while($data = socket_read($socket,2046,PHP_NORMAL_READ)) //listen for any data, and echo that data out
echo $data;

After connecting, that server (gpcm.gamespy.com:29900) should automatically send back a reply without the client sending anything. But I get nothing, just a page that appears to be loading forever.

Share this post

Link to post
Share on other sites


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.