本文整理汇总了Python中socket.socket.close函数的典型用法代码示例。如果您正苦于以下问题:Python close函数的具体用法?Python close怎么用?Python close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: close
def close(self):
if self._makefile_refs < 1:
if self._sslobj:
self.unwrap()
socket.close(self)
else:
self._makefile_refs -= 1
示例2: close
def close(self):
if self._makefile_refs < 1:
self._sslobj = None
socket.close(self)
else:
self._makefile_refs -= 1
return
示例3: announce_bc
def announce_bc(socket, port, name, world):
'''This function acts to broadcast the server's
status of operation. Whether it's alive and
ready to accept new players, or dead.
'''
print 'Broadcasting thread started!'
dest = ('<broadcast>', port)
alive = True
while alive:
if world.keep_alive:
message = "\HELLO;"+name
socket.sendto(message, dest)
if not world.keep_alive:
message = "\DIE"
for _ in range(3):
socket.sendto(message, dest)
sleep(0.2)
alive = False
#Try to sleep up to 5 seconds before broadcasting again.
for _ in range(20):
if world.keep_alive:
sleep(0.25)
else:
break
print "Broadcasting thread closed!"
socket.close()
示例4: convProgress
def convProgress(socket):
socket.listen(0)
conn, addr = socket.accept()
while 1:
data = conn.recv(4096)
if not data: break
print data,
sys.stderr.write("Progress thread exiting!!")
socket.close()
示例5: apns_send_bulk_message
def apns_send_bulk_message(registration_ids, data, **kwargs):
"""
Sends an APNS notification to one or more registration_ids.
The registration_ids argument needs to be a list.
"""
socket = _apns_create_socket()
for registration_id in registration_ids:
_apns_send(registration_id, data, socket=socket, **kwargs)
socket.close()
示例6: 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
示例7: close
def close(self):
'''
Correctly close the socket and free all resources.
'''
global sockets
if self.pthread is not None:
self._stop = True
if self.epid is not None:
assert self.port is not None
if not self.fixed:
sockets.free(self.port)
self.epid = None
socket.close(self)
示例8: _apns_send
def _apns_send(token, alert, badge=0, sound="chime", content_available=False, action_loc_key=None, loc_key=None,
loc_args=[], extra={}, socket=None):
data = {}
if action_loc_key or loc_key or loc_args:
alert = {"body": alert}
if action_loc_key:
alert["action-loc-key"] = action_loc_key
if loc_key:
alert["loc-key"] = loc_key
if loc_args:
alert["loc-args"] = loc_args
data["alert"] = alert
if badge:
data["badge"] = badge
if sound:
data["sound"] = sound
if content_available:
data["content-available"] = 1
data.update(extra)
# convert to json, avoiding unnecessary whitespace with separators
payload = json.dumps({"aps": data}, separators=(",", ":"))
numBytes = len(payload)
if numBytes > APNS_MAX_NOTIFICATION_SIZE:
overflow = numBytes - APNS_MAX_NOTIFICATION_SIZE + 3
notificationText = data['alert']
shortenedText = notificationText[:overflow*-1]
shortenedText += "..."
data['alert'] = shortenedText
payload = json.dumps({"aps": data}, separators=(",", ":"))
if len(payload) > APNS_MAX_NOTIFICATION_SIZE:
raise APNSDataOverflow("Notification body cannot exceed %i bytes" % APNS_MAX_NOTIFICATION_SIZE)
data = _apns_pack_message(token, payload)
if socket:
socket.write(data)
#data = socket.recv(4096)
#print "received message:", data
else:
socket = _apns_create_socket()
socket.write(data)
socket.close()
示例9: apns_send_bulk_message
def apns_send_bulk_message(registration_ids, alert, **kwargs):
"""
Sends an APNS notification to one or more registration_ids.
The registration_ids argument needs to be a list.
Note that if set alert should always be a string. If it is not set,
it won't be included in the notification. You will need to pass None
to this for silent notifications.
"""
socket = _apns_create_socket()
for registration_id in registration_ids:
_apns_send(registration_id, alert, socket=socket, **kwargs)
socket.close()
示例10: _apns_send
def _apns_send(
token,
alert,
badge=0,
sound="chime",
content_available=False,
action_loc_key=None,
loc_key=None,
loc_args=[],
extra={},
socket=None,
):
data = {}
if action_loc_key or loc_key or loc_args:
alert = {"body": alert}
if action_loc_key:
alert["action-loc-key"] = action_loc_key
if loc_key:
alert["loc-key"] = loc_key
if loc_args:
alert["loc-args"] = loc_args
data["alert"] = alert
if badge:
data["badge"] = badge
if sound:
data["sound"] = sound
if content_available:
data["content-available"] = 1
data.update(extra)
# convert to json, avoiding unnecessary whitespace with separators
data = json.dumps({"aps": data}, separators=(",", ":"))
if len(data) > APNS_MAX_NOTIFICATION_SIZE:
raise APNSDataOverflow("Notification body cannot exceed %i bytes" % (APNS_MAX_NOTIFICATION_SIZE))
data = _apns_pack_message(token, data)
if socket:
socket.write(data)
else:
socket = _apns_create_socket()
socket.write(data)
socket.close()
示例11: _apns_send
def _apns_send(token, data, badge=0, sound="chime", content_available=False, custom_params={}, action_loc_key=None,
loc_key=None, loc_args=[], socket=None):
# data = {}
#alert = {}
# if action_loc_key or loc_key or loc_args:
# alert = {} #{"body": alert}
# if action_loc_key:
# alert["action-loc-key"] = action_loc_key
# if loc_key:
# alert["loc-key"] = loc_key
# if loc_args:
# alert["loc-args"] = loc_args
#data["alert"] = alert
# if badge:
# data["badge"] = badge
#
# if sound:
# data["sound"] = sound
#
# if content_available:
# data["content-available"] = 1
# convert to json, avoiding unnecessary whitespace with sepatators
#data = json.dumps({"aps": data, "content": content}, separators=(",",":"))
#data = json.dumps(data, separators=(",",":"))
if len(data) > APNS_MAX_NOTIFICATION_SIZE:
raise APNSDataOverflow("Notification body cannot exceed %i bytes" % (APNS_MAX_NOTIFICATION_SIZE))
data = _apns_pack_message(token, data)
if socket:
socket.write(data)
else:
socket = _apns_create_socket()
socket.write(data)
socket.close()
示例12: res_fun
BACKLOG = 10
addr_info = ('127.0.0.1', 4000)
def res_fun(sockfd_n):
x = sockfd_n.recvfrom(100)
print x[0]
x = x[0][:100].split()
if (x[0] == 'GET'):
if (x[1] == '/apple.html'):
fileo = os.getcwd() + x[1]
fd = os.open(fileo, os.O_RDONLY)
string = os.read(fd)
while string:
os.write(sockfd_n, string)
string = os.read(fd)
sockfd = socket()
sockfd.bind(addr_info)
sockfd.listen(BACKLOG)
while True:
(sockfd_new, from_port) = sockfd.accept()
if(os.fork())== 0:
socket.close(sockfd)
res_fun(sockfd_new)
socket.close(sockfd_new)
exit(0)
socket.close(sockfd_new)
示例13: socket
from socket import socket
import os
sockfd = socket()
sockfd.bind(('127.0.0.1',8031))
sockfd.listen(10)
while True:
(new_fd,from_port) = sockfd.accept()
print "incoming connection"
if os.fork() == 0:
socket.close(sockfd)
numbytes = new_fd.recv(300)
print numbytes
numbytes = numbytes[:100].split()
print numbytes
if numbytes[1] == "/":
req_file = "/index.html"
else:
req_file = numbytes[1]
fd = open(os.getcwd()+req_file)
data = fd .read()
s = "HTTP/1.1 200 OK\nContent-length: %d\nContent-Type: %s\n\n%s" % (len(data),"text/html",data)
new_fd.send(s)
new_fd.close()
exit(0)
socket.close(new_fd)
示例14: shutdown
def shutdown(self, completely=False):
self.connect = False
socket.close(self.socket)
if not completely:
self.ui.menu_file.entryconfigure(1, label="Reconnect", command=self.startup)
self.ui.parse_output('Connection closed.')
示例15: close
def close(self):
socket.close(self)
self.send_x = not_implemented
self.recv_headers = not_implemented
self.recv_content = not_implemented
self.recv_chunked_content = not_implemented