本文主要和大家分享PHP中Socket简单使用方法,希望能帮助到大家。
<?php /*socket收发数据 @host(string) socket服务器IP @post(int) 端口 @str(string) 要发送的数据 @back 1|0 socket端是否有数据返回 返回true|false|服务端数据 */ function sendSocketMsg($host,$port,$str,$back=0){ echo '**************************'; $socket = socket_create(AF_INET,SOCK_STREAM,0); if ($socket < 0) return false; $result = @socket_connect($socket,$host,$port); if ($result == false)return false; socket_write($socket,$str,strlen($str)); socket_shutdown($socket); if($back!=0){ $input = socket_read($socket,5000); socket_close ($socket); return $input; }else{ socket_close ($socket); return true; }} $host = '192.168.1.100'; $post = 12299; $str = '{"@type":"xxx","args":[{"@type":"xxx","userInfo":{"nickname":"nickname", "phoneNo":"123143345345","roleType":"USER"}}],"methodName":"registerUser","serviceInterface":"xxx"}'; $back = 1; echo sendSocketMsg($host,$post,$str,$back);
相关推荐:
以上就是PHP中Socket简单使用方法的详细内容,更多请关注php中文网其它相关文章!
已抢16494个
抢已抢49441个
抢已抢16502个
抢已抢8720个
抢已抢4351个
抢已抢4258个
抢