在python中广播套接字服务器 [英] Broadcasting socket server in python

查看:95
本文介绍了在python中广播套接字服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个多人游戏,所以一旦服务器启动,我想连续广播服务器名称,以便客户端可以知道有一些服务器正在运行.我不想提供IP地址和端口号来连接服务器.有人可以帮我广播服务器名称.

I am building a multiplayer game, so once the server started i want to broadcast server name continuously so that client can know that there are some server is running. I don't want to give IP address and port number to connect to server. can someone help me to broadcast server name.

  • 它是一个应用程序,而不是网络应用程序.

推荐答案

SO中有一个自动答复的问题正在谈论此问题:

There is an auto-responded question in SO already talking about this: How to make a server discoverable to LAN clients

您可以使用相同的技术在本地网络中请求服务器.

You can use the same technique to ask for servers in the local network.

视频游戏中的方法(YMMV)是:

The approach (YMMV) in video games is:

  • 服务器启动并绑定到广播.
  • 客户端启动并绑定到广播.
  • 客户端发送一条广播消息,询问服务器.
  • 服务器从客户端接收广播消息,并以另一广播的形式对其进行答复(如果他们感到偏执,它们可能会在一两秒钟后重新发送该消息).
  • 客户端等待几秒钟,并记录所有正在响应的服务器的信息.
  • 客户端向服务器显示一个列表,并要求玩家选择一个.
    • 在玩家访问服务器列表页面期间,也许他们会希望继续并行执行上一步.
    • Servers start and bind to broadcast.
    • Clients start and bind to broadcast.
    • Clients send a broadcast message asking for servers.
    • Servers receive broadcast messages from clients and reply with another broadcast about them (they maybe resend that message a second or two later, if they feel paranoid).
    • Clients wait a few seconds and record the information of all servers responding.
    • Clients present a list with the servers and ask the players to choose one.
      • Maybe they will want to keep doing the previous step in parallel, during the player visit to the server list page.
      • 通常也可以选择端口,但是在游戏中默认情况下此连接的默认端口可用.这样,如果端口未更改,您甚至不需要在消息中广播服务器身份...

      要通过Internet发现服务器,您需要某种通知服务.自从android联网游戏时代以来,您就可以在网络中有很多作为通用发现服务的选择.

      To discover server over Internet, you need some kind of notification service. You have plenty of options in the network that work as generic discovery services, popular since the android networking games era.

      这篇关于在python中广播套接字服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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