C#平的Minecraft [英] C# ping minecraft

查看:176
本文介绍了C#平的Minecraft的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以发现这个小的代码片段,将允许你来ping在PHP中的Minecraft服务器,但现在我想这样做在C#。

So found this little code snippet that would allow you to ping a Minecraft server in PHP, but now i want to do this in C#.

我试着在我自己的,但由于某种原因,它只是不工作

I tried doing this on my own but for some reason its just not working

        UdpClient client = new UdpClient();
        IPEndPoint ep;
        try
        {
            ep = new IPEndPoint(IPAddress.Parse("-snip-"), -snip-);
            client.Connect(ep);
        }
        catch { Console.WriteLine("Error"); Console.ReadLine(); return; }
        byte[] bytes = new byte[1];
        bytes[0] = (byte)0xFE;
        client.Send(bytes, bytes.Length);
        IPEndPoint rep = new IPEndPoint(IPAddress.Any, 0);
        byte[] recv = client.Receive(ref rep);
        Console.WriteLine(ASCIIEncoding.ASCII.GetString(recv));
        Console.ReadLine();



服务器似乎只是完全忽略该数据包。这是代码片段,我发现:

The server seems to just completely ignore the packet. This is the code snippet i found:

    $fp = fsockopen($host, $port, $errno, $errstr, $timeout);
    if (!$fp) return false;

    //Send 0xFE: Server list ping

    fwrite($fp, "\xFE");

    //Read as much data as we can (max packet size: 241 bytes)
    $d = fread($fp, 256);

    //Check we've got a 0xFF Disconnect
    if ($d[0] != "\xFF") return false;



任何人都可以请指出我正在做什么错误?谢谢!

Could anyone please point out what mistake i'm making? Thank you!

推荐答案

由于这里 >

As described here

客户端发起的 TCP
标准的端口上连接到服务器的Minecraft。代替这样做身份验证和登录(如
协议加密详述)的,它发送两个字节序列FE 01这是一个
0xFE的服务器列表ping包。如果第二个字节(0x01)的为
丢失,服务器等待约1000毫秒再与服务器回复 - >在1.3和更低版本
客户端格式

The client initiates a TCP connection to the minecraft server on the standard port. Instead of doing auth and logging in (as detailed in Protocol Encryption), it sends the two byte sequence FE 01. This is a 0xFE server list ping packet. If the second byte (the 0x01) is missing, the server waits about 1000ms then replies with the Server -> Client format used in 1.3 and earlier.

您需要发送一个TCP请求,而你发送一个UDP包...

you need to send a TCP request whereas you're sending an UDP packet...

这篇关于C#平的Minecraft的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆