{"id":38609,"date":"2025-05-20T17:46:03","date_gmt":"2025-05-20T09:46:03","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/38609.html"},"modified":"2025-05-20T17:46:03","modified_gmt":"2025-05-20T09:46:03","slug":"python-socket%e7%bc%96%e7%a8%8b%ef%bc%9a%e5%ae%9e%e7%8e%b0%e7%ae%80%e5%8d%95%e7%9a%84%e5%ae%a2%e6%88%b7%e7%ab%af-%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%80%9a%e4%bf%a1","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/38609.html","title":{"rendered":"Python Socket\u7f16\u7a0b\uff1a\u5b9e\u73b0\u7b80\u5355\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1"},"content":{"rendered":"<h3>\u76ee\u5f55<\/h3>\n<li>\n<p>\u5f15\u8a00<\/p>\n<\/li>\n<li>\n<p>Socket\u7f16\u7a0b\u57fa\u7840<\/p>\n<\/li>\n<li>\n<p>\u670d\u52a1\u5668\u7aef\u5b9e\u73b0<\/p>\n<\/li>\n<li>\n<p>\u5ba2\u6237\u7aef\u5b9e\u73b0<\/p>\n<\/li>\n<li>\n<p>\u901a\u4fe1\u6d41\u7a0b\u89e3\u6790<\/p>\n<\/li>\n<li>\n<p>\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/p>\n<\/li>\n<li>\n<p>\u5b8c\u6574\u4ee3\u7801<\/p>\n<\/li>\n<h3>\u5f15\u8a00<\/h3>\n<p>\u7f51\u7edc\u7f16\u7a0b\u662f\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206&#xff0c;\u800cSocket\u7f16\u7a0b\u5219\u662f\u7f51\u7edc\u901a\u4fe1\u7684\u57fa\u7840\u3002Python\u901a\u8fc7socket\u6a21\u5757\u63d0\u4f9b\u4e86\u7b80\u5355\u800c\u5f3a\u5927\u7684\u7f51\u7edc\u7f16\u7a0b\u63a5\u53e3\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u7684socket\u6a21\u5757\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u7cfb\u7edf\u3002<\/p>\n<h3>Socket\u7f16\u7a0b\u57fa\u7840<\/h3>\n<p>Socket\u662f\u7f51\u7edc\u901a\u4fe1\u7684\u7aef\u70b9&#xff0c;\u5b83\u5141\u8bb8\u4e0d\u540c\u8ba1\u7b97\u673a\u4e0a\u7684\u7a0b\u5e8f\u8fdb\u884c\u6570\u636e\u4ea4\u6362\u3002\u5728Python\u4e2d&#xff0c;\u6211\u4eec\u4e3b\u8981\u4f7f\u7528\u4e24\u79cd\u7c7b\u578b\u7684socket&#xff1a;<\/p>\n<li>\n<p>\u6d41\u5f0fSocket(SOCK_STREAM)&#xff1a;\u9762\u5411\u8fde\u63a5\u7684\u901a\u4fe1&#xff0c;\u57fa\u4e8eTCP\u534f\u8bae<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u62a5Socket(SOCK_DGRAM)&#xff1a;\u65e0\u8fde\u63a5\u7684\u901a\u4fe1&#xff0c;\u57fa\u4e8eUDP\u534f\u8bae<\/p>\n<\/li>\n<p>\u672c\u6587\u793a\u4f8b\u4f7f\u7528\u7684\u662f\u6d41\u5f0fSocket&#xff0c;\u5373TCP\u901a\u4fe1\u3002<\/p>\n<h3>\u670d\u52a1\u5668\u7aef\u5b9e\u73b0<\/h3>\n<p>\u670d\u52a1\u5668\u7aef\u7684\u4e3b\u8981\u804c\u8d23\u662f\u76d1\u542c\u7279\u5b9a\u7aef\u53e3&#xff0c;\u63a5\u53d7\u5ba2\u6237\u7aef\u8fde\u63a5&#xff0c;\u5e76\u5904\u7406\u5ba2\u6237\u7aef\u53d1\u9001\u7684\u6570\u636e\u3002<\/p>\n<p>from socket import *<\/p>\n<p>IP &#061; &#039;127.0.0.1&#039;  # \u672c\u5730\u56de\u73af\u5730\u5740<br \/>\nPORT &#061; 20000      # \u76d1\u542c\u7684\u7aef\u53e3\u53f7<br \/>\nBUFLEN &#061; 512      # \u7f13\u51b2\u533a\u5927\u5c0f<\/p>\n<p># \u521b\u5efasocket\u5bf9\u8c61<br \/>\nlistenSocket &#061; socket(AF_INET, SOCK_STREAM)<br \/>\n# \u7ed1\u5b9aIP\u548c\u7aef\u53e3<br \/>\nlistenSocket.bind((IP, PORT))<br \/>\n# \u5f00\u59cb\u76d1\u542c&#xff0c;\u8bbe\u7f6e\u6700\u5927\u8fde\u63a5\u6570\u4e3a5<br \/>\nlistenSocket.listen(5)<br \/>\nprint(f&#039;\u7b49\u5f85\u5ba2\u6237\u7aef\u8fde\u63a5&#8230;&#039;)<\/p>\n<p># \u63a5\u53d7\u5ba2\u6237\u7aef\u8fde\u63a5<br \/>\ndataSocket, addr &#061; listenSocket.accept()<br \/>\nprint(f&#039;\u670d\u52a1\u7aef\u5df2\u63a5\u53d7\u5230{addr}\u5ba2\u6237\u7aef\u8fde\u63a5&#039;)<\/p>\n<p>while True:<br \/>\n    # \u63a5\u6536\u5ba2\u6237\u7aef\u6570\u636e<br \/>\n    recved &#061; dataSocket.recv(BUFLEN)<br \/>\n    if not recved:  # \u5982\u679c\u63a5\u6536\u5230\u7a7a\u6570\u636e&#xff0c;\u8868\u793a\u8fde\u63a5\u65ad\u5f00<br \/>\n        break<br \/>\n    info &#061; recved.decode()<br \/>\n    print(f&#039;\u63a5\u6536\u5230\u5ba2\u6237\u7aef\u4fe1\u606f&#xff1a;{info}&#039;)<br \/>\n    # \u5c06\u63a5\u6536\u5230\u7684\u6570\u636e\u539f\u6837\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef<br \/>\n    dataSocket.send(recved)<\/p>\n<p># \u5173\u95edsocket<br \/>\nlistenSocket.close()<br \/>\ndataSocket.close() <\/p>\n<h4>\u5173\u952e\u4ee3\u7801\u89e3\u6790<\/h4>\n<li>\n<p>socket(AF_INET, SOCK_STREAM)&#xff1a;\u521b\u5efaIPv4\u7684TCP socket<\/p>\n<\/li>\n<li>\n<p>bind((IP, PORT))&#xff1a;\u5c06socket\u7ed1\u5b9a\u5230\u7279\u5b9aIP\u548c\u7aef\u53e3<\/p>\n<\/li>\n<li>\n<p>listen(5)&#xff1a;\u5f00\u59cb\u76d1\u542c&#xff0c;\u53c2\u65705\u8868\u793a\u6700\u5927\u7b49\u5f85\u8fde\u63a5\u6570<\/p>\n<\/li>\n<li>\n<p>accept()&#xff1a;\u63a5\u53d7\u5ba2\u6237\u7aef\u8fde\u63a5&#xff0c;\u8fd4\u56de\u65b0\u7684socket\u5bf9\u8c61\u548c\u5ba2\u6237\u7aef\u5730\u5740<\/p>\n<\/li>\n<li>\n<p>recv(BUFLEN)&#xff1a;\u63a5\u6536\u6570\u636e&#xff0c;\u53c2\u6570\u6307\u5b9a\u7f13\u51b2\u533a\u5927\u5c0f<\/p>\n<\/li>\n<li>\n<p>send(data)&#xff1a;\u53d1\u9001\u6570\u636e\u5230\u5ba2\u6237\u7aef<\/p>\n<\/li>\n<h3>\u5ba2\u6237\u7aef\u5b9e\u73b0<\/h3>\n<p>\u5ba2\u6237\u7aef\u8d1f\u8d23\u8fde\u63a5\u5230\u670d\u52a1\u5668&#xff0c;\u53d1\u9001\u6570\u636e\u5e76\u63a5\u6536\u670d\u52a1\u5668\u7684\u54cd\u5e94\u3002<\/p>\n<p>from socket import *<\/p>\n<p>IP &#061; &#039;127.0.0.1&#039;  # \u670d\u52a1\u5668IP\u5730\u5740<br \/>\nPORT &#061; 20000       # \u670d\u52a1\u5668\u7aef\u53e3\u53f7<br \/>\nBUFLEN &#061; 512       # \u7f13\u51b2\u533a\u5927\u5c0f<\/p>\n<p># \u521b\u5efasocket\u5bf9\u8c61<br \/>\ndataSocket &#061; socket(AF_INET, SOCK_STREAM)<br \/>\n# \u8fde\u63a5\u5230\u670d\u52a1\u5668<br \/>\ndataSocket.connect((IP, PORT))<\/p>\n<p>while True:<br \/>\n    toSend &#061; input(&#039;&gt;&gt;&gt;&#039;)<br \/>\n    if toSend &#061;&#061; &#039;EXIT&#039;:  # \u8f93\u5165EXIT\u9000\u51fa<br \/>\n        break<br \/>\n    # \u53d1\u9001\u6570\u636e\u5230\u670d\u52a1\u5668<br \/>\n    dataSocket.send(toSend.encode())<br \/>\n    # \u63a5\u6536\u670d\u52a1\u5668\u54cd\u5e94<br \/>\n    recved &#061; dataSocket.recv(BUFLEN).decode()<br \/>\n    print(f&#039;\u5ba2\u6237\u7aef\u63a5\u6536\u5230\u786e\u8ba4:{recved}&#039;)<\/p>\n<p># \u5173\u95edsocket<br \/>\ndataSocket.close() <\/p>\n<h4>\u5173\u952e\u4ee3\u7801\u89e3\u6790<\/h4>\n<li>\n<p>connect((IP, PORT))&#xff1a;\u8fde\u63a5\u5230\u6307\u5b9a\u7684\u670d\u52a1\u5668IP\u548c\u7aef\u53e3<\/p>\n<\/li>\n<li>\n<p>send(data.encode())&#xff1a;\u53d1\u9001\u6570\u636e&#xff0c;\u6ce8\u610f\u9700\u8981\u5c06\u5b57\u7b26\u4e32\u7f16\u7801\u4e3abytes<\/p>\n<\/li>\n<li>\n<p>recv(BUFLEN).decode()&#xff1a;\u63a5\u6536\u6570\u636e\u5e76\u89e3\u7801\u4e3a\u5b57\u7b26\u4e32<\/p>\n<\/li>\n<li>\n<p>close()&#xff1a;\u5173\u95edsocket\u8fde\u63a5<\/p>\n<\/li>\n<h3>\u901a\u4fe1\u6d41\u7a0b\u89e3\u6790<\/h3>\n<li>\n<p>\u670d\u52a1\u5668\u542f\u52a8&#xff1a;\u670d\u52a1\u5668\u521b\u5efasocket&#xff0c;\u7ed1\u5b9a\u7aef\u53e3\u5e76\u5f00\u59cb\u76d1\u542c<\/p>\n<\/li>\n<li>\n<p>\u5ba2\u6237\u7aef\u8fde\u63a5&#xff1a;\u5ba2\u6237\u7aef\u521b\u5efasocket\u5e76\u8fde\u63a5\u5230\u670d\u52a1\u5668<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u4ea4\u6362&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5ba2\u6237\u7aef\u53d1\u9001\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>\u670d\u52a1\u5668\u63a5\u6536\u5e76\u5904\u7406\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>\u670d\u52a1\u5668\u8fd4\u56de\u54cd\u5e94<\/p>\n<\/li>\n<li>\n<p>\u5ba2\u6237\u7aef\u63a5\u6536\u54cd\u5e94<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u8fde\u63a5\u7ec8\u6b62&#xff1a;\u5ba2\u6237\u7aef\u53d1\u9001&#034;EXIT&#034;\u6216\u5173\u95ed\u8fde\u63a5&#xff0c;\u53cc\u65b9\u5173\u95edsocket<\/p>\n<\/li>\n<h3>\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/h3>\n<li>\n<p>\u7aef\u53e3\u88ab\u5360\u7528&#xff1a;<\/p>\n<p> netstat -ano | findstr &#034;20000&#034; <\/p>\n<p>\u5982\u679c\u53d1\u73b0\u7aef\u53e3\u88ab\u5360\u7528&#xff0c;\u53ef\u4ee5&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u66f4\u6362\u7aef\u53e3\u53f7<\/p>\n<\/li>\n<li>\n<p>\u7ec8\u6b62\u5360\u7528\u7aef\u53e3\u7684\u8fdb\u7a0b<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u8fde\u63a5\u62d2\u7edd\u9519\u8bef&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u786e\u4fdd\u670d\u52a1\u5668\u5148\u8fd0\u884c<\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5IP\u548c\u7aef\u53e3\u662f\u5426\u6b63\u786e<\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5\u9632\u706b\u5899\u8bbe\u7f6e<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6570\u636e\u7f16\u7801\u95ee\u9898&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u53d1\u9001\u524d\u786e\u4fdd\u7f16\u7801(encode())<\/p>\n<\/li>\n<li>\n<p>\u63a5\u6536\u540e\u786e\u4fdd\u89e3\u7801(decode())<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u8d44\u6e90\u91ca\u653e&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u786e\u4fdd\u5728finally\u5757\u6216\u4f7f\u7528with\u8bed\u53e5\u5173\u95edsocket<\/p>\n<\/li>\n<li>\n<p>\u907f\u514d\u8fde\u63a5\u6cc4\u6f0f<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<h3>\u5b8c\u6574\u4ee3\u7801<\/h3>\n<h4>\u670d\u52a1\u5668\u7aef\u4ee3\u7801<\/h4>\n<p>from socket import *<\/p>\n<p>IP &#061; &#039;127.0.0.1&#039;<br \/>\nPORT &#061; 20000<br \/>\nBUFLEN &#061; 512<\/p>\n<p>listenSocket &#061; socket(AF_INET, SOCK_STREAM)<br \/>\nlistenSocket.bind((IP, PORT))<br \/>\nlistenSocket.listen(5)<br \/>\nprint(f&#039;\u7b49\u5f85\u5ba2\u6237\u7aef\u8fde\u63a5&#8230;&#039;)<br \/>\ndataSocket, addr &#061; listenSocket.accept()<br \/>\nprint(f&#039;\u670d\u52a1\u7aef\u5df2\u63a5\u53d7\u5230{addr}\u5ba2\u6237\u7aef\u8fde\u63a5&#039;)<\/p>\n<p>while True:<br \/>\n    recved &#061; dataSocket.recv(BUFLEN)<br \/>\n    if not recved:<br \/>\n        break<br \/>\n    info &#061; recved.decode()<br \/>\n    print(f&#039;\u63a5\u6536\u5230\u5ba2\u6237\u7aef\u4fe1\u606f&#xff1a;{info}&#039;)<br \/>\n    dataSocket.send(recved)<\/p>\n<p>listenSocket.close()<br \/>\ndataSocket.close() <\/p>\n<h4>\u5ba2\u6237\u7aef\u4ee3\u7801<\/h4>\n<p>from socket import *<\/p>\n<p>IP &#061; &#039;127.0.0.1&#039;<br \/>\nPORT &#061; 20000<br \/>\nBUFLEN &#061; 512<\/p>\n<p>dataSocket &#061; socket(AF_INET, SOCK_STREAM)<br \/>\ndataSocket.connect((IP, PORT))<\/p>\n<p>while True:<br \/>\n    toSend &#061; input(&#039;&gt;&gt;&gt;&#039;)<br \/>\n    if toSend &#061;&#061; &#039;EXIT&#039;:<br \/>\n        break<br \/>\n    dataSocket.send(toSend.encode())<br \/>\n    recved &#061; dataSocket.recv(BUFLEN).decode()<br \/>\n    print(f&#039;\u5ba2\u6237\u7aef\u63a5\u6536\u5230\u786e\u8ba4:{recved}&#039;)<\/p>\n<p>dataSocket.close() <\/p>\n<p>\u901a\u8fc7\u8fd9\u4e2a\u7b80\u5355\u7684\u793a\u4f8b&#xff0c;\u6211\u4eec\u5b9e\u73b0\u4e86\u57fa\u672c\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u6a21\u578b\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u4f60\u53ef\u80fd\u9700\u8981\u6dfb\u52a0\u9519\u8bef\u5904\u7406\u3001\u591a\u7ebf\u7a0b\/\u591a\u8fdb\u7a0b\u5904\u7406\u3001\u66f4\u590d\u6742\u7684\u6570\u636e\u534f\u8bae\u7b49\u529f\u80fd\u6765\u6ee1\u8db3\u9700\u6c42\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5e2e\u52a9\u4f60\u7406\u89e3Python Socket\u7f16\u7a0b\u7684\u57fa\u7840\u77e5\u8bc6&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb928\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf5\u6b21\u3002\u8fd9\u7bc7\u535a\u5ba2\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Python\u7684socket\u6a21\u5757\u5b9e\u73b0\u57fa\u672c\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u3002\u6587\u7ae0\u8be6\u7ec6\u8bb2\u89e3\u4e86TCP socket\u7f16\u7a0b\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5305\u62ec\u670d\u52a1\u5668\u7aef\u7684\u7aef\u53e3\u7ed1\u5b9a\u3001\u76d1\u542c\u548c\u8fde\u63a5\u63a5\u53d7\uff0c\u4ee5\u53ca\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u5efa\u7acb\u548c\u6570\u636e\u6536\u53d1\u3002\u901a\u8fc7\u6e05\u6670\u7684\u4ee3\u7801\u793a\u4f8b\u5c55\u793a\u4e86\u5b8c\u6574\u7684\u901a\u4fe1\u6d41\u7a0b\uff0c\u5e76\u5bf9\u5173\u952e\u4ee3\u7801\u8fdb\u884c\u4e86\u9010\u884c\u89e3\u6790\u3002\u6b64\u5916\uff0c\u535a\u5ba2\u8fd8\u63d0\u4f9b\u4e86\u68c0\u67e5\u7aef\u53e3\u5360\u7528\u7684\u65b9\u6cd5\uff08netstat\u547d\u4ee4\uff09\u548c\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6848\uff0c\u6700\u540e\u7ed9\u51fa\u4e86\u53ef\u76f4\u63a5\u590d\u7528\u7684\u5b8c\u6574\u811a\u672c\u3002\u8fd9\u7bc7\u6559\u7a0b\u9002\u5408\u7f51\u7edc\u7f16\u7a0b\u521d\u5b66\u8005\u5feb\u901f\u638c\u63e1Python socket\u7684\u57fa\u672c\u4f7f\u7528\u65b9\u6cd5\u3002<\/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,43,78,3421],"topic":[],"class_list":["post-38609","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-43","tag-78","tag-3421"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Socket\u7f16\u7a0b\uff1a\u5b9e\u73b0\u7b80\u5355\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1 - \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\/38609.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Socket\u7f16\u7a0b\uff1a\u5b9e\u73b0\u7b80\u5355\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb928\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf5\u6b21\u3002\u8fd9\u7bc7\u535a\u5ba2\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Python\u7684socket\u6a21\u5757\u5b9e\u73b0\u57fa\u672c\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u3002\u6587\u7ae0\u8be6\u7ec6\u8bb2\u89e3\u4e86TCP socket\u7f16\u7a0b\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5305\u62ec\u670d\u52a1\u5668\u7aef\u7684\u7aef\u53e3\u7ed1\u5b9a\u3001\u76d1\u542c\u548c\u8fde\u63a5\u63a5\u53d7\uff0c\u4ee5\u53ca\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u5efa\u7acb\u548c\u6570\u636e\u6536\u53d1\u3002\u901a\u8fc7\u6e05\u6670\u7684\u4ee3\u7801\u793a\u4f8b\u5c55\u793a\u4e86\u5b8c\u6574\u7684\u901a\u4fe1\u6d41\u7a0b\uff0c\u5e76\u5bf9\u5173\u952e\u4ee3\u7801\u8fdb\u884c\u4e86\u9010\u884c\u89e3\u6790\u3002\u6b64\u5916\uff0c\u535a\u5ba2\u8fd8\u63d0\u4f9b\u4e86\u68c0\u67e5\u7aef\u53e3\u5360\u7528\u7684\u65b9\u6cd5\uff08netstat\u547d\u4ee4\uff09\u548c\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6848\uff0c\u6700\u540e\u7ed9\u51fa\u4e86\u53ef\u76f4\u63a5\u590d\u7528\u7684\u5b8c\u6574\u811a\u672c\u3002\u8fd9\u7bc7\u6559\u7a0b\u9002\u5408\u7f51\u7edc\u7f16\u7a0b\u521d\u5b66\u8005\u5feb\u901f\u638c\u63e1Python socket\u7684\u57fa\u672c\u4f7f\u7528\u65b9\u6cd5\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/38609.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-20T09:46:03+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\/38609.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/38609.html\",\"name\":\"Python Socket\u7f16\u7a0b\uff1a\u5b9e\u73b0\u7b80\u5355\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-20T09:46:03+00:00\",\"dateModified\":\"2025-05-20T09:46:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/38609.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/38609.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38609.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Socket\u7f16\u7a0b\uff1a\u5b9e\u73b0\u7b80\u5355\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\"}]},{\"@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":"Python Socket\u7f16\u7a0b\uff1a\u5b9e\u73b0\u7b80\u5355\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1 - \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\/38609.html","og_locale":"zh_CN","og_type":"article","og_title":"Python Socket\u7f16\u7a0b\uff1a\u5b9e\u73b0\u7b80\u5355\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb928\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf5\u6b21\u3002\u8fd9\u7bc7\u535a\u5ba2\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Python\u7684socket\u6a21\u5757\u5b9e\u73b0\u57fa\u672c\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u3002\u6587\u7ae0\u8be6\u7ec6\u8bb2\u89e3\u4e86TCP socket\u7f16\u7a0b\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5305\u62ec\u670d\u52a1\u5668\u7aef\u7684\u7aef\u53e3\u7ed1\u5b9a\u3001\u76d1\u542c\u548c\u8fde\u63a5\u63a5\u53d7\uff0c\u4ee5\u53ca\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u5efa\u7acb\u548c\u6570\u636e\u6536\u53d1\u3002\u901a\u8fc7\u6e05\u6670\u7684\u4ee3\u7801\u793a\u4f8b\u5c55\u793a\u4e86\u5b8c\u6574\u7684\u901a\u4fe1\u6d41\u7a0b\uff0c\u5e76\u5bf9\u5173\u952e\u4ee3\u7801\u8fdb\u884c\u4e86\u9010\u884c\u89e3\u6790\u3002\u6b64\u5916\uff0c\u535a\u5ba2\u8fd8\u63d0\u4f9b\u4e86\u68c0\u67e5\u7aef\u53e3\u5360\u7528\u7684\u65b9\u6cd5\uff08netstat\u547d\u4ee4\uff09\u548c\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6848\uff0c\u6700\u540e\u7ed9\u51fa\u4e86\u53ef\u76f4\u63a5\u590d\u7528\u7684\u5b8c\u6574\u811a\u672c\u3002\u8fd9\u7bc7\u6559\u7a0b\u9002\u5408\u7f51\u7edc\u7f16\u7a0b\u521d\u5b66\u8005\u5feb\u901f\u638c\u63e1Python socket\u7684\u57fa\u672c\u4f7f\u7528\u65b9\u6cd5\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/38609.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-20T09:46:03+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\/38609.html","url":"https:\/\/www.wsisp.com\/helps\/38609.html","name":"Python Socket\u7f16\u7a0b\uff1a\u5b9e\u73b0\u7b80\u5355\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-20T09:46:03+00:00","dateModified":"2025-05-20T09:46:03+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/38609.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/38609.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/38609.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python Socket\u7f16\u7a0b\uff1a\u5b9e\u73b0\u7b80\u5355\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1"}]},{"@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\/38609","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=38609"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38609\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=38609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=38609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=38609"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=38609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}