将Chars写入Java套接字时出现fsockopen 10053错误 [英] fsockopen 10053 error when writing Chars to Java socket
问题描述
对,
我试图在PHP中写一个wee脚本,将会发送一个游戏聊天包到Minecraft。
//故意低超时
$ mc = fsockopen(localhost,25565,$ errno,$ err,3);
现在,如果连接成功,那么我发送2个数据包。
一个单个字节与整数3在它告诉Minecraft它应该处理传入的网络流量作为一个Packet3Chat包:
fwrite($ mc,strrev(pack(C,3)));
这似乎工作A-OK **。
所需的第二个数据包是字符串的长度签署的简短。
$ my_string =你好,世界!;
// Minecraft聊天消息上限为119个字符
$ processed_string = substr($ my_string,0,119);
fwrite($ mc,strrev(pack(s,strlen($ processed_string)))));
这也似乎工作A-OK **。
现在剩下要做的就是发送实际的字符串作为字符。
我已经尝试使用 str_split
并使用两者发送每个字符自己:
//签名的char
fwrite ($ mc,strrev(pack(c,$ character)));
和
// unsigned char
fwrite($ mc,strrev(pack(C,$ character)));
我也试过用这些方法发送整个字符串,无法成功打印出 readChar()
( System.out.println
)一个空行),并且在发送字符的某个时刻,我得到一个 fwrite错误10053 - 即 EOFException
被抛出 readChar()
。
我在Windows 7上运行修改的Minecraft服务器,我运行PHP 5.x在同一台机器上使用XAMPP。
任何想法为什么连接将由软件关闭?为什么它只会在发送字符/字符串期间而不是在发送字节/短期时关闭?
**是我使用
System.out.println
来验证Minecraft收到的数据。 10053是 WSAECONNABORTED 的winsock错误代码/ a>。
可以在 http://www.chilkatsoft.com/p/p_299.asp
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
这篇关于将Chars写入Java套接字时出现fsockopen 10053错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!