本文整理汇总了Python中socket.socket.send函数的典型用法代码示例。如果您正苦于以下问题:Python send函数的具体用法?Python send怎么用?Python send使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了send函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: returnResponse
def returnResponse (response, socket) :
"""
send bytes over a socket
response the bytes to send
socket the client socket to use
"""
socket.send(response)
示例2: send_push
def send_push(self, message, badge, data, socket):
payload = {}
aps = {}
aps["alert"] = message
aps["badge"] = badge
payload["aps"] = aps
if type(data) is dict:
payload.update(data)
else:
payload["data"] = data
token = binascii.unhexlify(self.devicetoken)
payloadstr = json.dumps(payload, separators=(',',':'))
payloadLen = len(payloadstr)
# struct.pack format string breakdown:
# ! - big-endian byte order for network transmission
# c - char for command
# H - 2 byte device token length (value should be 32)
# 32s - 32 byte device token string
# H - Lenth of payload
# %ds - payload with length payloadLen
fmt = "!cH32sH%ds" % payloadLen
command = '\x00' # 0 for simple format, 1 for extended
msg = struct.pack(fmt, command, 32, token, payloadLen, payloadstr)
if len(msg) > 256:
raise Exception('Message payload is too large')
socket.send(msg)
示例3: processClientMessage
def processClientMessage(self, socket, tokens):
if tokens[0] == 'LOGOUT':
self.logoutPlayer(socket)
elif self.state == 'REGISTRATION' or self.state == 'RESTART':
print "Registration state."
if tokens[0] == 'LOGIN':
print 'Login: ', tokens[1]
self.loginPlayer(socket, tokens[1])
if self.numReadyPlayers == self.numPlayers:
print "Players Ready."
# if new game
if self.state == 'REGISTRATION':
self.playGame(0, -1)
else: # restarting interrupted game
scores = self.gameState.currentScores()
for i in range(self.numPlayers):
self.players[i].score = scores[i]
self.playGame( self.gameState.numHands(),
self.gameState.nextDealer())
raise 'End server'
else:
print 'Error'
socket.send('ERROR Unknown\n')
示例4: logoutPlayer
def logoutPlayer( self, socket ):
player = findPlayer(socket)
if player is not None:
i = self.players.index(player)
del self.players[i]
player.sendMessage('OK')
else:
socket.send('ERROR\n')
示例5: 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
示例6: send
def send(self, data, flags=0):
self._checkClosed()
if self._sslobj:
if flags != 0:
raise ValueError(
"non-zero flags not allowed in calls to send() on %s" %
self.__class__)
return self._sslobj.write(data)
else:
return socket.send(self, data, flags)
示例7: send
def send(self, data, flags=0):
self._checkClosed()
if self._sslobj:
if flags != 0:
raise ValueError('non-zero flags not allowed in calls to send() on %s' % self.__class__)
try:
v = self._sslobj.write(data)
except SSLError as x:
if x.args[0] == SSL_ERROR_WANT_READ:
return 0
if x.args[0] == SSL_ERROR_WANT_WRITE:
return 0
raise
return v
continue
else:
return socket.send(self, data, flags)
示例8: save_send
def save_send(socket, data):
"""send data to a socket.
socket: a connected socket object
data: string to send over the socket
"""
#We have no control about how much data the clients accepts,
#thus we send in chunks until done
while len(data)>0:
try:
send_data_size = socket.send(data)
#remove sent portion form data
data = data[send_data_size:]
except error, msg:
#most likely socket busy, buffer full or not yet ready
sleep(0.01)
示例9: send
def send(self, data, flags=0):
if self._sslobj:
if flags != 0:
raise ValueError(
"non-zero flags not allowed in calls to send() on %s" %
self.__class__)
while True:
try:
v = self._sslobj.write(data)
except (SSLError) as x:
if x.args[0] == SSL_ERROR_WANT_READ:
return 0
elif x.args[0] == SSL_ERROR_WANT_WRITE:
return 0
else:
raise
else:
return v
else:
return socket.send(self, data, flags)
示例10: send
"non-zero flags not allowed in calls to send() on %s" %
self.__class__)
while True:
try:
v = self._sslobj.write(data)
except SSLError, x:
if x.args[0] == SSL_ERROR_WANT_READ:
return 0
elif x.args[0] == SSL_ERROR_WANT_WRITE:
return 0
else:
raise
else:
return v
else:
return socket.send(self, data, flags)
def sendto(self, data, addr, flags=0):
if self._sslobj:
raise ValueError("sendto not allowed on instances of %s" %
self.__class__)
else:
return socket.sendto(self, data, addr, flags)
def sendall(self, data, flags=0):
if self._sslobj:
if flags != 0:
raise ValueError(
"non-zero flags not allowed in calls to sendall() on %s" %
self.__class__)
amount = len(data)
示例11: send
def send(self, data, flags=0, raw=False):
if not raw:
return self._sslobj.send(data, flags)
else:
return socket.send(self, data, flags)
示例12: close_socket_connection
def close_socket_connection(socket):
socket.send(mlprotocol.end_message())
socket.close()