码迷,mamicode.com
首页 > 编程语言 > 详细

Python之socket

时间:2018-06-16 11:46:54      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:turn   orm   类型   res   编程   ble   udp   lis   enc   

1.1socket编程之tcp编程

"""
socket类型
sock_stream 面向连接的流套接字,默认值 tcp协议
sock_dgram  无连接的数据报文套接字,udp协议
"""
import socket
s = socket.socket()
s.bind((‘127.0.0.1‘,9999))  #bind接受一个2元祖
s.listen()
"""
Accept a connection. The socket must be bound to an address and listening for connections.
The return value is a pair (conn, address) where conn is a new socket object usable to send and receive data on the connection, 
and address is the address bound to the socket on the other end of the connection
"""
new_socker,info = s.accept() #只接受一个client请求,阻塞
data=new_socker.recv(1024)  #阻塞
print(data)
print(type(data))
new_socker.send(‘back {}‘.format(data).encode())
s.close()

  

 

Python之socket

标签:turn   orm   类型   res   编程   ble   udp   lis   enc   

原文地址:https://www.cnblogs.com/harden13/p/9189869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!