skliz4rel Posted April 19, 2012 Share Posted April 19, 2012 i have been working to works. but any time i use the method socket_read(); or socket_write(); my apache server gives me an error undefined method pls want could be responsible for this error. i am quite sure of the syntax Quote Link to comment https://forums.phpfreaks.com/topic/261247-sockets/ Share on other sites More sharing options...
requinix Posted April 19, 2012 Share Posted April 19, 2012 That's weird but not impossible (clearly). Before we start looking at the more unusual explanations, can you post the code you're having problems with? Quote Link to comment https://forums.phpfreaks.com/topic/261247-sockets/#findComment-1338783 Share on other sites More sharing options...
skliz4rel Posted April 23, 2012 Author Share Posted April 23, 2012 this is the code <?php $PORT = 1234; //the port on which we are connecting to the "remote" machine $HOST = "127.0.0.1"; //the ip of the remote machine (in this case it's the same machine) $sock = socket_create(AF_INET,SOCK_STREAM, 1) //Creating a TCP socket or die("error: could not create socket\n"); $succ = socket_connect($sock, $HOST, $PORT) //Connecting to to server using that socket or die("error: could not connect to host\n"); $text = "Hello, Java!"; //the text we want to send to the socket_write($sock, $text . "\n", strlen($text) + 1) //Writing the text to the socket or die("error: failed to write to socket\n"); $reply = socket_read($sock, 10000, PHP_NORMAL_READ) //Reading the reply from socket or die("error: failed to read from socket\n"); echo $reply; ?> sorry i think i posted the wrong message. This is the rite error message. Warning: socket_create() [function.socket-create]: Unable to create socket [0]: The requested protocol has not been configured into the system, or no implementation for it exists. in C:\wamp\www\socket\client.php on line 4 i am trying to use my java and php code to communicate through socket. But i am having problems with socket at php level. Quote Link to comment https://forums.phpfreaks.com/topic/261247-sockets/#findComment-1339719 Share on other sites More sharing options...
requinix Posted April 23, 2012 Share Posted April 23, 2012 What does echo getprotobyname("tcp"); output? Quote Link to comment https://forums.phpfreaks.com/topic/261247-sockets/#findComment-1339744 Share on other sites More sharing options...
skliz4rel Posted April 24, 2012 Author Share Posted April 24, 2012 The output is 6. Bro what does it mean? Quote Link to comment https://forums.phpfreaks.com/topic/261247-sockets/#findComment-1340164 Share on other sites More sharing options...
requinix Posted April 24, 2012 Share Posted April 24, 2012 $sock = socket_create(AF_INET,SOCK_STREAM, 1) That 1 there is a number corresponding to the TCP protocol. At least it's "supposed" to be. On your system TCP is actually 6. I just realized there's a constant you can use instead of the function call, so the proper way of writing that code above would be $sock = socket_create(AF_INET,SOCK_STREAM, SOL_TCP) Quote Link to comment https://forums.phpfreaks.com/topic/261247-sockets/#findComment-1340174 Share on other sites More sharing options...
skliz4rel Posted April 26, 2012 Author Share Posted April 26, 2012 Thanks alot, I would try that Quote Link to comment https://forums.phpfreaks.com/topic/261247-sockets/#findComment-1340549 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.