[php]php里使用SOCKET通信
2013/2/21 11:07:00 人气 3196 编程语言区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);
}
}
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);
}
}
18
暂无回复!
发表回复