Server.py(首先运行)
import
socket
s = socket.socket()
s.bind(( ' 127.0.0.1 ' , 1358 ))
s.listen( 5 )
cs,address = s.accept()
print ' got connected from ' ,address
cs.send( ' byebye ' )
ra = cs.recv( 512 )
print ra
cs.close()
s = socket.socket()
s.bind(( ' 127.0.0.1 ' , 1358 ))
s.listen( 5 )
cs,address = s.accept()
print ' got connected from ' ,address
cs.send( ' byebye ' )
ra = cs.recv( 512 )
print ra
cs.close()
Client.py
import
socket
s = socket.socket()
s.connect(( ' 127.0.0.1 ' , 1358 ))
data = s.recv( 512 )
s.send( ' hihi ' )
s.close()
print ' the data received is ' ,data
s = socket.socket()
s.connect(( ' 127.0.0.1 ' , 1358 ))
data = s.recv( 512 )
s.send( ' hihi ' )
s.close()
print ' the data received is ' ,data