我想在 XNA 4 中编写多人游戏。为了发送数据,我使用 TcpClient 类连接,如下所示:
try{
client.Connect(serverEndPoint);
}
catch (Exception ex){
Console.WriteLine("not connected");
return;
}
if (!client.Connected) return;
NetworkStream stream = client.GetStream();
stream.BeginRead(buf, 0, 1024, new AsyncCallback(PrijmiData), null);
当我想用他的方法发送数据时:
private void Send(byte[] co){
NetworkStream clientStream = client.GetStream();
clientStream.BeginWrite(co, 0, co.Length, new AsyncCallback(Sended), null);
}
private void Sended(IAsyncResult res){
NetworkStream clientStream = client.GetStream();
clientStream.EndWrite(res);
}
服务器收到数据但 XNA 游戏立即结束。为什么?谢谢你的建议。