Fork me on GitHub
'''
SOCK_STREAM TCP协议又被称为流逝协议
SOCK_DGRAM UDO协议又被称为数据报协议
'''
# import socket
# phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# phone.bind(('127.1.1.1',8888))
# phone.listen(5)
# print('starting...')
# phone.accept()
# print('>>:')
'''
starting...
'''
# import socket
# phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# # phone.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) # 有的系统IP地址不可以重复,可以在绑定之前用这个办法解决
# phone.bind(('127.1.1.1',8888))
# phone.listen(5)
# print('starting...')
# conn,client_addr=phone.accept()
# print(conn,client_addr)
# data=conn.recv(1024) # 最多收1024bytes
# conn.send(data.upper())
# conn.close()
# phone.close()
'''
starting...
<socket.socket fd=488, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.1.1.1', 8888), raddr=('127.0.0.1', 61589)> ('127.0.0.1', 61589)
'''
# import socket
# phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# phone.bind(('127.1.1.1',8888))
# phone.listen(5)
# print('starting...')
# conn,client_addr=phone.accept()
# print(conn,client_addr)
# while True:
# data=conn.recv(1024)
# conn.send(data.upper())
# conn.close()
# phone.close()
'''
starting...
<socket.socket fd=500, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.1.1.1', 8888), raddr=('127.0.0.1', 62235)> ('127.0.0.1', 62235)
'''
# import socket
# phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# phone.bind(('127.1.1.1',8888))
# phone.listen(5)
# print('starting...')
# conn,client_addr=phone.accept()
# print(conn,client_addr)
# while True:
# data=conn.recv(1024)
# print('客户端消息',data)
# conn.send(data.upper())
# conn.close()
# phone.close()
'''
starting...
<socket.socket fd=544, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.1.1.1', 8888), raddr=('127.0.0.1', 62260)> ('127.0.0.1', 62260)
客户端消息 b'rambo'
'''
# import socket
# phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# phone.bind(('127.1.1.1',8888))
# phone.listen(5)
# print('starting...')
# conn,client_addr=phone.accept()
# print(conn,client_addr)
# while True:
# data=conn.recv(1024)
# print('客户端消息',data)
# conn.send(data.upper())
# print('has send')
# conn.close()
# phone.close()
'''
starting...
<socket.socket fd=528, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.1.1.1', 8888), raddr=('127.0.0.1', 62291)> ('127.0.0.1', 62291)
客户端消息 b'rambo'
has send
'''
# import socket
# phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# print(phone)
# phone.bind(('127.1.1.1',8888))
# phone.listen(5)
# print('starting...')
# conn,client_addr=phone.accept()
# print(conn,client_addr)
# while True:
# data=conn.recv(1024)
# print('客户端消息',data)
# conn.send(data.upper())
# print('has send')
# conn.close()
# phone.close()
'''
<socket.socket fd=124, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>
starting...
'''
'''
两个套接字对象,一个是accept,用来跟客户端来建立三次握手
一种是conn,是accept之后的结果
'''
''''''
# import socket
# phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# phone.bind(('127.1.1.1',8888))
# phone.listen(5)
# print('starting...')
# while True:
# conn,client_addr=phone.accept()
# print(client_addr)
# while True:
# try:
# data=conn.recv(1024)
# if not data:break
# print('客户端消息',data)
# conn.send(data.upper())
# print('has send')
# except ConnectionResetError:
# break
# conn.close()
# phone.close()
posted on 2019-12-31 16:36  OBOS  阅读(203)  评论(0编辑  收藏  举报