且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

实施C#客户端-服务器以保持游戏数据同步时出现问题

更新时间:2023-11-04 14:51:16

如果是我,我将让客户端定期推送自己的更新并拉取其他客户端更新.这使得服务器不过是一个令人赞叹的数据交换所.它所做的只是侦听客户端连接,然后客户端驱动comm会话-而不是服务器.
If it were me, I would let the clients push their own updates and pull other client updates on a regular basis. That makes the server nothing more than a glorified data clearinghouse. All it does is listen for client connections, and then the clients drive the comm session - not the server.


好的,我的问题已经解决了.我删除了
Alright, my question has been solved. I removed the
ReadToEnd(conn.GetStream());


函数调用,并将其替换为


function call, and replaced it with

conn.GetStream().Read(data, 0, buffSize); 


我的客户端服务器运行正常,现在我只需要弄清楚如何发送任意长度的消息...

这是不要盲目复制粘贴!"的一个很好的例子.我使用的功能无法正常工作!


My client-server is functioning correctly, now I just need to figure out how to send messages of arbitrary length...

This is a good example of "Don''t blindly copy-paste!!" The function I used did not work as expected!