久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='rvhZo'><tr id='rvhZo'><dt id='rvhZo'><q id='rvhZo'><span id='rvhZo'><b id='rvhZo'><form id='rvhZo'><ins id='rvhZo'></ins><ul id='rvhZo'></ul><sub id='rvhZo'></sub></form><legend id='rvhZo'></legend><bdo id='rvhZo'><pre id='rvhZo'><center id='rvhZo'></center></pre></bdo></b><th id='rvhZo'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rvhZo'><tfoot id='rvhZo'></tfoot><dl id='rvhZo'><fieldset id='rvhZo'></fieldset></dl></div>

    <small id='rvhZo'></small><noframes id='rvhZo'>

      <tfoot id='rvhZo'></tfoot>

        <bdo id='rvhZo'></bdo><ul id='rvhZo'></ul>
    1. <legend id='rvhZo'><style id='rvhZo'><dir id='rvhZo'><q id='rvhZo'></q></dir></style></legend>
    2. 如何使 LAN 客戶端可以發現服務器

      How to make a server discoverable to LAN clients(如何使 LAN 客戶端可以發現服務器)
          <tbody id='oQX9Y'></tbody>
        <tfoot id='oQX9Y'></tfoot>
      • <i id='oQX9Y'><tr id='oQX9Y'><dt id='oQX9Y'><q id='oQX9Y'><span id='oQX9Y'><b id='oQX9Y'><form id='oQX9Y'><ins id='oQX9Y'></ins><ul id='oQX9Y'></ul><sub id='oQX9Y'></sub></form><legend id='oQX9Y'></legend><bdo id='oQX9Y'><pre id='oQX9Y'><center id='oQX9Y'></center></pre></bdo></b><th id='oQX9Y'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oQX9Y'><tfoot id='oQX9Y'></tfoot><dl id='oQX9Y'><fieldset id='oQX9Y'></fieldset></dl></div>
      • <legend id='oQX9Y'><style id='oQX9Y'><dir id='oQX9Y'><q id='oQX9Y'></q></dir></style></legend>

            <small id='oQX9Y'></small><noframes id='oQX9Y'>

              • <bdo id='oQX9Y'></bdo><ul id='oQX9Y'></ul>
                本文介紹了如何使 LAN 客戶端可以發現服務器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在使用 Python 開發一個多人游戲,該游戲使用套接字庫進行網絡連接.游戲將支持局域網播放.一名玩家將設置服務器,局域網上的其他玩家將能夠加入游戲.

                I am working on a multiplayer game in python that uses the socket library for its networking. The game will support play over LAN. One player will set up the server and other players on the LAN will be able to join the game.

                為了實現這一點,我需要一種讓玩家發現可用服務器列表的簡單方法(不應該期望玩家必須輸入 IP 地址!).我首選的解決方案將僅使用 python 套接字庫(以及可選的標準庫的其他部分).

                To implement this, I need a simple way for the players to discover a list of available servers (players shouldn't be expected to have to enter IP addresses!). My preferred solution would use only the python socket library (and optionally other parts of the standard library).

                我正在尋找的是客戶端和服務器代碼:

                What I am looking for is client and server code:

                • 客戶端:將其對游戲的請求廣播到偵聽 LAN 上某個端口的所有機器

                • client: broadcasts its request for games to all machines listening on a certain port on the LAN

                服務器:回復客戶端的可用性

                server(s): replies to the client with its availability

                嘗試的答案 按照 Hans 在下面的答案中的建議,可以使用 UDP 套接字來響應來自客戶端的廣播請求.

                ATTEMPTED ANSWER Following Hans' advice in his answer below, a UDP socket can be used to respond broadcast requests from the client.

                服務器:

                #UDP server responds to broadcast packets
                #you can have more than one instance of these running
                import socket
                address = ('', 54545)
                server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
                server_socket.bind(address)
                
                while True:
                    print "Listening"
                    recv_data, addr = server_socket.recvfrom(2048)
                    print addr,':',recv_data
                    server_socket.sendto("*"+recv_data, addr)
                

                客戶:

                #UDP client broadcasts to server(s)
                import socket
                
                address = ('<broadcast>', 54545)
                client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
                
                data = "Request"
                client_socket.sendto(data, address)
                while True:
                    recv_data, addr = client_socket.recvfrom(2048)
                    print addr,recv_data
                

                還有其他令人信服的方法來處理這個可發現性問題嗎?

                Are there other compelling ways to handle this discoverability problem?

                推薦答案

                你可以試試 UDP 廣播.你可以例如從客戶端發送廣播.然后,服務器應使用其地址廣播響應,以便客戶端可以使用常規連接.

                You could try a UDP broadcast. You can e.g. send a broadcast from the client. The server should then broadcast a response with its address so the client can use a regular connection.

                有關示例代碼,請參見此處:http://wiki.python.org/moin/UdpCommunication

                See here for some example code: http://wiki.python.org/moin/UdpCommunication

                這篇關于如何使 LAN 客戶端可以發現服務器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)

                      <tbody id='fLmuf'></tbody>
                        • <bdo id='fLmuf'></bdo><ul id='fLmuf'></ul>
                        • <legend id='fLmuf'><style id='fLmuf'><dir id='fLmuf'><q id='fLmuf'></q></dir></style></legend>
                        • <tfoot id='fLmuf'></tfoot>
                        • <small id='fLmuf'></small><noframes id='fLmuf'>

                          <i id='fLmuf'><tr id='fLmuf'><dt id='fLmuf'><q id='fLmuf'><span id='fLmuf'><b id='fLmuf'><form id='fLmuf'><ins id='fLmuf'></ins><ul id='fLmuf'></ul><sub id='fLmuf'></sub></form><legend id='fLmuf'></legend><bdo id='fLmuf'><pre id='fLmuf'><center id='fLmuf'></center></pre></bdo></b><th id='fLmuf'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fLmuf'><tfoot id='fLmuf'></tfoot><dl id='fLmuf'><fieldset id='fLmuf'></fieldset></dl></div>

                          主站蜘蛛池模板: 亚洲成人在线视频播放 | 国产精品成人一区二区三区夜夜夜 | 国产2区 | 天天拍天天操 | 中文字幕电影在线观看 | 欧美在线亚洲 | 日韩精品在线观看免费 | 99精品久久 | 狠狠操在线 | 欧美一区二区黄 | 日韩国产高清在线观看 | 久久精品网 | 天堂一区二区三区四区 | 亚洲 欧美 另类 综合 偷拍 | 午夜小电影 | 色网站在线 | 国产一区二区三区欧美 | 亚洲国产精品视频一区 | 亚洲深夜福利 | 免费激情av | 狠狠入ady亚洲精品经典电影 | 97国产精品 | 国产精品亚洲精品日韩已方 | 天天躁日日躁性色aⅴ电影 免费在线观看成年人视频 国产欧美精品 | 日韩av成人 | 天天草视频 | 美日韩一区二区 | 日韩欧美三级电影 | 欧洲精品一区 | 亚洲一区二区精品视频 | 国产一级片一区二区三区 | 久久的色 | 日韩一区在线观看视频 | 国内精品视频免费观看 | 欧美视频一区二区三区 | 亚洲精品区 | 久久精品亚洲精品国产欧美 | 91成人| 你懂的在线视频播放 | 五月婷婷亚洲 | 91成人午夜性a一级毛片 |