本文整理汇总了Python中socket.socket.recv函数的典型用法代码示例。如果您正苦于以下问题:Python recv函数的具体用法?Python recv怎么用?Python recv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了recv函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self,db):
self._ipcPath=db.getSettingPath()
SocketlikeIPC.__init__(self, self._ipcPath)
# super(type(self),self).__init__(self._ipcPath)
# if super(type(self),self)._connect():
if SocketlikeIPC._connect(self):
print('IPC connect succeed. Welcome back, administrator.')
return
print('IPC failed. proceeding with TCP.')
super(type(self)) #unbound
socket.__init__(self)
try:
socket.connect(self,('racu.idea.sh', PortEnum.MAIN_SERVER.value))
lastPin = db.getConfig()
print('lastPin =', lastPin, len(lastPin))
pinmsg = int.to_bytes(SocketEnum.PIN.value, 1, 'big') + int.to_bytes(lastPin[0]) if 10**3<=lastPin['lastPIN']<10**4 else b''
msg = ''
# while not msg:
socket.sendall(self,pinmsg)
msg = socket.recv(self)
if not msg:
print('main server connect error')
return
except:
print('main server connect error')
示例2: recv
def recv(self, buflen=1024, flags=0):
self._checkClosed()
if self._sslobj:
if flags != 0:
raise ValueError('non-zero flags not allowed in calls to recv() on %s' % self.__class__)
return self.read(buflen)
return socket.recv(self, buflen, flags)
示例3: recv
def recv(self, buflen=1024, flags=0):
if self._sslobj:
if flags != 0:
raise ValueError("non-zero flags not allowed in calls to recv() on %s" % self.__class__)
return self.read(buflen)
else:
return socket.recv(self, buflen, flags)
示例4: recv
def recv(self, buffersize, flags = 0, raw = False):
if not raw:
data = self._sslobj.recv(buffersize, flags)
#print("RECV: {0}".format(data))
return data
else:
data = socket.recv(self, buffersize, flags)
#print("RECV (raw): {0}".format(data))
return data
示例5: getRequest
def getRequest (socket) :
"""
receive bytes from a socket
socket the socket of the client
return a string containing the client's request
"""
request = socket.recv(MAX_FILE_SIZE)
request = bytes.decode(request)
print(request)
return request
示例6: recvFile
def recvFile(socket, numBytes):
# Retrieve the given number of bytes.
data = "";
while len(data) < numBytes:
try:
data += socket.recv(numBytes - len(data))
except Exception as e:
print e.strerror
sys.exit(1);
return data
示例7: send
def send(self, topic, msg):
if type(topic) != bytes:
topic = bytes(str(topic), 'utf-8')
messagedata = bytes(json.dumps(msg), 'utf-8')
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect(self._relay_in)
socket.send(topic + b' ' + messagedata)
reply = socket.recv()
assert reply
示例8: receiveData
def receiveData(socket, bytesNumber):
# data will collect the number of bytes
# will be called a number of times
# source: http://stackoverflow.com/questions/7174927/when-does-socket-recvrecv-size-return
data = "";
while len(data) < bytesNumber:
try:
data += socket.recv(bytesNumber - len(data))
except Exception as e:
print e.strerror
sys.exit(1);
return data
示例9: readClientMessage
def readClientMessage(self, socket):
data = socket.recv(1024)
if not data:
socket.close()
self.sockets.remove(socket)
return None
else:
print '\tRead:', data, 'on', id(socket)
tokens = string.split(data)
return tokens
示例10: recv
def recv (self, buflen=1024, flags=0):
if self._sslobj:
if flags != 0:
raise ValueError(
"non-zero flags not allowed in calls to sendall() on %s" %
self.__class__)
while True:
try:
return self.read(buflen)
except SSLError, x:
if x.args[0] == SSL_ERROR_WANT_READ:
continue
else:
raise x
else:
return socket.recv(self, buflen, flags)
def recv_into (self, buffer, nbytes=None, flags=0):
if buffer and (nbytes is None):
nbytes = len(buffer)
elif nbytes is None:
nbytes = 1024
if self._sslobj:
if flags != 0:
raise ValueError(
"non-zero flags not allowed in calls to recv_into() on %s" %
self.__class__)
while True:
try:
tmp_buffer = self.read(nbytes)
v = len(tmp_buffer)
示例11: recv
def recv(self, *args, **kwargs):
time.sleep(random.random() * seconds)
return _socket.recv(self, *args, **kwargs)
示例12: socket
lContact = [c1, c2]
ss = socket(AF_INET, SOCK_STREAM)
ss.bind(('192.168.28.83', 4269))
ss.listen(5)
print("Serveur lancé en écoute")
msg = "\n 1 = findNom \n 2 = findTel \n 3 = addByNomTel \n 4 = deleteByNom"
print(msg)
socket, info = ss.accept()
while (True):
commande = socket.recv(16)
commande = commande.decode()
print(commande)
socket.send((sys.argv[1] + "\rtoast\n").encode())
if commande == "1":
nom = socket.recv(512)
nom = nom.decode()
c = findContactByNom(lContact, nom)
socket.sendto(c)
if commande == "2":
nom = socket.recv(512)
nom = nom.decode()