node.js编写服务器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了node.js编写服务器相关的知识,希望对你有一定的参考价值。
1 import socket 2 import sys 3 4 HOST, PORT = "localhost", 8000 5 data = " ".join(sys.argv[1:]) 6 7 # Create a socket (SOCK_STREAM means a TCP socket) 8 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 9 10 try: 11 # Connect to server and send data 12 sock.connect((HOST, PORT)) 13 sock.sendall(bytes(data + "\n", "utf-8")) 14 15 # Receive data from the server and shut down 16 received = str(sock.recv(1024), "utf-8") 17 finally: 18 sock.close() 19 20 print("Sent: {}".format(data)) 21 print("Received: {}".format(received))
以上是关于node.js编写服务器的主要内容,如果未能解决你的问题,请参考以下文章