Python网络通信TCP服务端

来源:转载

1.导入Socket from socket import * 2.创建socket server_socket = socket(AF_INET, SOCK_STREAM) 3.绑定IP和Port server_socket.bind(("", 8080)) 4.开始监听 server_socket.listen(10) 5.接收请求 client_socket, client_info = server_socket.accept() 6.接收数据 data = client_socket.recv(2048) 7.处理接收到的数据 print("%s"%data)


8.关闭socket


client_socket.close()


server_socket.close()


分享给朋友:
您可能感兴趣的文章:
随机阅读: