将字符写入 Java 套接字时 fsockopen 10053 错误
是的,
我正在尝试用 PHP 编写一个小脚本,它将向 Minecraft 发送游戏内聊天包。
//Deliberately low timeout
$mc = fsockopen("localhost", 25565, $errno, $err, 3);
现在,如果连接成功,那么我会发送 2 个“数据包”。
单个字节 其中包含整数 3,告诉 Minecraft 它应该将传入的网络流量作为 Packet3Chat“数据包”处理:
fwrite( $mc, strrev( pack( "C", 3 ) ) );
这似乎工作正常**。
所需的第二个“数据包”是字符串的长度 签名短片。
$my_string = "Hello World!";
//119 character limit on Minecraft chat messages
$processed_string = substr($my_string, 0, 119);
fwrite($mc, strrev( pack( "s", strlen( $processed_string ) ) ) );
这似乎也很有效**。
现在剩下要做的就是发送实际的字符串 作为字符。
我尝试过使用 str_split
分割字符串,并使用两者单独发送每个字符:
//Signed char
fwrite($mc, strrev( pack( "c", $character ) ) );
并且
//Unsigned char
fwrite($mc, strrev( pack( "C", $character ) ) );
我也尝试过通过这些方法发送整个字符串而不将其分割,但是我还没有能够成功打印出 readChar()
接收到的字符(System.out.println
只是打印一个空行),并且我收到一个 fwrite 错误 10053 于发送字符期间的某个时刻 - 即 readChar()
抛出 EOFException
。
我在 Windows 7 上运行修改后的 Minecraft Server,并在同一台计算机上使用 XAMPP 运行 PHP 5.x。
有什么想法为什么连接会“被软件关闭”吗?为什么它仅在发送字符/字符串期间而不是在发送字节/短期间关闭?
** Yes I have used
System.out.println
to verify the data received by Minecraft.Right,
I'm trying to write a wee script in PHP that will send an in game chat package to Minecraft.
//Deliberately low timeout
$mc = fsockopen("localhost", 25565, $errno, $err, 3);
Now, if that connects successfully, then I send 2 "packets".
A single byte with the integer 3 in it to tell Minecraft that it should handle the incoming network traffic as a Packet3Chat "packet":
fwrite( $mc, strrev( pack( "C", 3 ) ) );
This appears to work A-OK**.
The second "packet" that is required is the length of the string as a signed short.
$my_string = "Hello World!";
//119 character limit on Minecraft chat messages
$processed_string = substr($my_string, 0, 119);
fwrite($mc, strrev( pack( "s", strlen( $processed_string ) ) ) );
And that also appears to work A-OK**.
And now all that's left to do is send the actual string, as chars.
I have tried splitting the string using str_split
and sending each character on it's own using both:
//Signed char
fwrite($mc, strrev( pack( "c", $character ) ) );
and
//Unsigned char
fwrite($mc, strrev( pack( "C", $character ) ) );
And I've also tried just sending the whole string by those methods without splitting it up, however I haven't been able to successfully print out the characters received by readChar()
(System.out.println
just prints an empty line), and I get an fwrite error 10053 at some point during the sending of the characters - i.e. an EOFException
is thrown by readChar()
.
I'm running the modified Minecraft Server on Windows 7 and I'm running PHP 5.x using XAMPP on the same machine.
Any ideas why the connection would be "closed by software"? And why it would close only during the sending of the characters/string and not during the sending of the byte/short?
** Yes I have used
System.out.println
to verify the data received by Minecraft.如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
10053 是 WSAECONNABORTED 的 Winsock 错误代码。
可以在 http://www.chilkatsoft.com/ 找到该错误情况的“可理解”解释p/p_299.asp
10053 is the winsock error code for WSAECONNABORTED.
An "understandable" explaination of that error condition can be found at http://www.chilkatsoft.com/p/p_299.asp
尝试插件 HTTPConsole 并
使用这样的函数来执行命令:
当您说“发送聊天消息”时,我不确定这是否正在执行您想要的操作,这会发布一条控制台消息到服务器。
try the plugin HTTPConsole and
and use a function like this to execute the command:
I am not sure if this is doing what you want when you say "send a chat message", This posts a console message to the server.