[php]php里使用SOCKET通信

2013/2/21 11:07:00  人气 2897    编程语言区  
class socketClient{
public $$socketConnection;
public $$Connection;
public $$changed_sockets;

public function __construct($$ipAddress,$$port){
$$this->socketConnection = socket_*(AF_INET, SOCK_STREAM, SOL_TCP);
$$this->Connection = socket_connect($$this->socketConnection,$$ipAddress, $$port);
$$this->changed_sockets = array($$this->socketConnection);
}

public function sendMsg($$msg){
socket_write($$this->socketConnection, $$msg);
}
public function recv(){
$$num_changed_sockets = socket_*($$this->changed_sockets, $$write = NULL, $$except = NULL, NULL);
foreach($$this->changed_sockets as $$socket) {
$$bytes = @socket_recv($$this->socketConnection, $$buffer, 2048, 0);
return $$buffer;
}
}
public function close(){
socket_close($$this->socketConnection);
}
}

发表回复

   


  通知楼主
暂无回复!

朋友圈|阅读|美图|切换

琴剑听月 微信:qjtywwx 4月26日(五) 22:26
©2015 数据时代 京ICP备13050724号