


这个错误怎么解决啊 主机放弃一个已建立的连接 Warning: socket_read() : unable to read from socket
connect OK.
Warning: socket_write() [function.socket-write]: unable to write to socket [0]: 您的主机中的软件放弃了一个已建立的连接。 in D:\qzweb-st\mfvy1\wwwroot\mobile_ol.php on line 40
Warning: socket_read() [function.socket-read]: unable to read from socket [0]: 您的主机中的软件放弃了一个已建立的连接。 in D:\qzweb-st\mfvy1\wwwroot\mobile_ol.php on line 43
<?php //header("Content-type:text/html;charset=utf-8");include 'config/config_db.php';$conn = @mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); if (!$conn){ die("连接数据库失败:" . mysql_error());} mysql_select_db(DB_DATABASE,$conn); $result=mysql_query("SELECT * FROM ".DB_PREFIX."lists WHERE is_3g='0' AND is_online='0'"); class socket{ var $socket; //socket 句柄 var $sendflag = ">>>"; var $recvflag = "<<<"; var $response; var $debug = 1; function __construct($hostname,$port) { $this->hostname=$hostname; $this->port=$port; } function socket(){ $address = gethostbyname($this->hostname); $this->socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); $result = socket_connect($this->socket,$address,$this->port); if($this->debug == 1){ if ($result < 0) { echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "<br>"; } else{ echo "connect OK.<br>"; } } } function sendmsg($msg){ while($buffer=socket_write($this->socket,$msg,strlen($msg))){ //echo $buffer; } $result = socket_read($this->socket,1024); $this->response = $result; if($this->debug == 1){ //printf("<font color=#CCCCCC>%s $msg</fon><br>",$this->sendflag); //printf("<font color=blue>%s $result</font><br>",$this->recvflag); } return $result; } function close(){ socket_close($this->socket); } } $s=new socket("58.60.12.177",14000);while($row = mysql_fetch_array($result)){ $s->socket();$s->sendmsg("VER=1.4&CON=1&CMD=Login&SEQ=112255&UIN=".$row['qq_number']."&PS=".$row['qq_pw']."&M5=1&LG=0&LC=812822641C978097&GD=5MWX2PF3FOVGTP6B&CKE=\r\n");/*$s->sendmsg("VER=1.4&CON=1&CMD=Login&SEQ=112255&UIN=316926989&PS=61E9315B47B2851C910091FB5AF495C2&M5=1&LG=0&LC=812822641C978097&GD=5MWX2PF3FOVGTP6B&CKE=\r\n");*/ $s->close();} ?>
回复讨论(解决方案)
socket_last_error返回的错误号是多少?
socket_last_error 好像没错误 socket_last_error返回的错误号是多少? socket_last_error 好像没错误 你接收时需要打循环的么?1k就能收完? tcp,能用curl就用curl吧。 很明显,你应该是已经将socket close了,还继续向socket 读取数据和发送数据。
//echo $buffer; 返回值是 142142142 一排
40之前都对的 网页上显示出connect OK. 这个了
//printf("%s $msg
",$this->sendflag);
//printf("%s $result
",$this->recvflag);
输出
>>> VER=1.4&CON=1&CMD=Login&SEQ=112255&UIN=2810316641&PS=CA9ED0A4F6F2A06017F09D3CA53D030B&M5=1&LG=0&LC=812822641C978097&GD=5MWX2PF3FOVGTP6B&CKE=
//echo $buffer; 返回值是 142142142 一排
40之前都对的 网页上显示出connect OK. 这个了
//printf("%s $msg
",$this->sendflag);
//printf("%s $result
",$this->recvflag);
输出
>>> VER=1.4&CON=1&CMD=Login&SEQ=112255&UIN=2810316641&PS=CA9ED0A4F6F2A06017F09D3CA53D030B&M5=1&LG=0&LC=812822641C978097&GD=5MWX2PF3FOVGTP6B&CKE=
另外,程序比网络快,你发完就直接收,那边可能还没来得及发呢,你的read可能一下子就跳过了,执行了close()
最后要说的是,你了解socket和通信机制么?
如果已经做过相关工作,可以忽略这个问题
如果完全新手,还是要花时间看看socket相关资料,光错误类型就几十个,而且几乎每次都发生的“错误”都有两三个,socket编程很多时候要通过判断错误来确认数据状态的,因为有些非致命“错误”是必然发生的,是传输结束的标志

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
