Lines Matching refs:self
55 def run_forever(self): argument
57 logger.info("Listening on port %d for clients.." % self.port)
58 self.serve_forever()
60 self.server_close()
66 def new_client(self, client, server): argument
69 def client_left(self, client, server): argument
72 def message_received(self, client, server, message): argument
75 def set_fn_new_client(self, fn): argument
76 self.new_client = fn
78 def set_fn_client_left(self, fn): argument
79 self.client_left = fn
81 def set_fn_message_received(self, fn): argument
82 self.message_received = fn
84 def send_message(self, client, msg): argument
85 self._unicast_(client, msg)
87 def send_message_to_all(self, msg): argument
88 self._multicast_(msg)
121 def __init__(self, port, host='127.0.0.1', loglevel=logging.WARNING): argument
123 TCPServer.__init__(self, (host, port), WebSocketHandler)
124 self.port = self.socket.getsockname()[1]
126 def _message_received_(self, handler, msg): argument
127 self.message_received(self.handler_to_client(handler), self, msg)
129 def _ping_received_(self, handler, msg): argument
132 def _pong_received_(self, handler, msg): argument
135 def _new_client_(self, handler): argument
136 self.id_counter += 1
138 'id': self.id_counter,
142 self.clients.append(client)
143 self.new_client(client, self)
145 def _client_left_(self, handler): argument
146 client = self.handler_to_client(handler)
147 self.client_left(client, self)
148 if client in self.clients:
149 self.clients.remove(client)
151 def _unicast_(self, to_client, msg): argument
154 def _multicast_(self, msg): argument
155 for client in self.clients:
156 self._unicast_(client, msg)
158 def handler_to_client(self, handler): argument
159 for client in self.clients:
166 def __init__(self, socket, addr, server): argument
167 self.server = server
168 StreamRequestHandler.__init__(self, socket, addr, server)
170 def setup(self): argument
171 StreamRequestHandler.setup(self)
172 self.keep_alive = True
173 self.handshake_done = False
174 self.valid_client = False
176 def handle(self): argument
177 while self.keep_alive:
178 if not self.handshake_done:
179 self.handshake()
180 elif self.valid_client:
181 self.read_next_message()
183 def read_bytes(self, num): argument
185 bytes = self.rfile.read(num)
191 def read_next_message(self): argument
193 b1, b2 = self.read_bytes(2)
197 self.keep_alive = 0
210 self.keep_alive = 0
214 self.keep_alive = 0
223 opcode_handler = self.server._message_received_
225 opcode_handler = self.server._ping_received_
227 opcode_handler = self.server._pong_received_
230 self.keep_alive = 0
234 payload_length = struct.unpack(">H", self.rfile.read(2))[0]
236 payload_length = struct.unpack(">Q", self.rfile.read(8))[0]
238 masks = self.read_bytes(4)
240 for message_byte in self.read_bytes(payload_length):
243 opcode_handler(self, message_bytes.decode('utf8'))
245 def send_message(self, message): argument
246 self.send_text(message)
248 def send_pong(self, message): argument
249 self.send_text(message, OPCODE_PONG)
251 def send_text(self, message, opcode=OPCODE_TEXT): argument
296 self.request.send(header + payload)
298 def read_http_headers(self): argument
301 http_get = self.rfile.readline().decode().strip()
305 header = self.rfile.readline().decode().strip()
312 def handshake(self): argument
313 headers = self.read_http_headers()
318 self.keep_alive = False
325 self.keep_alive = False
328 response = self.make_handshake_response(key)
329 self.handshake_done = self.request.send(response.encode())
330 self.valid_client = True
331 self.server._new_client_(self)
349 def finish(self): argument
350 self.server._client_left_(self)