本文整理汇总了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)
开发者ID:zjg95,项目名称:cs356-routing-table,代码行数:7,代码来源:server-zjg95.py
示例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)
开发者ID:nathanjhaveri,项目名称:django-push-notify,代码行数:29,代码来源:models.py
示例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')
开发者ID:SeanCCarter,项目名称:ohell,代码行数:32,代码来源:server.py
示例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')
开发者ID:SeanCCarter,项目名称:ohell,代码行数:10,代码来源:server.py
示例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
开发者ID:oksome,项目名称:Intercom,代码行数:11,代码来源:minion.py
示例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)
开发者ID:Logotrop,项目名称:trida,代码行数:10,代码来源:ssl.py
示例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)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:17,代码来源:ssl.py
示例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)
开发者ID:cmhill,项目名称:qiime,代码行数:19,代码来源:cluster_utils.py
示例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)
开发者ID:lupescu,项目名称:subtxt_pkg,代码行数:20,代码来源:ssl.py
示例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)
开发者ID:ToM-Korn,项目名称:sublime-text-2-plugin,代码行数:31,代码来源:ssl.py
示例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)
开发者ID:lsowen,项目名称:pySchannelSSL,代码行数:5,代码来源:sslsocket.py
示例12: close_socket_connection
def close_socket_connection(socket):
socket.send(mlprotocol.end_message())
socket.close()
开发者ID:quantnode,项目名称:quantnode-client,代码行数:3,代码来源:actors.py
注:本文中的socket.socket.send函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论