here is my code and this work perfectly it sends the message. but server.php doesnt receive it. now if I use javascript and html5 and send to ws://localhost:8000/instantchat/server.php it works of course. I am guessing I need to specify the server.php file on the socket_connect function somehow. If I change localhost with the ws URL or just with a direct path it will fail to look up host so it wont connect. any ideas how to do this? I did go to php dot net and looked pretty much everywhere on google. Any help please will be greatly appreciated
<?php
if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
echo "Socket created \n";
//Connect socket to remote server
if(!socket_connect($sock , 'localhost' , 8000))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not connect: [$errorcode] $errormsg \n");
}
echo "Connection established \n";
$message = array( 'action' => 'chat_text' , 'user_id' => '4' , 'chat_text' => '');
$message = json_encode($message);
//Send the message to the server
if( !socket_send ( $sock , $message , '55' , 0))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not send data: [$errorcode] $errormsg \n");
} else echo "Message send successfully \n";