fsockopen 10053 error when writing Chars to Java socket(将字符写入 Java 套接字时出现 fsockopen 10053 错误)
问题描述
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.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
这篇关于将字符写入 Java 套接字时出现 fsockopen 10053 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将字符写入 Java 套接字时出现 fsockopen 10053 错误
基础教程推荐
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01