3. Python Socket Client
  实现代码如下

 

# -*- coding:utf-8 -*-
from socket import *
def SocketClient():
try:
#建立socket对象
s=socket(AF_INET,SOCK_STREAM,0)
Colon = ServerUrl.find(':')
IP = ServerUrl[0:Colon]
Port = ServerUrl[Colon+1:]
#建立连接
s.connect((IP,int(Port)))
sdata='GET /Test HTTP/1.1
Host: %s '%ServerUrl
print "Request: %s "%sdata
s.send(sdata)
sresult=s.recv(1024)
print "Response: %s " %sresult
#关闭Socket
s.close()
except Exception,ex:
print ex
ServerUrl = "192.168.16.15:9999"
SocketClient()

  4. 运行结果
  Socket Server端运行截图如下:

  Socket-Server
  Socket Client端运行截图如下: