各位达人好,我的问题如下
这是我网上找的一段代码
<?php
/** *//***
* @project:socket类
* @license:GPL
* @author: [email protected]星期八
* @description:PHP Socket协议异步通信
* @file:socket.class.php
* @created date:Fri Apr 25 12:22:33 CST 2008
* @last modified :
***/
class sockets
{
public $host;//通信地址
public $port;//通信端口
public $limitTime=0;//连接超时时间
public $backlog=3;//请求队列中允许的最大请求数
private $socket=null;
private $result=null;
private $spawn=null;
private $input=null;
//构造函数
public function __construct()
{
set_time_limit($this->limitTime);
$this->socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
}
//创建Socket连接,监听外部连接
public function socket_bind_listen()
{
$this->result = socket_bind($this->socket, $this->host, $this->port) or die("Could not bind to socket\n");
$this->result = socket_listen($this->socket, $this->backlog) or die("Could not set up socket listener\n");
}
//接受请求连接,调用socket处理信息
public function accept_client()
{
$this->spawn = socket_accept($this->socket) or die("Could not accept incoming connection\n");
$msg = "Welcome to the Test Server";
socket_write($this->spawn,serialize($this->spawn), strlen($msg));
}
// 读取客户端输入
public function read_client()
{
$this->input = socket_read($this->spawn, 2048, PHP_NORMAL_READ) or die("Could not read input\n");
}
// 处理客户端输入并返回数据
public function write_client()
{
socket_write($this->spawn, $this->input, strlen ($this->input)) or die("Could not write output\n");
}
//析构函数
public function __destruct()
{
socket_close($this->spawn);
socket_close($this->socket);
}
}
$socket_test=new sockets();
$socket_test->host="localhost";
$socket_test->port="12345";
$socket_test->socket_bind_listen();
$socket_test->accept_client();
//$socket_test->read_client();
//$socket_test->write_client();?>可是我在打开服务器,打开客户端,关闭客户端,关闭服务端,几个流程之后出现了
通常每个套接字地址(协议/网络地址/端口)只允许使用一次 的错误,可是我释放资源了,是不是我释放的不对
谁能告诉我,谢谢
这是我网上找的一段代码
<?php
/** *//***
* @project:socket类
* @license:GPL
* @author: [email protected]星期八
* @description:PHP Socket协议异步通信
* @file:socket.class.php
* @created date:Fri Apr 25 12:22:33 CST 2008
* @last modified :
***/
class sockets
{
public $host;//通信地址
public $port;//通信端口
public $limitTime=0;//连接超时时间
public $backlog=3;//请求队列中允许的最大请求数
private $socket=null;
private $result=null;
private $spawn=null;
private $input=null;
//构造函数
public function __construct()
{
set_time_limit($this->limitTime);
$this->socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
}
//创建Socket连接,监听外部连接
public function socket_bind_listen()
{
$this->result = socket_bind($this->socket, $this->host, $this->port) or die("Could not bind to socket\n");
$this->result = socket_listen($this->socket, $this->backlog) or die("Could not set up socket listener\n");
}
//接受请求连接,调用socket处理信息
public function accept_client()
{
$this->spawn = socket_accept($this->socket) or die("Could not accept incoming connection\n");
$msg = "Welcome to the Test Server";
socket_write($this->spawn,serialize($this->spawn), strlen($msg));
}
// 读取客户端输入
public function read_client()
{
$this->input = socket_read($this->spawn, 2048, PHP_NORMAL_READ) or die("Could not read input\n");
}
// 处理客户端输入并返回数据
public function write_client()
{
socket_write($this->spawn, $this->input, strlen ($this->input)) or die("Could not write output\n");
}
//析构函数
public function __destruct()
{
socket_close($this->spawn);
socket_close($this->socket);
}
}
$socket_test=new sockets();
$socket_test->host="localhost";
$socket_test->port="12345";
$socket_test->socket_bind_listen();
$socket_test->accept_client();
//$socket_test->read_client();
//$socket_test->write_client();?>可是我在打开服务器,打开客户端,关闭客户端,关闭服务端,几个流程之后出现了
通常每个套接字地址(协议/网络地址/端口)只允许使用一次 的错误,可是我释放资源了,是不是我释放的不对
谁能告诉我,谢谢
建议 perl python