python https://www.quora.com/Does-Python-have-good-support-for-socket-programming/answer/Deepanshu-M

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python https://www.quora.com/Does-Python-have-good-support-for-socket-programming/answer/Deepanshu-M相关的知识,希望对你有一定的参考价值。

import socket
 
ip, port = 'localhost', 9999
 
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((ip, port))
while True:
  data = sock.recv(1024)
  if not data:
    break
  print data 
import threading, SocketServer
 
class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
  pass
 
'''
  Request handler (New thread for each session)
'''
class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
 
  def __init__(self):
    pass
 
  def handle(self):
    # Logic for inbound connections here
    pass
 
HOST, PORT = "localhost", 9999
 
server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
ip, port = server.server_address
 
# Start a thread with the server -- that thread will then start one
# more thread for each request
server_thread = threading.Thread(target=server.serve_forever)
# Exit the server thread when the main thread terminates
server_thread.daemon = True
server_thread.start() 

以上是关于python https://www.quora.com/Does-Python-have-good-support-for-socket-programming/answer/Deepanshu-M的主要内容,如果未能解决你的问题,请参考以下文章

how to study reinforcement learning(answered by Sergio Valcarcel Macua on Quora)

What-are-P-NP-NP-complete-and-NP-hard

How do I code well?

How difficult is it to create a JavaScript framework?

how browser works

亚马逊应用程序使用本机 webview 吗?