{"id":1036167,"date":"2024-12-31T12:04:46","date_gmt":"2024-12-31T04:04:46","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1036167.html"},"modified":"2024-12-31T12:04:48","modified_gmt":"2024-12-31T04:04:48","slug":"python%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e4%b8%a4%e5%8f%b0%e7%94%b5%e8%84%91%e9%80%9a%e4%bf%a1","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1036167.html","title":{"rendered":"Python\u5982\u4f55\u5b9e\u73b0\u4e24\u53f0\u7535\u8111\u901a\u4fe1"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/71153f9b-8a22-4ec4-8bc6-40d6e49d10db.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"Python\u5982\u4f55\u5b9e\u73b0\u4e24\u53f0\u7535\u8111\u901a\u4fe1\" \/><\/p>\n<p><p> <strong>Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u4e24\u53f0\u7535\u8111\u901a\u4fe1\uff0c\u5305\u62ec\u4f7f\u7528\u5957\u63a5\u5b57\u7f16\u7a0b\u3001HTTP\u8bf7\u6c42\u3001RPC\uff08\u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528\uff09\u548c\u6d88\u606f\u961f\u5217\u7b49\u3002\u5176\u4e2d\uff0c\u5957\u63a5\u5b57\u7f16\u7a0b\u662f\u6700\u5e38\u89c1\u548c\u57fa\u7840\u7684\u65b9\u5f0f\uff0c\u5b83\u5141\u8bb8\u4e24\u53f0\u8ba1\u7b97\u673a\u901a\u8fc7\u7f51\u7edc\u8fdb\u884c\u6570\u636e\u4f20\u8f93\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u5957\u63a5\u5b57\u7f16\u7a0b\u5b9e\u73b0\u4e24\u53f0\u7535\u8111\u901a\u4fe1\u7684\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u670d\u52a1\u5668\u7aef\u7a0b\u5e8f\uff0c\u5b83\u4f1a\u76d1\u542c\u67d0\u4e2a\u7aef\u53e3\uff0c\u7b49\u5f85\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u8bf7\u6c42\uff1b\u7136\u540e\uff0c\u521b\u5efa\u4e00\u4e2a\u5ba2\u6237\u7aef\u7a0b\u5e8f\uff0c\u5b83\u4f1a\u8fde\u63a5\u5230\u670d\u52a1\u5668\u7684\u6307\u5b9a\u7aef\u53e3\uff0c\u8fdb\u884c\u6570\u636e\u4f20\u8f93\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5\u548c\u8bbe\u7f6e\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u7684Python\u73af\u5883\u5b89\u88c5\u6b63\u786e\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528Python\u7684\u6807\u51c6\u5e93\u4e2d\u7684<code>socket<\/code>\u6a21\u5757\uff0c\u5b83\u63d0\u4f9b\u4e86\u6240\u6709\u5fc5\u8981\u7684\u5de5\u5177\u6765\u8fdb\u884c\u7f51\u7edc\u7f16\u7a0b\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Python<\/strong>\uff1a\u786e\u4fdd\u4f60\u5728\u4e24\u53f0\u7535\u8111\u4e0a\u90fd\u5b89\u88c5\u4e86Python\u3002\u53ef\u4ee5\u8bbf\u95ee<a href=\"https:\/\/www.python.org\/\">Python\u5b98\u7f51<\/a>\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u68c0\u67e5\u7f51\u7edc\u8fde\u63a5<\/strong>\uff1a\u786e\u4fdd\u4e24\u53f0\u7535\u8111\u80fd\u591f\u901a\u8fc7\u7f51\u7edc\u4e92\u76f8\u8bbf\u95ee\uff0c\u53ef\u4ee5\u4f7f\u7528<code>ping<\/code>\u547d\u4ee4\u68c0\u67e5\u7f51\u7edc\u8fde\u901a\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u57fa\u7840\u6982\u5ff5<\/h3>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u5957\u63a5\u5b57\u7f16\u7a0b\u524d\uff0c\u4e86\u89e3\u4e00\u4e9b\u57fa\u7840\u6982\u5ff5\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>Socket<\/strong>\uff1a\u5957\u63a5\u5b57\u662f\u7f51\u7edc\u901a\u8baf\u7684\u4e00\u4e2a\u7aef\u70b9\uff0c\u53ef\u4ee5\u662f\u670d\u52a1\u5668\u7aef\uff0c\u4e5f\u53ef\u4ee5\u662f\u5ba2\u6237\u7aef\u3002<\/li>\n<li><strong>IP\u5730\u5740<\/strong>\uff1a\u6bcf\u4e2a\u7f51\u7edc\u8bbe\u5907\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684IP\u5730\u5740\uff0c\u7528\u6765\u6807\u8bc6\u8bbe\u5907\u3002<\/li>\n<li><strong>\u7aef\u53e3<\/strong>\uff1a\u7aef\u53e3\u662f\u7528\u6765\u533a\u5206\u540c\u4e00\u53f0\u7535\u8111\u4e0a\u7684\u4e0d\u540c\u7f51\u7edc\u670d\u52a1\u7684\u7f16\u53f7\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u521b\u5efa\u670d\u52a1\u5668\u7aef\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u670d\u52a1\u5668\u7aef\u7a0b\u5e8f\u4e3b\u8981\u8d1f\u8d23\u76d1\u542c\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u8bf7\u6c42\uff0c\u5e76\u5904\u7406\u8fd9\u4e9b\u8bf7\u6c42\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u670d\u52a1\u5668\u7aef\u7a0b\u5e8f\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import socket<\/p>\n<p>def server_program():<\/p>\n<p>    host = socket.gethostname()  # \u83b7\u53d6\u672c\u5730\u4e3b\u673a\u540d<\/p>\n<p>    port = 5000  # \u8bbe\u7f6e\u7aef\u53e3\u53f7<\/p>\n<p>    server_socket = socket.socket()  # \u521b\u5efa\u5957\u63a5\u5b57\u5bf9\u8c61<\/p>\n<p>    server_socket.bind((host, port))  # \u7ed1\u5b9a\u4e3b\u673a\u5730\u5740\u548c\u7aef\u53e3\u53f7<\/p>\n<p>    server_socket.listen(2)  # \u76d1\u542c\u8fde\u63a5\u8bf7\u6c42\uff0c\u6700\u591a\u5141\u8bb82\u4e2a\u8fde\u63a5<\/p>\n<p>    conn, address = server_socket.accept()  # \u63a5\u53d7\u65b0\u8fde\u63a5<\/p>\n<p>    print(&quot;Connection from: &quot; + str(address))<\/p>\n<p>    while True:<\/p>\n<p>        # \u63a5\u6536\u6570\u636e<\/p>\n<p>        data = conn.recv(1024).decode()<\/p>\n<p>        if not data:<\/p>\n<p>            # \u5982\u679c\u6ca1\u6709\u6570\u636e\uff0c\u9000\u51fa\u5faa\u73af<\/p>\n<p>            break<\/p>\n<p>        print(&quot;from connected user: &quot; + str(data))<\/p>\n<p>        # \u53d1\u9001\u6570\u636e<\/p>\n<p>        data = input(&#39; -&gt; &#39;)<\/p>\n<p>        conn.send(data.encode())<\/p>\n<p>    conn.close()  # \u5173\u95ed\u8fde\u63a5<\/p>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    server_program()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u521b\u5efa\u5ba2\u6237\u7aef\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u5ba2\u6237\u7aef\u7a0b\u5e8f\u8d1f\u8d23\u8fde\u63a5\u5230\u670d\u52a1\u5668\uff0c\u5e76\u4e0e\u670d\u52a1\u5668\u8fdb\u884c\u6570\u636e\u4ea4\u6362\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5ba2\u6237\u7aef\u7a0b\u5e8f\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import socket<\/p>\n<p>def client_program():<\/p>\n<p>    host = socket.gethostname()  # \u83b7\u53d6\u672c\u5730\u4e3b\u673a\u540d<\/p>\n<p>    port = 5000  # \u8bbe\u7f6e\u670d\u52a1\u5668\u7aef\u53e3\u53f7<\/p>\n<p>    client_socket = socket.socket()  # \u521b\u5efa\u5957\u63a5\u5b57\u5bf9\u8c61<\/p>\n<p>    client_socket.connect((host, port))  # \u8fde\u63a5\u5230\u670d\u52a1\u5668<\/p>\n<p>    message = input(&quot; -&gt; &quot;)  # \u83b7\u53d6\u7528\u6237\u8f93\u5165<\/p>\n<p>    while message.lower().strip() != &#39;bye&#39;:<\/p>\n<p>        client_socket.send(message.encode())  # \u53d1\u9001\u6570\u636e<\/p>\n<p>        data = client_socket.recv(1024).decode()  # \u63a5\u6536\u6570\u636e<\/p>\n<p>        print(&#39;Received from server: &#39; + data)  # \u663e\u793a\u670d\u52a1\u5668\u8fd4\u56de\u7684\u6570\u636e<\/p>\n<p>        message = input(&quot; -&gt; &quot;)  # \u7ee7\u7eed\u83b7\u53d6\u7528\u6237\u8f93\u5165<\/p>\n<p>    client_socket.close()  # \u5173\u95ed\u8fde\u63a5<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    client_program()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u542f\u52a8\u670d\u52a1\u5668\u7aef<\/strong>\uff1a\u5728\u4e00\u53f0\u7535\u8111\u4e0a\u8fd0\u884c\u670d\u52a1\u5668\u7aef\u7a0b\u5e8f\u3002\u5b83\u4f1a\u5728\u6307\u5b9a\u7684\u7aef\u53e3\u4e0a\u76d1\u542c\u8fde\u63a5\u8bf7\u6c42\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u542f\u52a8\u5ba2\u6237\u7aef<\/strong>\uff1a\u5728\u53e6\u4e00\u53f0\u7535\u8111\u4e0a\u8fd0\u884c\u5ba2\u6237\u7aef\u7a0b\u5e8f\uff0c\u8fde\u63a5\u5230\u670d\u52a1\u5668\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fdb\u884c\u901a\u4fe1<\/strong>\uff1a\u5ba2\u6237\u7aef\u53ef\u4ee5\u53d1\u9001\u6570\u636e\u5230\u670d\u52a1\u5668\uff0c\u670d\u52a1\u5668\u63a5\u6536\u5230\u6570\u636e\u540e\uff0c\u53ef\u4ee5\u5904\u7406\u5e76\u8fd4\u56de\u6570\u636e\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u5904\u7406\u591a\u5ba2\u6237\u7aef\u8fde\u63a5<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u670d\u52a1\u5668\u901a\u5e38\u9700\u8981\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u8bf7\u6c42\u3002\u53ef\u4ee5\u4f7f\u7528\u591a\u7ebf\u7a0b\u6216\u5f02\u6b65\u7f16\u7a0b\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528\u591a\u7ebf\u7a0b\u5904\u7406\u591a\u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import socket<\/p>\n<p>import threading<\/p>\n<p>def handle_client(conn, address):<\/p>\n<p>    print(&quot;New connection from: &quot; + str(address))<\/p>\n<p>    while True:<\/p>\n<p>        data = conn.recv(1024).decode()<\/p>\n<p>        if not data:<\/p>\n<p>            break<\/p>\n<p>        print(&quot;from &quot; + str(address) + &quot;: &quot; + str(data))<\/p>\n<p>        conn.send(data.encode())<\/p>\n<p>    conn.close()<\/p>\n<p>def server_program():<\/p>\n<p>    host = socket.gethostname()<\/p>\n<p>    port = 5000<\/p>\n<p>    server_socket = socket.socket()<\/p>\n<p>    server_socket.bind((host, port))<\/p>\n<p>    server_socket.listen(5)<\/p>\n<p>    print(&quot;Server started, waiting for connections...&quot;)<\/p>\n<p>    while True:<\/p>\n<p>        conn, address = server_socket.accept()<\/p>\n<p>        threading.Thread(target=handle_client, args=(conn, address)).start()<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    server_program()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u9519\u8bef\u5904\u7406\u548c\u8c03\u8bd5<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u7f51\u7edc\u901a\u4fe1\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5982\u7f51\u7edc\u5ef6\u8fdf\u3001\u8fde\u63a5\u4e2d\u65ad\u7b49\u3002\u9700\u8981\u52a0\u5165\u9002\u5f53\u7684\u9519\u8bef\u5904\u7406\u548c\u8c03\u8bd5\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import socket<\/p>\n<p>import threading<\/p>\n<p>def handle_client(conn, address):<\/p>\n<p>    print(&quot;New connection from: &quot; + str(address))<\/p>\n<p>    while True:<\/p>\n<p>        try:<\/p>\n<p>            data = conn.recv(1024).decode()<\/p>\n<p>            if not data:<\/p>\n<p>                break<\/p>\n<p>            print(&quot;from &quot; + str(address) + &quot;: &quot; + str(data))<\/p>\n<p>            conn.send(data.encode())<\/p>\n<p>        except Exception as e:<\/p>\n<p>            print(f&quot;Error: {e}&quot;)<\/p>\n<p>            break<\/p>\n<p>    conn.close()<\/p>\n<p>def server_program():<\/p>\n<p>    host = socket.gethostname()<\/p>\n<p>    port = 5000<\/p>\n<p>    server_socket = socket.socket()<\/p>\n<p>    server_socket.bind((host, port))<\/p>\n<p>    server_socket.listen(5)<\/p>\n<p>    print(&quot;Server started, waiting for connections...&quot;)<\/p>\n<p>    while True:<\/p>\n<p>        conn, address = server_socket.accept()<\/p>\n<p>        threading.Thread(target=handle_client, args=(conn, address)).start()<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    server_program()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u4f7f\u7528\u66f4\u9ad8\u7ea7\u7684\u901a\u4fe1\u534f\u8bae<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u5957\u63a5\u5b57\u7f16\u7a0b\uff0cPython\u8fd8\u652f\u6301\u4f7f\u7528\u66f4\u9ad8\u7ea7\u7684\u901a\u4fe1\u534f\u8bae\uff0c\u5982HTTP\u3001WebSocket\u3001RPC\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>HTTP\u534f\u8bae<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528<code>requests<\/code>\u5e93\u8fdb\u884cHTTP\u8bf7\u6c42\uff0c\u4f7f\u7528<code>Flask<\/code>\u6216<code>Django<\/code>\u6846\u67b6\u642d\u5efaHTTP\u670d\u52a1\u5668\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>WebSocket\u534f\u8bae<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528<code>websockets<\/code>\u5e93\u5b9e\u73b0\u5b9e\u65f6\u53cc\u5411\u901a\u4fe1\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>RPC\u534f\u8bae<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528<code>xmlrpc<\/code>\u6216<code>gRPC<\/code>\u5b9e\u73b0\u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4ee5\u4e0b\u662f\u4f7f\u7528<code>Flask<\/code>\u6846\u67b6\u5b9e\u73b0HTTP\u901a\u4fe1\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, request, jsonify<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>@app.route(&#39;\/message&#39;, methods=[&#39;POST&#39;])<\/p>\n<p>def message():<\/p>\n<p>    data = request.json<\/p>\n<p>    print(&quot;Received message: &quot; + data[&#39;message&#39;])<\/p>\n<p>    return jsonify({&quot;response&quot;: &quot;Message received&quot;})<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    app.run(host=&#39;0.0.0.0&#39;, port=5000)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5ba2\u6237\u7aef\u53ef\u4ee5\u4f7f\u7528<code>requests<\/code>\u5e93\u53d1\u9001HTTP\u8bf7\u6c42\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>url = &#39;http:\/\/&lt;server_ip&gt;:5000\/message&#39;<\/p>\n<p>data = {&quot;message&quot;: &quot;Hello, server&quot;}<\/p>\n<p>response = requests.post(url, json=data)<\/p>\n<p>print(response.json())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e5d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u4ecb\u7ecd\uff0c\u53ef\u4ee5\u770b\u51fa\uff0c<strong>Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u4e24\u53f0\u7535\u8111\u901a\u4fe1\uff0c\u5305\u62ec\u5957\u63a5\u5b57\u7f16\u7a0b\u3001HTTP\u8bf7\u6c42\u3001RPC\u3001\u6d88\u606f\u961f\u5217\u7b49\u3002<\/strong> \u6bcf\u79cd\u65b9\u5f0f\u90fd\u6709\u5176\u9002\u7528\u7684\u573a\u666f\u548c\u4f18\u7f3a\u70b9\uff0c\u9009\u62e9\u5408\u9002\u7684\u901a\u4fe1\u65b9\u5f0f\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u7cfb\u7edf\u6027\u80fd\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u9700\u8981\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u901a\u4fe1\u65b9\u5f0f\uff0c\u5e76\u52a0\u5165\u9002\u5f53\u7684\u9519\u8bef\u5904\u7406\u548c\u8c03\u8bd5\u4fe1\u606f\uff0c\u786e\u4fdd\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bbe\u7f6e\u4e24\u53f0\u7535\u8111\u4e4b\u95f4\u7684\u7f51\u7edc\u901a\u4fe1\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5957\u63a5\u5b57\uff08socket\uff09\u5e93\u6765\u5b9e\u73b0\u4e24\u53f0\u7535\u8111\u4e4b\u95f4\u7684\u7f51\u7edc\u901a\u4fe1\u3002\u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u4e24\u53f0\u7535\u8111\u5728\u540c\u4e00\u7f51\u7edc\u4e2d\u3002\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u670d\u52a1\u5668\u7aef\u548c\u5ba2\u6237\u7aef\u8fdb\u884c\u901a\u4fe1\u3002\u670d\u52a1\u5668\u7aef\u4f7f\u7528<code>socket.socket()<\/code>\u521b\u5efa\u4e00\u4e2a\u5957\u63a5\u5b57\u5e76\u76d1\u542c\u8fde\u63a5\uff0c\u800c\u5ba2\u6237\u7aef\u5219\u4f7f\u7528\u76f8\u540c\u7684\u65b9\u6cd5\u8fde\u63a5\u5230\u670d\u52a1\u5668\u3002\u4ee3\u7801\u793a\u4f8b\u53ef\u4ee5\u53c2\u8003Python\u7684\u5b98\u65b9\u6587\u6863\u3002<\/p>\n<p><strong>\u4e24\u53f0\u7535\u8111\u901a\u4fe1\u65f6\uff0c\u9700\u8981\u8003\u8651\u54ea\u4e9b\u7f51\u7edc\u914d\u7f6e\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u4e24\u53f0\u7535\u8111\u901a\u4fe1\u4e4b\u524d\uff0c\u786e\u4fdd\u9632\u706b\u5899\u5141\u8bb8\u901a\u4fe1\u7aef\u53e3\u7684\u6d41\u91cf\u3002\u6b64\u5916\uff0c\u786e\u8ba4\u4e24\u53f0\u7535\u8111\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\u662f\u5426\u6b63\u786e\u914d\u7f6e\u3002\u5982\u679c\u4f7f\u7528\u7684\u662f\u8def\u7531\u5668\uff0c\u53ef\u80fd\u9700\u8981\u8bbe\u7f6e\u7aef\u53e3\u8f6c\u53d1\uff0c\u786e\u4fdd\u5916\u90e8\u8fde\u63a5\u80fd\u591f\u8bbf\u95ee\u5185\u90e8\u7f51\u7edc\u4e2d\u7684\u8ba1\u7b97\u673a\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u901a\u4fe1\u4e2d\u7684\u6570\u636e\u4f20\u8f93\u548c\u9519\u8bef\uff1f<\/strong><br \/>\u5728Python\u901a\u4fe1\u4e2d\uff0c\u4f7f\u7528\u5957\u63a5\u5b57\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u5faa\u73af\u63a5\u6536\u548c\u53d1\u9001\u6570\u636e\u3002\u786e\u4fdd\u5b9e\u73b0\u6570\u636e\u7684\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\uff0c\u5e38\u7528\u7684\u65b9\u5f0f\u6709JSON\u6216pickle\u6a21\u5757\u3002\u6b64\u5916\uff0c\u5904\u7406\u53ef\u80fd\u51fa\u73b0\u7684\u5f02\u5e38\u60c5\u51b5\uff0c\u5982\u8fde\u63a5\u4e2d\u65ad\u3001\u6570\u636e\u4e22\u5931\u7b49\uff0c\u4f7f\u7528try-except\u8bed\u53e5\u6765\u6355\u83b7\u548c\u5904\u7406\u9519\u8bef\uff0c\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u4e24\u53f0\u7535\u8111\u901a\u4fe1\uff0c\u5305\u62ec\u4f7f\u7528\u5957\u63a5\u5b57\u7f16\u7a0b\u3001HTTP\u8bf7\u6c42\u3001RPC\uff08\u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528\uff09\u548c\u6d88\u606f\u961f [&hellip;]","protected":false},"author":3,"featured_media":1036175,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1036167"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1036167"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1036167\/revisions"}],"predecessor-version":[{"id":1036177,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1036167\/revisions\/1036177"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1036175"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1036167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1036167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1036167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}