TCP协议简单套接字通信 客户端

# import socket
# phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# phone.connect(('127.1.1.1',8888))
# phone.send('hello'.encode('utf-8'))
# data=phone.recv(1024)
# print(data)
# phone.close()
'''
b'HELLO'
'''
# import socket
# phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# phone.connect(('127.1.1.1',8888))
# while True:
# msg=input('>>:')
# phone.send(msg.encode('utf-8'))
# data=phone.recv(1024)
# print(data)
# phone.close()
''''''
# import socket
# phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# phone.connect(('127.1.1.1',8888))
# while True:
# msg=input('>>:').strip() # 去掉空格
# if not msg:continue # 有的系统发空不会回复
# phone.send(msg.encode('utf-8'))
# print('has send')
# data=phone.recv(1024)
# print('has recv')
# print(data)
# phone.close()

猜你喜欢

转载自www.cnblogs.com/0B0S/p/12125175.html