The code is simple, look directly at the code:
The code is 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\ ' s IPv4 address: ')
Ip_match=ip_pattern.match (IP)
If Ip_match:
Break
C.connect ((ip,33333))
While True:
Sms=raw_input (' Input the message 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 ()