socket 
s1=socket.socket();
s1.bind((
'',65533))
s1.listen(
5)
while 1:
    sc,add
=s1.accept()
    
print 'add is :',add
    
print 'content is :',sc.recv(1024)
    sc.send(
"welcome")
    

#client.py

import socket
sc
=socket.socket()
sc.connect((
'localhost',65533))
sc.send(
'bullshitWorld')
print sc.recv(1024)
sc.close()


#example from internet

 
import socket   
sock 
= socket.socket(socket.AF_INET, socket.SOCK_STREAM)   
sock.bind((
'localhost'8001))   
sock.listen(
5)   
while True:   
    connection,address 
= sock.accept()   
    
try:   
        connection.settimeout(
5)   
        buf 
= connection.recv(1024)   
        
if buf == '1':   
            connection.send(
'welcome to server!')   
        
else:   
            connection.send(
'please go out!')   
    
except socket.timeout:   
        
print 'time out'   
        connection.close() 

相关文章:

  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-03-30
  • 2021-05-20
猜你喜欢
  • 2022-12-23
  • 2021-10-19
  • 2021-12-19
  • 2022-12-23
  • 2021-07-09
  • 2021-06-14
  • 2022-12-23
相关资源
相似解决方案