Code simple, look at the code directly:
Copy Code code as follows:
Import socket
Import threading
Import re
#import Tkinter
Def ser ():
S=socket.socket (Socket.af_inet,socket. SOCK_STREAM)
S.bind ((', 33333))
S.listen (1)
Conn,addr=s.accept ()
While True:
print ' [%s:%d] send a message to me:%s '% (ADDR[0],ADDR[1],CONN.RECV (1024))
S.close ()
Def CLT ():
c=socket.socket (socket.af_inet,socket. SOCK_STREAM)
ip_pattern=re.compile (R ' ^ (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) \. ( \D{1,2}|1\D\D|2[0-4]\D|25[0-5]) \. (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) \. (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) $ '
while True:
Ip=raw_input (' Input the Server\ ' IPV4 Address: ')
Ip_match=ip_ Pattern.match (IP)
if Ip_match:
Break
C.connect ((ip,33333))
While True:
sms=raw_input (' input, ' want to send: ')
c.sendall (SMS)
c.close ()
If __name__== "__main__":
Ser=threading. Thread (Target=ser)
Clt=threading. Thread (TARGET=CLT)
Ser.start ()
Clt.start ()
Ser.join ()
Clt.join ()