码迷,mamicode.com
首页 > Web开发 > 详细

node.js编写服务器

时间:2016-03-15 00:19:09      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

 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编写服务器

标签:

原文地址:http://www.cnblogs.com/liuaqu/p/5277626.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!