{"id":23472,"date":"2025-04-19T07:56:51","date_gmt":"2025-04-18T23:56:51","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/23472.html"},"modified":"2025-04-19T07:56:51","modified_gmt":"2025-04-18T23:56:51","slug":"%e3%80%90python%e3%80%91%e6%90%ad%e5%bb%basocket-%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%90%8c%e6%ad%a5%e6%89%8b%e6%9c%ba%e9%aa%8c%e8%af%81%e7%a0%81%e5%88%b0%e7%94%b5%e8%84%91","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/23472.html","title":{"rendered":"\u3010Python\u3011\u642d\u5efasocket \u670d\u52a1\u5668\u540c\u6b65\u624b\u673a\u9a8c\u8bc1\u7801\u5230\u7535\u8111"},"content":{"rendered":"<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u5173\u4e8e\u5982\u4f55\u4f7f\u7528\u60a8\u63d0\u4f9b\u7684 Python \u4ee3\u7801\u521b\u5efa\u5e76\u8fd0\u884c\u4e00\u4e2a\u9a8c\u8bc1\u7801\u63d0\u53d6\u670d\u52a1\u5668\u7684\u7b80\u5355\u6559\u7a0b\u3002\u8fd9\u4e2a\u6559\u7a0b\u9762\u5411\u521d\u5b66\u8005&#xff0c;\u9010\u6b65\u89e3\u91ca\u4ee3\u7801\u7684\u529f\u80fd\u5e76\u6307\u5bfc\u5982\u4f55\u90e8\u7f72\u5b83\u3002<\/p>\n<hr \/>\n<p>\u6559\u7a0b&#xff1a;\u521b\u5efa\u5e76\u8fd0\u884c\u4e00\u4e2a\u9a8c\u8bc1\u7801\u63d0\u53d6\u670d\u52a1\u5668<\/p>\n<p>\u8fd9\u4e2a\u6559\u7a0b\u5c06\u6307\u5bfc\u60a8\u5982\u4f55\u4f7f\u7528 Python \u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 socket \u670d\u52a1\u5668&#xff0c;\u7528\u4e8e\u63a5\u6536\u6587\u672c\u6570\u636e&#xff0c;\u63d0\u53d6\u5176\u4e2d\u7684\u9a8c\u8bc1\u7801&#xff08;4-8\u4f4d\u6570\u5b57&#xff09;&#xff0c;\u5e76\u5c06\u5176\u590d\u5236\u5230\u526a\u8d34\u677f&#xff0c;\u540c\u65f6\u663e\u793a\u684c\u9762\u901a\u77e5\u3002\u6211\u4eec\u8fd8\u5c06\u4ecb\u7ecd\u5982\u4f55\u5b89\u88c5\u4f9d\u8d56\u3001\u8fd0\u884c\u4ee3\u7801\u5e76\u53d1\u5e03\u4f7f\u7528\u3002<\/p>\n<p>\u529f\u80fd\u6982\u8ff0<\/p>\n<p>\u8be5\u7a0b\u5e8f\u662f\u4e00\u4e2a\u57fa\u4e8e socket \u7684\u670d\u52a1\u5668&#xff0c;\u53ef\u4ee5&#xff1a;<\/p>\n<li>\n<p>\u76d1\u542c\u6307\u5b9a\u7aef\u53e3&#xff08;\u9ed8\u8ba45000&#xff09;\u7684\u4f20\u5165\u8fde\u63a5\u3002<\/p>\n<\/li>\n<li>\n<p>\u63a5\u6536\u5ba2\u6237\u7aef\u53d1\u9001\u7684\u6587\u672c\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ece\u6587\u672c\u4e2d\u63d0\u53d6\u7b2c\u4e00\u4e2a4-8\u4f4d\u6570\u5b57&#xff08;\u9a8c\u8bc1\u7801&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06\u63d0\u53d6\u7684\u9a8c\u8bc1\u7801\u590d\u5236\u5230\u526a\u8d34\u677f\u3002<\/p>\n<\/li>\n<li>\n<p>\u663e\u793a\u4e00\u4e2a\u684c\u9762\u901a\u77e5&#xff0c;\u544a\u77e5\u7528\u6237\u7ed3\u679c\u3002<\/p>\n<\/li>\n<p>\u524d\u7f6e\u6761\u4ef6<\/p>\n<p>\u5728\u8fd0\u884c\u4ee3\u7801\u4e4b\u524d&#xff0c;\u60a8\u9700\u8981\u51c6\u5907\u4ee5\u4e0b\u5185\u5bb9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u64cd\u4f5c\u7cfb\u7edf: Windows\u3001Linux \u6216 macOS\u3002<\/p>\n<\/li>\n<li>\n<p>Python \u7248\u672c: Python 3.6 \u6216\u66f4\u9ad8\u7248\u672c\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f9d\u8d56\u5e93: \u9700\u8981\u5b89\u88c5 pyperclip \u548c plyer \u5e93\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6b65\u9aa4 1&#xff1a;\u5b89\u88c5\u4f9d\u8d56<\/p>\n<p>\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u884c&#xff0c;\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93&#xff1a;<\/p>\n<p>pip install pyperclip plyer <\/p>\n<ul>\n<li>\n<p>pyperclip: \u7528\u4e8e\u64cd\u4f5c\u526a\u8d34\u677f\u3002<\/p>\n<\/li>\n<li>\n<p>plyer: \u7528\u4e8e\u663e\u793a\u684c\u9762\u901a\u77e5\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6b65\u9aa4 2&#xff1a;\u7406\u89e3\u4ee3\u7801<\/p>\n<p>\u4ee5\u4e0b\u662f\u4ee3\u7801\u7684\u4e3b\u8981\u7ec4\u6210\u90e8\u5206&#xff1a;<\/p>\n<li>\n<p>\u5bfc\u5165\u5e93:<\/p>\n<p> import socket, re, pyperclip, threading <\/p>\n<ul>\n<li>\n<p>socket: \u7528\u4e8e\u521b\u5efa\u7f51\u7edc\u670d\u52a1\u5668\u3002<\/p>\n<\/li>\n<li>\n<p>re: \u7528\u4e8e\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u6570\u5b57\u3002<\/p>\n<\/li>\n<li>\n<p>pyperclip: \u7528\u4e8e\u590d\u5236\u6587\u672c\u5230\u526a\u8d34\u677f\u3002<\/p>\n<\/li>\n<li>\n<p>threading: \u7528\u4e8e\u5f02\u6b65\u663e\u793a\u901a\u77e5\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>SocketServer \u7c7b:<\/p>\n<ul>\n<li>\n<p>__init__: \u521d\u59cb\u5316\u670d\u52a1\u5668&#xff0c;\u7ed1\u5b9a\u5230\u6307\u5b9a\u7aef\u53e3&#xff08;\u4f8b\u5982 5000&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>start: \u542f\u52a8\u670d\u52a1\u5668&#xff0c;\u63a5\u53d7\u5ba2\u6237\u7aef\u8fde\u63a5\u5e76\u5904\u7406\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p>extract_first_long_number: \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u53d64-8\u4f4d\u6570\u5b57\u3002<\/p>\n<\/li>\n<li>\n<p>show_toast_notification: \u5f02\u6b65\u663e\u793a\u684c\u9762\u901a\u77e5\u3002<\/p>\n<\/li>\n<li>\n<p>copy_verification_code: \u63d0\u53d6\u9a8c\u8bc1\u7801\u5e76\u590d\u5236\u5230\u526a\u8d34\u677f\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4e3b\u51fd\u6570:<\/p>\n<p> def main():<br \/>\n    SocketServer(5000).start() <\/p>\n<p>\u521b\u5efa\u5e76\u542f\u52a8\u4e00\u4e2a\u76d1\u542c\u5728\u7aef\u53e3 5000 \u7684\u670d\u52a1\u5668\u3002<\/p>\n<\/li>\n<p>\u6b65\u9aa4 3&#xff1a;\u4fdd\u5b58\u4ee3\u7801<\/p>\n<p>\u5c06\u4ee3\u7801\u4fdd\u5b58\u4e3a\u4e00\u4e2a .py \u6587\u4ef6&#xff0c;\u4f8b\u5982 socket_server.py\u3002<\/p>\n<p>\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>import socket, re, pyperclip, threading<\/p>\n<p>class SocketServer:<br \/>\n    def __init__(self, port):<br \/>\n        self.s &#061; socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br \/>\n        self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)<br \/>\n        self.s.bind((&#039;0.0.0.0&#039;, port))<br \/>\n        self.s.listen(5)<br \/>\n        print(f&#034;Server on port {port}&#8230;&#034;)<\/p>\n<p>    def start(self):<br \/>\n        while True:<br \/>\n            c, addr &#061; self.s.accept()<br \/>\n            print(f&#034;\u8bbe\u5907\u5730\u5740 {addr}&#034;)<br \/>\n            data &#061; c.recv(1024)<br \/>\n            text &#061; data.decode(&#039;utf-8&#039;) if data else &#034;&#034;<br \/>\n            print(f&#034;\u63a5\u6536\u6570\u636e: {text}&#034;)<br \/>\n            result &#061; self.copy_verification_code(text)<br \/>\n            c.send(str(result).encode(&#039;utf-8&#039;))<br \/>\n            c.close()<\/p>\n<p>    def extract_first_long_number(self, text):<br \/>\n        &#034;&#034;&#034;\u63d0\u53d6\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c\u4e00\u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u6570\u5b57&#034;&#034;&#034;<br \/>\n        pattern &#061; r&#039;(?&lt;!\\\\d)\\\\d{4,8}(?!\\\\d)&#039;<br \/>\n        match &#061; re.search(pattern, text)<br \/>\n        if match:<br \/>\n            return match.group(0)<br \/>\n        return None<\/p>\n<p>    def show_toast_notification(self, title, message):<br \/>\n        &#034;&#034;&#034;\u663e\u793a\u684c\u9762\u901a\u77e5&#xff08;\u5f02\u6b65&#xff09;&#034;&#034;&#034;<br \/>\n        from plyer import notification<br \/>\n        def _show():<br \/>\n            try:<br \/>\n                notification.notify(title&#061;title, message&#061;message, timeout&#061;2)<br \/>\n            except Exception as e:<br \/>\n                print(f&#034;Failed to show notification: {e}&#034;)<\/p>\n<p>        threading.Thread(target&#061;_show).start()<\/p>\n<p>    def copy_verification_code(self, text):<br \/>\n        &#034;&#034;&#034;\u63d0\u53d6\u5e76\u590d\u5236\u9a8c\u8bc1\u7801\u5230\u526a\u8d34\u677f&#xff0c;\u5e76\u663e\u793a\u901a\u77e5&#034;&#034;&#034;<br \/>\n        number &#061; self.extract_first_long_number(text)<br \/>\n        if number:<br \/>\n            pyperclip.copy(number)<br \/>\n            print(f&#034;\u5df2\u590d\u5236\u5230\u526a\u8d34\u677f: {number}&#034;)<br \/>\n            self.show_toast_notification(&#034;\u5df2\u590d\u5236\u9a8c\u8bc1\u7801&#034;, number)<br \/>\n            return number<br \/>\n        else:<br \/>\n            print(&#034;\u672a\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u6570\u5b57\u5b57\u7b26\u4e32&#034;)<br \/>\n            self.show_toast_notification(&#034;\u590d\u5236\u5931\u8d25&#034;, &#034;\u8bf7\u68c0\u67e5\u77ed\u4fe1\u9a8c\u8bc1\u7801&#034;)<br \/>\n            return None<\/p>\n<p>def main():<br \/>\n    SocketServer(5000).start()<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    main() <\/p>\n<p>\u6b65\u9aa4 4&#xff1a;\u8fd0\u884c\u670d\u52a1\u5668<\/p>\n<li>\n<p>\u6253\u5f00\u7ec8\u7aef&#xff0c;\u8fdb\u5165\u4ee3\u7801\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/p>\n<p> python socket_server.py <\/li>\n<li>\n<p>\u60a8\u5c06\u770b\u5230\u8f93\u51fa&#xff1a;<\/p>\n<p> Server on port 5000&#8230; <\/p>\n<p>\u8fd9\u8868\u793a\u670d\u52a1\u5668\u5df2\u542f\u52a8\u5e76\u76d1\u542c\u5728\u7aef\u53e3 5000\u3002<\/p>\n<\/li>\n<p>\u6b65\u9aa4 5&#xff1a;\u6d4b\u8bd5\u670d\u52a1\u5668<\/p>\n<p>\u60a8\u9700\u8981\u4e00\u4e2a\u5ba2\u6237\u7aef\u6765\u53d1\u9001\u6570\u636e\u7ed9\u670d\u52a1\u5668\u8fdb\u884c\u6d4b\u8bd5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5ba2\u6237\u7aef\u4ee3\u7801\u793a\u4f8b&#xff1a;<\/p>\n<p>import socket<\/p>\n<p>client &#061; socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br \/>\nclient.connect((&#039;127.0.0.1&#039;, 5000))  # \u672c\u5730\u6d4b\u8bd5\u4f7f\u7528 127.0.0.1<br \/>\nclient.send(&#034;Your code is 123456&#034;.encode(&#039;utf-8&#039;))<br \/>\nresponse &#061; client.recv(1024).decode(&#039;utf-8&#039;)<br \/>\nprint(f&#034;Server response: {response}&#034;)<br \/>\nclient.close() <\/p>\n<li>\n<p>\u5c06\u6b64\u4ee3\u7801\u4fdd\u5b58\u4e3a client.py\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u53e6\u4e00\u4e2a\u7ec8\u7aef\u8fd0\u884c&#xff1a;<\/p>\n<p> python client.py <\/li>\n<li>\n<p>\u670d\u52a1\u5668\u5c06\u8f93\u51fa&#xff1a;<\/p>\n<p> \u8bbe\u5907\u5730\u5740 (&#039;127.0.0.1&#039;, xxxx)<br \/>\n\u63a5\u6536\u6570\u636e: Your code is 123456<br \/>\n\u5df2\u590d\u5236\u5230\u526a\u8d34\u677f: 123456 <\/p>\n<p>\u540c\u65f6&#xff0c;\u60a8\u7684\u526a\u8d34\u677f\u5c06\u5305\u542b 123456&#xff0c;\u5e76\u663e\u793a\u4e00\u4e2a\u684c\u9762\u901a\u77e5\u3002<\/p>\n<\/li>\n<p>\u6b65\u9aa4 6&#xff1a;\u53d1\u5e03\u548c\u4f7f\u7528<\/p>\n<li>\n<p>\u672c\u5730\u4f7f\u7528: \u5982\u679c\u53ea\u5728\u672c\u5730\u4f7f\u7528&#xff0c;\u76f4\u63a5\u8fd0\u884c\u670d\u52a1\u5668\u5373\u53ef\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fdc\u7a0b\u90e8\u7f72:<\/p>\n<ul>\n<li>\n<p>\u5c06\u4ee3\u7801\u90e8\u7f72\u5230\u4e00\u53f0\u5177\u6709\u516c\u7f51 IP \u7684\u670d\u52a1\u5668\u4e0a\u3002<\/p>\n<\/li>\n<li>\n<p>\u4fee\u6539 client.connect((&#039;127.0.0.1&#039;, 5000)) \u4e2d\u7684 IP \u4e3a\u670d\u52a1\u5668\u7684\u516c\u7f51 IP\u3002<\/p>\n<\/li>\n<li>\n<p>\u786e\u4fdd\u9632\u706b\u5899\u5141\u8bb8 5000 \u7aef\u53e3\u7684\u4f20\u5165\u8fde\u63a5&#xff08;\u4f8b\u5982&#xff0c;\u5728 Linux \u4e0a\u8fd0\u884c sudo ufw allow 5000&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5b89\u5168\u6027\u5efa\u8bae:<\/p>\n<ul>\n<li>\n<p>\u5f53\u524d\u4ee3\u7801\u672a\u52a0\u5bc6\u901a\u4fe1&#xff0c;\u5efa\u8bae\u6dfb\u52a0 SSL\/TLS\u3002<\/p>\n<\/li>\n<li>\n<p>\u53ef\u6dfb\u52a0\u8eab\u4efd\u9a8c\u8bc1&#xff0c;\u9632\u6b62\u672a\u7ecf\u6388\u6743\u7684\u8bbf\u95ee\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p>\u793a\u4f8b\u573a\u666f<\/p>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u8bbe\u5907&#xff08;\u5982\u624b\u673a&#xff09;\u63a5\u6536\u9a8c\u8bc1\u7801\u77ed\u4fe1&#xff0c;\u60a8\u53ef\u4ee5\u901a\u8fc7\u811a\u672c\u5c06\u77ed\u4fe1\u5185\u5bb9\u53d1\u9001\u5230\u6b64\u670d\u52a1\u5668&#xff0c;\u670d\u52a1\u5668\u4f1a\u81ea\u52a8\u63d0\u53d6\u9a8c\u8bc1\u7801\u5e76\u590d\u5236\u5230\u526a\u8d34\u677f&#xff0c;\u65b9\u4fbf\u60a8\u7c98\u8d34\u4f7f\u7528\u3002<\/p>\n<p>\u6545\u969c\u6392\u67e5<\/p>\n<ul>\n<li>\n<p>\u4f9d\u8d56\u672a\u5b89\u88c5: \u786e\u4fdd\u8fd0\u884c pip install pyperclip plyer\u3002<\/p>\n<\/li>\n<li>\n<p>\u7aef\u53e3\u88ab\u5360\u7528: \u66f4\u6539 SocketServer(5000) \u4e2d\u7684\u7aef\u53e3\u53f7&#xff0c;\u4f8b\u5982 SocketServer(5001)\u3002<\/p>\n<\/li>\n<li>\n<p>\u901a\u77e5\u4e0d\u663e\u793a: \u68c0\u67e5 plyer \u662f\u5426\u6b63\u786e\u5b89\u88c5&#xff0c;\u4e14\u64cd\u4f5c\u7cfb\u7edf\u652f\u6301\u901a\u77e5\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<p>\u5e0c\u671b\u8fd9\u4e2a\u6559\u7a0b\u5bf9\u60a8\u6709\u5e2e\u52a9&#xff01;\u5982\u679c\u60a8\u9700\u8981\u8fdb\u4e00\u6b65\u4f18\u5316\u4ee3\u7801&#xff08;\u4f8b\u5982\u6dfb\u52a0\u52a0\u5bc6&#xff09;\u6216\u6709\u5176\u4ed6\u95ee\u9898&#xff0c;\u8bf7\u544a\u8bc9\u6211\u3002\u795d\u60a8\u7684\u9879\u76ee\u6210\u529f&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb880\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u8fd9\u4e2a\u6559\u7a0b\u5c06\u6307\u5bfc\u60a8\u5982\u4f55\u4f7f\u7528 Python \u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 socket \u670d\u52a1\u5668\uff0c\u7528\u4e8e\u63a5\u6536\u6587\u672c\u6570\u636e\uff0c\u63d0\u53d6\u5176\u4e2d\u7684\u9a8c\u8bc1\u7801\uff084-8\u4f4d\u6570\u5b57\uff09\uff0c\u5e76\u5c06\u5176\u590d\u5236\u5230\u526a\u8d34\u677f\uff0c\u540c\u65f6\u663e\u793a\u684c\u9762\u901a\u77e5\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5173\u4e8e\u5982\u4f55\u4f7f\u7528\u60a8\u63d0\u4f9b\u7684 Python \u4ee3\u7801\u521b\u5efa\u5e76\u8fd0\u884c\u4e00\u4e2a\u9a8c\u8bc1\u7801\u63d0\u53d6\u670d\u52a1\u5668\u7684\u7b80\u5355\u6559\u7a0b\u3002\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u8bbe\u5907\uff08\u5982\u624b\u673a\uff09\u63a5\u6536\u9a8c\u8bc1\u7801\u77ed\u4fe1\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u811a\u672c\u5c06\u77ed\u4fe1\u5185\u5bb9\u53d1\u9001\u5230\u6b64\u670d\u52a1\u5668\uff0c\u670d\u52a1\u5668\u4f1a\u81ea\u52a8\u63d0\u53d6\u9a8c\u8bc1\u7801\u5e76\u590d\u5236\u5230\u526a\u8d34\u677f\uff0c\u65b9\u4fbf\u60a8\u7c98\u8d34\u4f7f\u7528\u3002\u540c\u65f6\uff0c\u60a8\u7684\u526a\u8d34\u677f\u5c06\u5305\u542b 123456\uff0c\u5e76\u663e\u793a\u4e00\u4e2a\u684c\u9762\u901a\u77e5\u3002start: \u542f\u52a8\u670d\u52a1\u5668\uff0c\u63a5\u53d7\u5ba2\u6237\u7aef\u8fde\u63a5\u5e76\u5904\u7406\u6570\u636e\u3002_python socket \u767b\u5f55\u9a8c\u8bc1\u529f\u80fd<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,190,43],"topic":[],"class_list":["post-23472","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-190","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Python\u3011\u642d\u5efasocket \u670d\u52a1\u5668\u540c\u6b65\u624b\u673a\u9a8c\u8bc1\u7801\u5230\u7535\u8111 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/23472.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Python\u3011\u642d\u5efasocket \u670d\u52a1\u5668\u540c\u6b65\u624b\u673a\u9a8c\u8bc1\u7801\u5230\u7535\u8111 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb880\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u8fd9\u4e2a\u6559\u7a0b\u5c06\u6307\u5bfc\u60a8\u5982\u4f55\u4f7f\u7528 Python \u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 socket \u670d\u52a1\u5668\uff0c\u7528\u4e8e\u63a5\u6536\u6587\u672c\u6570\u636e\uff0c\u63d0\u53d6\u5176\u4e2d\u7684\u9a8c\u8bc1\u7801\uff084-8\u4f4d\u6570\u5b57\uff09\uff0c\u5e76\u5c06\u5176\u590d\u5236\u5230\u526a\u8d34\u677f\uff0c\u540c\u65f6\u663e\u793a\u684c\u9762\u901a\u77e5\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5173\u4e8e\u5982\u4f55\u4f7f\u7528\u60a8\u63d0\u4f9b\u7684 Python \u4ee3\u7801\u521b\u5efa\u5e76\u8fd0\u884c\u4e00\u4e2a\u9a8c\u8bc1\u7801\u63d0\u53d6\u670d\u52a1\u5668\u7684\u7b80\u5355\u6559\u7a0b\u3002\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u8bbe\u5907\uff08\u5982\u624b\u673a\uff09\u63a5\u6536\u9a8c\u8bc1\u7801\u77ed\u4fe1\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u811a\u672c\u5c06\u77ed\u4fe1\u5185\u5bb9\u53d1\u9001\u5230\u6b64\u670d\u52a1\u5668\uff0c\u670d\u52a1\u5668\u4f1a\u81ea\u52a8\u63d0\u53d6\u9a8c\u8bc1\u7801\u5e76\u590d\u5236\u5230\u526a\u8d34\u677f\uff0c\u65b9\u4fbf\u60a8\u7c98\u8d34\u4f7f\u7528\u3002\u540c\u65f6\uff0c\u60a8\u7684\u526a\u8d34\u677f\u5c06\u5305\u542b 123456\uff0c\u5e76\u663e\u793a\u4e00\u4e2a\u684c\u9762\u901a\u77e5\u3002start: \u542f\u52a8\u670d\u52a1\u5668\uff0c\u63a5\u53d7\u5ba2\u6237\u7aef\u8fde\u63a5\u5e76\u5904\u7406\u6570\u636e\u3002_python socket \u767b\u5f55\u9a8c\u8bc1\u529f\u80fd\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/23472.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T23:56:51+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/23472.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/23472.html\",\"name\":\"\u3010Python\u3011\u642d\u5efasocket \u670d\u52a1\u5668\u540c\u6b65\u624b\u673a\u9a8c\u8bc1\u7801\u5230\u7535\u8111 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T23:56:51+00:00\",\"dateModified\":\"2025-04-18T23:56:51+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/23472.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/23472.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/23472.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Python\u3011\u642d\u5efasocket \u670d\u52a1\u5668\u540c\u6b65\u624b\u673a\u9a8c\u8bc1\u7801\u5230\u7535\u8111\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010Python\u3011\u642d\u5efasocket \u670d\u52a1\u5668\u540c\u6b65\u624b\u673a\u9a8c\u8bc1\u7801\u5230\u7535\u8111 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/23472.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Python\u3011\u642d\u5efasocket \u670d\u52a1\u5668\u540c\u6b65\u624b\u673a\u9a8c\u8bc1\u7801\u5230\u7535\u8111 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb880\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u8fd9\u4e2a\u6559\u7a0b\u5c06\u6307\u5bfc\u60a8\u5982\u4f55\u4f7f\u7528 Python \u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 socket \u670d\u52a1\u5668\uff0c\u7528\u4e8e\u63a5\u6536\u6587\u672c\u6570\u636e\uff0c\u63d0\u53d6\u5176\u4e2d\u7684\u9a8c\u8bc1\u7801\uff084-8\u4f4d\u6570\u5b57\uff09\uff0c\u5e76\u5c06\u5176\u590d\u5236\u5230\u526a\u8d34\u677f\uff0c\u540c\u65f6\u663e\u793a\u684c\u9762\u901a\u77e5\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5173\u4e8e\u5982\u4f55\u4f7f\u7528\u60a8\u63d0\u4f9b\u7684 Python \u4ee3\u7801\u521b\u5efa\u5e76\u8fd0\u884c\u4e00\u4e2a\u9a8c\u8bc1\u7801\u63d0\u53d6\u670d\u52a1\u5668\u7684\u7b80\u5355\u6559\u7a0b\u3002\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u8bbe\u5907\uff08\u5982\u624b\u673a\uff09\u63a5\u6536\u9a8c\u8bc1\u7801\u77ed\u4fe1\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u811a\u672c\u5c06\u77ed\u4fe1\u5185\u5bb9\u53d1\u9001\u5230\u6b64\u670d\u52a1\u5668\uff0c\u670d\u52a1\u5668\u4f1a\u81ea\u52a8\u63d0\u53d6\u9a8c\u8bc1\u7801\u5e76\u590d\u5236\u5230\u526a\u8d34\u677f\uff0c\u65b9\u4fbf\u60a8\u7c98\u8d34\u4f7f\u7528\u3002\u540c\u65f6\uff0c\u60a8\u7684\u526a\u8d34\u677f\u5c06\u5305\u542b 123456\uff0c\u5e76\u663e\u793a\u4e00\u4e2a\u684c\u9762\u901a\u77e5\u3002start: \u542f\u52a8\u670d\u52a1\u5668\uff0c\u63a5\u53d7\u5ba2\u6237\u7aef\u8fde\u63a5\u5e76\u5904\u7406\u6570\u636e\u3002_python socket \u767b\u5f55\u9a8c\u8bc1\u529f\u80fd","og_url":"https:\/\/www.wsisp.com\/helps\/23472.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T23:56:51+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/23472.html","url":"https:\/\/www.wsisp.com\/helps\/23472.html","name":"\u3010Python\u3011\u642d\u5efasocket \u670d\u52a1\u5668\u540c\u6b65\u624b\u673a\u9a8c\u8bc1\u7801\u5230\u7535\u8111 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T23:56:51+00:00","dateModified":"2025-04-18T23:56:51+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/23472.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/23472.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/23472.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Python\u3011\u642d\u5efasocket \u670d\u52a1\u5668\u540c\u6b65\u624b\u673a\u9a8c\u8bc1\u7801\u5230\u7535\u8111"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/23472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=23472"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/23472\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=23472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=23472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=23472"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=23472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}