将字符写入 Java 套接字时 fsockopen 10053 错误

发布于 2024-11-27 22:07:08 字数 1772 浏览 2 评论 0原文

是的,

我正在尝试用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷鸟归林 2024-12-04 22:07:08

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

后来的我们 2024-12-04 22:07:08

尝试插件 HTTPConsole

使用这样的函数来执行命令:

function exec_shell_command($command) {
$command = urlencode($command);
$url = "http://127.0.0.1:25560/console?command=$command";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$out = curl_exec($ch);
curl_close($ch);
return $out;
}
$retval = exec_shell_command("say this is a server message");

当您说“发送聊天消息”时,我不确定这是否正在执行您想要的操作,这会发布一条控制台消息到服务器。

try the plugin HTTPConsole and

and use a function like this to execute the command:

function exec_shell_command($command) {
$command = urlencode($command);
$url = "http://127.0.0.1:25560/console?command=$command";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$out = curl_exec($ch);
curl_close($ch);
return $out;
}
$retval = exec_shell_command("say this is a server message");

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文