elentz Posted April 15, 2007 Share Posted April 15, 2007 I need to connect to a server. The server is a phone system. It has a Socket server running that I need to connect to. The very first message to the server must be in this format: <byte_count><Socket_Type><Password><0x00[<AppNAme>0x00] The two most important ate the Byte_Count and the Socket_Type. From the manufacturer info the: Byte Count: Indicates the byte count for the data being passed Socket_Type : Passed as hex 84 (0x84) The Password and Appname are not needed or required. So How do I connect using this format? So far I have this: $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); //make the socket $connection = socket_connect($socket,'192.168.1.230',4000); //connect to the server while($data = socket_read($socket,2046,PHP_NORMAL_READ)) //listen for any data, and echo that data out { echo $data; } Once the connection is made the server will send back call information after some other information. Right now I would be happy to get the records onto the screen to see that I have connected. My goal is to eventually try to get the recieved data into a MySql database. Can someone give me a hand here? Thanks Alot! Link to comment https://forums.phpfreaks.com/topic/47097-need-help-with-a-socket-connection-please/ Share on other sites More sharing options...
Glyde Posted April 15, 2007 Share Posted April 15, 2007 Try: <?php set_time_limit(0); $socket = fsockopen("192.168.1.230", 4000, $errNo, $errStr); if (!$socket) die("[ Error ($errNo) ] - Unable to connect to host." . $errStr ? " " . $errStr : ""); else { $dataToSend ="<byte_count><socket_type><password><0x00[<AppName>0x00]>"; fputs($socket, $dataToSend, strlen($dataToSend)); while (1) { $tmpResponse = fgets($socket, 1024); print $tmpResponse; } } ?> Link to comment https://forums.phpfreaks.com/topic/47097-need-help-with-a-socket-connection-please/#findComment-229715 Share on other sites More sharing options...
elentz Posted April 15, 2007 Author Share Posted April 15, 2007 Thanks for the reply Glyde. I don't think I am doing something right. When I use your code All I get is a 404 error. I should be able to just execute that code from a browser on a server on that network shouldn't I? Thanks Link to comment https://forums.phpfreaks.com/topic/47097-need-help-with-a-socket-connection-please/#findComment-229741 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.