Jump to content


Connect to a server, send packets, receive packets.

  • Please log in to reply
2 replies to this topic

#1 soadlink

  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 07 September 2006 - 07:53 PM


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
Enjoy the silence

#2 R_P

  • Members
  • PipPipPip
  • Advanced Member
  • 98 posts

Posted 07 September 2006 - 09:04 PM

Sure. Take a look at this tutorial: http://www.phpfreaks...orials/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.
Pro in: Win2K3S | Apache2 | PHP5 | Perl5 | MySQL | MSSQL | Firefox | Photoshop
Student of: Ubuntu6 | Java | C | VB.NET | ASP.NET
Developer: Roddzilla Webstudios, Burrson CG, DVIDSHUB, The Four Nations
Student: Georgia Tech, Georgia Tech College of Computing

#3 soadlink

  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 08 September 2006 - 11:15 PM

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.
Enjoy the silence

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users