def handle_client_send(sock, q, addr): while True: msg = q.get() if msg == None: break try: tincanchat.send_msg(sock, msg) except (ConnectionError, BrokenPipe): handle_disconnect(sock, addr) break
def button_check_send(self, msg, score, cost): if (score > cost): if (self.resource_check(cost, score)): message = msg tincanchat.send_msg(self.sock, message) else: return False else: self.update_server_textbox(msg)
def handle_client_send(sock, q, addr): """ Monitor queue for new messages, send them to client as they arrive """ while True: msg = q.get() # wait till receive something in queue if msg == None: break try: tincanchat.send_msg(sock, msg) except (ConnectionError, BrokenPipeError): handle_disconnect(sock, addr) break
def handle_client(sock, addr): """ Receive one message and echo it back to client, then close socket """ try: msg = tincanchat.recv_msg(sock) msg = '{}: {}'.format(addr, msg) print(msg) tincanchat.send_msg(sock, msg) except (ConnectionError, BrokenPipeError): print('socket error') """finally:
def handle_client(sock, addr): try: msg = tincanchat.recv_msg(sock) print('{}: {}'.format(addr, msg)) tincanchat.send_msg(sock, msg) except(ConnectionError, BrokenPipeError): print('Socket error') finally: print('Closed connection to {}'.format(addr)) sock.close()
def handle_client(sock, addr): """ Receive data from the client via sock and echo it back """ try: msg = tincanchat.recv_msg(sock) print('{}: {}'.format(addr, msg)) tincanchat.send_msg(sock, msg) except (ConnectionError, BrokenPipeError): print('Socket error') finally: print('Closed connection to {}'.format(addr)) sock.close()
def handle_client_send(self, sock, q, addr): """ Monitor queue for new messages, send them to client as they arrive """ while True: msg = q.get() if not msg: break try: tincanchat.send_msg(sock, msg) except (ConnectionError, BrokenPipeError): self.handle_disconnect(sock, addr) break
def handle_client(sock, addr): """ Receive data from client via sock and echo it back """ try: msg = tincanchat.recv_msg(sock) # blocks until recv complete msg print("{}: {}".format(addr, msg)) tincanchat.send_msg(sock, msg) # blocks until sent except (ConnectionError, BrokenPipeError): print("Socket error") finally: print("Closed connection to {}".format(addr)) sock.close()
def handle_client(sock, addr): """ Receive data from the client via sock and echo it back """ try: msg = tincanchat.recv_msg(sock) # Blocks until received # complete message print('{}: {}'.format(addr, msg)) tincanchat.send_msg(sock, msg) # Blocks until sent except (ConnectionError, BrokenPipeError): print('Socket error') finally: print('Closed connection to {}'.format(addr)) sock.close()
def handle_client(sock, addr): """ Receive one msg and echo it back to client, then close socket""" try: msg = tincanchat.recv_msg(sock) msg = '{}: {}'.format(addr, msg) print(msg) tincanchat.send_msg(sock, msg) except (ConnectionError, BrokenPipeError): print('Socket error') finally: print('Closed connection to {}'.format(addr)) sock.close()
def handle_client(sock, addr): """Receive data from the client via the sock and echo it back""" try: msg = tincanchat.recv_msg( sock) #Blocks until received complete messgae print("{}:{}".format(addr, msg)) tincanchat.send_msg(sock, msg) #Blocks until sent except (ConnectionError, BrokenPipeError): print("Socket Error") finally: print("Closed connection to {} ".format(addr)) sock.close()
def _SendMessage(self): #print('{}. Ha ha'.format(self.name.get())) self.scr.configure(state='normal') msg = self.name.get() self.scr.insert(tk.INSERT,msg + '\n') self.scr.configure(state='disabled') self.name.set('') try: tincanchat.send_msg(self.sock,msg) #Blocks until sent print('Send message ' + msg) except(BrokenPipeError,ConnectionError): print("Error")
def handle_input(self, sock): """ Prompt user for message and send it to server """ print("Type messages, enter to send. 'q' to quit") while True: msg = input() # blocks if msg == 'q': # sock.shutdown(socket.SHUT_RDWR) sock.close() break try: tincanchat.send_msg(sock, msg) # blocks until sent except (BrokenPipeError, ConnectionError): break
def handle_client(sock, addr): """Receive one message and echo it back to the client, close the socket next""" try: msg = tincanchat.recv_msg(sock) #Blocks until received complete msg msg = '{}: {}'.format(addr, msg) print(msg) tincanchat.send_msg(sock, msg) #Blocks until sent except (ConnectionError, BrokenPipeError): print("Socket Error") finally: print("Closed connection to {}".format(addr)) sock.close()
def handle_input(sock): print("Type messages, enter to send. 'q' to quit") while True: msg = input() # Blocks if msg == 'q': sock.shutdown(socket.SHUT_RDWR) sock.close() break try: tincanchat.send_msg(sock, msg) # Blocks until sent except (BrokenPipeError, ConnectionError): sys.stdout.flush() break
def handle_client(sock, addr): """ Receive one message and echo it back to client, then close socket """ try: msg = tincanchat.recv_msg(sock) # blocks until received # complete message msg = '{}: {}'.format(addr, msg) print(msg) tincanchat.send_msg(sock, msg) # blocks until sent except (ConnectionError, BrokenPipeError): print('Socket error') finally: print('Closed connection to {}'.format(addr)) sock.close()
def handle_input(sock): """ Prompt user for message and send it to server """ print("Type messages, enter to send. 'q' to quit") while True: msg = input() # Blocks if msg == 'q': sock.shutdown(socket.SHUT_RDWR) sock.close() break try: tincanchat.send_msg(sock, msg) # Blocks until sent except (BrokenPipeError, ConnectionError): sys.stdout.flush() break
def handle_client_send(sock, q, addr): """ Monitor queue for new messages, send them to client as they arrive """ while True: msg = q.get() if msg == None: break try: tincanchat.send_msg(sock, msg) except (ConnectionError, BrokenPipe): handle_disconnect(sock, addr) break
def handle_client(sock, addr): """ Receive data from the client via sock and echo it back """ try: msg = tincanchat.recv_msg(sock) # Blocks until received # complete message print('{}: {}'.format(addr, msg)) # adds exclamation points to confirm it went thru server msg = msg + "!!!" tincanchat.send_msg(sock, msg) # Blocks until sent except (ConnectionError, BrokenPipeError): print('Socket error') finally: print('Closed connection to {}'.format(addr)) sock.close()
import sys, socket import tincanchat HOST = sys.argv[-1] if len(sys.argv) > 1 else '127.0.0.1' PORT = tincanchat.PORT if __name__ == '__main__': while True: try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) print('\nConnected to {}:{}'.format(HOST, PORT)) print("Type message, enter to send. 'q' to quit") msg = input() if msg == 'q': break tincanchat.send_msg(sock, msg) # Blocks until sent print('Sent message: {}'.format(msg)) msg = tincanchat.recv_msg(sock) # Blocks until received # complete message print('Received echo: ' + msg) except ConnectionError: print('Socket error') break finally: sock.close() print('Closed connection to server\n')
#!/usr/bin/python import sys, socket import tincanchat host = sys.argv[-1] if len(sys.argv) > 1 else '127.0.0.1' port = tincanchat.port if __name__ == '__main__': while True: try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, port)) print('\nConnected to {}'.format(host, port)) msg = input() if msg == 'q': break tincanchat.send_msg(sock,msg) print('Sent message: {}'.format(msg)) msg = tincanchat.recv_msg(sock) print('Received echo: ' + msg) except ConnectionError: print('Socket Error') break finally: sock.close() print('Closed connection to server\n')
import sys, socket import tincanchat HOST = sys.argv[-1] if len(sys.argv) > 1 else '127.0.0.1' PORT = tincanchat.PORT if __name__ == '__main__': while True: try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) print('\nConnected to {}! {}'.format(HOST, PORT)) print("Type message, enter to send, 'q' to quit") msg = input() if msg == 'q': break tincanchat.send_msg(sock, msg) print('Sent message: {}'.format(msg)) msg = tincanchat.recv_msg(sock) print('Received echo: ' + msg) except ConnectionError: print('Socket error') break finally: sock.close() print('Closed connection to server\n')
''' cd Desktop\PythonPy\PythonTest Python echo_Client.py ''' import sys,socket import tincanchat HOST = sys.argv[-1] if len(sys.argv) > 1 else '127.0.0.1' PORT = tincanchat.PORT if __name__ == '__main__': while True: try: sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.connect((HOST,PORT)) print('\nConnected to {}:{}'.format(HOST,PORT)) print("Type message,enter to send, 'q' to quit") msg = input() if msg == 'q':break tincanchat.send_msg(sock,msg) #Block until sent print('Sent message: {}'.format(msg)) msg = tincanchat.recv_msg(sock) #Block until received complete message print('Received echo : '+msg) except: print('Socket error') break finally: sock.close() print('Closed connection to server\n')
def quit(self): msg = 'q' tincanchat.send_msg(self.sock, msg) self.root.destroy() #Closes the GUI self.sock.close() #Closes the socket, disconnects client