[英]C++ SFML UDP Socket receiving and sending data to multiple clients
I am trying to learn network socket programming basics and I can't understand some things. 我正在尝试学习网络套接字编程基础知识,但我听不懂某些内容。 I have assignment to create working MMORPG server-client application where even up to 1000 clients can be connected at same time to server using SFML library.
我分配了一个工作正常的MMORPG服务器-客户端应用程序,使用SFML库可以同时将多达1000个客户端连接到服务器。 I started with some simple stuff like testing packets, sockets and making simple applications like chat in console and multiplayer tic-tac-toe for other assignment.
我从一些简单的东西开始,例如测试数据包,套接字,并制作简单的应用程序,例如在控制台中聊天,以及进行其他分配的多人tic-tac-toe。 I heard that using UDP sockets is way to go for real-time applications like games so I am trying to understand how does it work.
我听说使用UDP套接字是用于游戏等实时应用程序的方法,因此我试图了解它是如何工作的。 In TCP Socket I am simply listening to connections, once client connects I can assign him to certain socket and keep listening for connections while I send data and identify him.
在TCP套接字中,我只是在监听连接,一旦客户端连接,我就可以将他分配给特定的套接字,并在发送数据并识别他的同时继续监听连接。
I don't know how to identify clients using UDP socket. 我不知道如何使用UDP套接字识别客户端。 I am not even sure if my approach is right.
我什至不确定我的方法是否正确。
I thought that it should work like this: 我认为它应该像这样工作:
1.I create UDP socket binding it to certain port. 1.我创建了将其绑定到特定端口的UDP套接字。
2.I am making sure that client got permission to receive data from server. 2.我确保客户端已获得从服务器接收数据的权限。
3.In loop I am receiving and sending packets from/to every client. 3.在循环中,我正在接收/从每个客户端发送数据包。
4.If client get disconnected, we close connection for him/delete him from vector of clients. 4.如果客户断开连接,我们会为他关闭连接/从客户引导中删除他。
So how I do this with UDP sockets? 那么我该如何使用UDP套接字呢? Are they necessary for this kind of architecture ?
它们对于这种架构是否必要? Also I would appreciate any good article about making working client-server application with good protection and performance.
同样,我也很感谢任何有关使工作的客户端-服务器应用程序具有良好的保护和性能的好文章。 Thanks in advance :)
提前致谢 :)
Okay so I found actually two good articles about using UDP sockets and overall network in game: 好的,所以我实际上找到了两篇有关在游戏中使用UDP套接字和整个网络的文章:
SFML Game Development by Example: https://www.packtpub.com/game-development/sfml-game-development-example SFML游戏开发示例: https : //www.packtpub.com/game-development/sfml-game-development-example
Author is writing 3 SFML games in C++ and explains everything as he goes, using UDP sockets and taking care of packet reliability included. 作者正在用C ++编写3种SFML游戏,并使用UDP套接字并考虑了包的可靠性来解释一切。
Gaffer on Games article: http://gafferongames.com/networking-for-game-programmers/ 关于游戏的Gaffer文章: http : //gafferongames.com/networking-for-game-programmers/
Big amount of informations about game networking. 有关游戏网络的大量信息。
I hope that it helps for someone looking for clues about UDP sockets and examples of using it in network game development. 我希望它对寻求有关UDP套接字的线索以及在网络游戏开发中使用它的示例的人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.