久久久久久久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 客戶端可以發(fā)現(xiàn)服務(wù)器

      How to make a server discoverable to LAN clients(如何使 LAN 客戶端可以發(fā)現(xiàn)服務(wù)器)
          <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 客戶端可以發(fā)現(xiàn)服務(wù)器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我正在使用 Python 開發(fā)一個多人游戲,該游戲使用套接字庫進(jìn)行網(wǎng)絡(luò)連接.游戲?qū)⒅С志钟蚓W(wǎng)播放.一名玩家將設(shè)置服務(wù)器,局域網(wǎng)上的其他玩家將能夠加入游戲.

                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.

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

                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).

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

                What I am looking for is client and server code:

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

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

                服務(wù)器:回復(fù)客戶端的可用性

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

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

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

                服務(wù)器:

                #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
                

                還有其他令人信服的方法來處理這個可發(fā)現(xiàn)性問題嗎?

                Are there other compelling ways to handle this discoverability problem?

                推薦答案

                你可以試試 UDP 廣播.你可以例如從客戶端發(fā)送廣播.然后,服務(wù)器應(yīng)使用其地址廣播響應(yīng),以便客戶端可以使用常規(guī)連接.

                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.

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

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

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

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

                相關(guān)文檔推薦

                How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機(jī)器人?)
                Discord bot isn#39;t responding to commands(Discord 機(jī)器人沒有響應(yīng)命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關(guān)于我嗎?Discord 機(jī)器人的功能?(不和諧.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機(jī)器人?)
                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>

                          主站蜘蛛池模板: 久久久久网站 | 一级欧美一级日韩片 | 欧美一卡二卡在线 | 四虎影院在线免费观看 | 亚洲欧洲成人在线 | 精品亚洲一区二区三区 | 又黑又粗又长的欧美一区 | 精品一区久久 | 91av在线不卡 | 免费成人国产 | 亚洲在线看 | 国外成人在线视频网站 | 人妖videosex高潮另类 | 欧美日韩电影在线 | 在线播放一区二区三区 | 亚洲精品在线观 | 国产毛片久久久 | 日韩av福利在线观看 | 亚洲成人精品一区 | 亚洲精品二三区 | 欧美日韩在线一区二区 | 爱爱免费视频网站 | 国产日韩欧美精品一区二区三区 | 日韩在线免费视频 | 美女久久久久久久久 | 一区二区三区视频播放 | 91在线精品一区二区 | 日本天堂一区二区 | 91精品国产综合久久久久久 | 欧美日韩视频在线播放 | 黄色国产视频 | 亚洲一区二区综合 | 精品不卡| 欧美精品久久久 | 一区二区三区av | 色视频www在线播放国产人成 | 在线观看黄色大片 | 国产成人精品一区二区三区网站观看 | 国产精品永久久久久久久www | 欧美日韩国产在线观看 | 亚洲高清成人 |