??????????????????Python?????дSocketЭ??Server??Client???????????
????1. Python Socket?????
????Socket????????"?????"????ó?????????"?????"?????緢????????????????????
???????????е????????????:stream??datagram??raw??stream??datagram?????????????TCPЭ????н?????raw??????????IPЭ?顣
????Python Socket??????????BSD???????????????????????齨??????TCP??????????????????????https://docs.python.org/2/library/socket.html
????2. Python Socket Server
??????????????

 

# -*- coding:utf-8 -*-
from socket import *
def SocketServer():
try:
Colon = ServerUrl.find(':')
IP = ServerUrl[0:Colon]
Port = int(ServerUrl[Colon+1:])
#????socket????
print 'Server start:%s'%ServerUrl
sockobj = socket(AF_INET?? SOCK_STREAM)
sockobj.setsockopt(SOL_SOCKET??SO_REUSEADDR?? 1)
#??IP????
sockobj.bind((IP?? Port))
#??????????5??????
sockobj.listen(5)
#???????????????????
while True:
#???client????
connection?? address = sockobj.accept( )
print 'Server connected by client:'?? address
while True:
#???Client?????????
data = connection.recv(1024)
#??????data?????????
if not data: break
#????????Client
RES='200 OK'
connection.send(RES)
print 'Receive MSG:%s'%data.strip()
print 'Send RES:%s '%RES
#???Socket
connection.close( )
except Exception??ex:
print ex
ServerUrl = "192.168.16.15:9999"
SocketServer()

????????????????Socket???????????????sockobj.setsockopt(SOL_SOCKET??SO_REUSEADDR?? 1)??????????Python????????Socket Server?????????????????????????