Jump to content

Need help with a Socket connection, Please


elentz

Recommended Posts

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!

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;
     }
}
?>

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.