[Python] python实现的简单的socket通信的客户端和服务器端 →→→→→进入此内容的聊天室

来自 , 2019-11-19, 写在 Python, 查看 126 次.
URL http://www.code666.cn/view/249338e6
  1. #!/usr/bin/python           # This is server.py file
  2.  
  3. import socket               # Import socket module
  4.  
  5. s = socket.socket()         # Create a socket object
  6. host = socket.gethostname() # Get local machine name
  7. port = 12345                # Reserve a port for your service.
  8. s.bind((host, port))        # Bind to the port
  9.  
  10. s.listen(5)                 # Now wait for client connection.
  11. while True:
  12.    c, addr = s.accept()     # Establish connection with client.
  13.    print 'Got connection from', addr
  14.    c.send('Thank you for connecting')
  15.    c.close()                # Close the connection
  16.  
  17.  
  18. #//python/8379

回复 "python实现的简单的socket通信的客户端和服务器端"

这儿你可以回复上面这条便签

captcha