多个线程写入一个服务器 [英] multiple threads writing to one server

查看:132
本文介绍了多个线程写入一个服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题。我想创建一个网络连接,以便我可以制作多人游戏。我知道并理解插座。
我的问题是,如果我同时按下键盘上的两个键,它会同时写入套接字,从而导致错误。然后我做的是为一个客户端创建多个套接字以写入并仅写入不忙的套接字。由于某种原因似乎超载它或其他东西。任何同时向服务器发送消息的想法,反之亦然。

I have a problem. I want to create a network connection so that I can make a multiplayer game. I know and understand sockets. My problem is that if I press two keys on the keyboard at the same time it writes to the socket at the same time which causes an error. What I then did was create multiple sockets for one client to writ to and only writes to a socket that isn't busy. By for some reason seems to overload it or something. Any ideas for simultaneously sending messages to server and vice versa.

推荐答案

我使用了排队方法并修复了问题。

I have used a queueing method and has fixed the problem.

这篇关于多个线程写入一个服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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