实际上我的客户端有问题 - 服务器与 tcp 和 dll (Networkcomms) 的通信。一切都很好,但问题如下:客户端将数据 a = 123 发送到服务器。服务器接收到 123 并发送回客户端,接收到 123,一切都很好。但是当客户端现在再次向服务器发送数据时,服务器将其发送回 2 次。下一次调用 3 次 and and and。如果我必须删除缓冲区或缓存,对我来说似乎,但我不知道如何。我已经尝试处理连接,但它不受影响。
我已经阅读了 Networkcomms 的文档,并且在他们的客户端示例中 - 服务器通信不需要重置,但我可以看到它是需要的。
有什么想法吗?
来自德国的问候
编辑:
static void Main(string[] args)
{
NetworkComms.AppendGlobalIncomingPacketHandler<string>("Message", PrintIncommingMessage);
Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 666));
Console.ReadKey(true);
}
private static void PrintIncommingMessage(PacketHeader header,Connection connection,string message)
{
string data = message;
string[] datasplit = data.Split(new char[] { '/' });
if(datasplit[0] == "IstReady")
{
if (ReadyName == null)
{
conn2 = connection;
ReadyName = datasplit[1];
Console.WriteLine(ReadyName + " ist ready!\n");
}
else
{
connection.SendObject("Message","Start");
conn2.SendObject("Message","Start");
ReadyName = null;
}
}
if (datasplit[0] == "SetUserPosition")
{
if(User1 == null||User1 == datasplit[1])
{
User1 = datasplit[1];
User1Y = datasplit[2];
}
else
{
User2 = datasplit[1];
User2Y = datasplit[2];
}
}
if (datasplit[0] == "GetUserPosition")
{
if(User1 == datasplit[1])
{
connection.SendObject("Message","GotUserY/"+User1Y);
}
else if(User2 == datasplit[1])
{
connection.SendObject("Message", "GotUserY/"+User2Y);
}
}
}
回答: 我忘记了我多次调用了,NetworkComms.AppendGlobalIncomingPacketHandler("Message", PrintIncommingMessage);" 这个函数在我的客户端。这就是为什么我每次都得到越来越多的结果,因为我添加了多个处理程序。嗯非常简单的问题,但我完全过度阅读了添加处理程序的计时器。