def __init__(self,hostname,port): super(netray, self).__init__() parser=argparse.ArgumentParser() parser.description="Netray Hostname[None] port [-Options] ..." parser.add_argument('-r',action="store_true",help='Netray reverse connection') parser.add_argument('-s',action="store_true",help='Server,Passive control') parser.add_argument('-c',action="store_true",help='Client,Control') args=parser.parse_args() if not args.s and not args.c: print("Netray: Please select Control[-c] or Passive control[-s] ") sys.exit() if args.s and args.c: print("Netray: [-s] and [-c] cannot exist at the same time") sys.exit() if len(hostname)>1 and args.s and not args.r: print("Netray: No need to enter the host name ") elif len(hostname)>1 and args.c and args.r: print("Netray: No need to enter the host name ") if args.s: if args.r:service(hostname,port,True).conn() else:service(hostname,port,False).conn() elif args.c: if args.r: client(hostname,port,True).conn() else: client(hostname,port,False).conn()
def __init__(self): """Set up thread to accept connections""" l.basicConfig(filename='Server.log', level=l.DEBUG) self.threads = [] #active_chatrooms structure: ([Chatroom name: Chatroom Object]) self.active_chatrooms = dict() self.current_room_reference = 0 self.current_join_id = 0 #self.chatroom_lock = threading.Lock() self.server_port = cf.SERVER_PORT self.server_socket = socket(AF_INET, SOCK_STREAM) self.server_socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) self.server_socket.bind(('', self.server_port)) self.server_socket.listen(5) self.mutex = threading.Lock() print('The server is ready to receive') #Setup thread looking for command to quit program command_control_thread = threading.Thread( target=self.manage_command_line_input) self.threads.append(command_control_thread) command_control_thread.start() while 1: #Accept connections from clients and start a new thread handling each new connection connection_socket, addr = self.server_socket.accept() new_client = client(connection_socket, addr, self.current_join_id) self.current_join_id += 1 new_connection_thread = threading.Thread( target=self.manage_connection_thread, args=(new_client, )) self.threads.append(new_connection_thread) new_connection_thread.start() connection_socket.close()
def __init__(self,ip,port): self.__cl = client(ip, port) self.__GUI_WINDOW = Tk() self.__name_label = Label(self.__GUI_WINDOW, text="Your name: ").grid(row=0, column=0, sticky='w') self.__name_entry = Entry(self.__GUI_WINDOW, bd=3) self.__text_box = Text(self.__GUI_WINDOW) self.__message_box = Text(self.__GUI_WINDOW, borderwidth=5) self. __send_button = Button(self.__GUI_WINDOW, text='SEND', height=2, width=15, bg='blue') self.__join_button = Button(self.__GUI_WINDOW, text='JOIN', height=2, width=15, bg='red') self.__create_room_button = Button(self.__GUI_WINDOW, text='CREATE ROOM', height=2, width=15, bg='red') self.__rooms = Listbox(self.__GUI_WINDOW, height=1, width=19, selectmode=SINGLE) self.__Is_Entered = False
def init_chat(self): self.s = client(self)
parser.add_argument('-g', '--gen-config', const=print_conf, action='store_const', dest='gen', help='Generate default config') args = parser.parse_args() # global isDebug # isDebug = args.isDebug if args.gen: print_conf() exit(0) # not good if args.config: global config with open(args.config) as json_file: config = json.load(json_file) pass if __name__ == '__main__': parse_args() mqtt = client(config) mqtt.start() while True: pass
def __init__(self): self._client = client()
num_of_nodes = 19 def get_open_port(): import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("", 0)) s.listen(1) port = s.getsockname()[1] s.close() return port for i in range(num_of_nodes): client_obj = client("action" + str(i), "data" + str(i), "false", "false") client_obj.client_num = str(i + 1) client_obj.init_client() clients_list.append(client_obj) time.sleep(1) client_obj = client("actionPipe", "dataPipe", "false", "true") client_obj.client_num = "yogevi" client_obj.init_client() clients_list.append(client_obj) client.temp = 0 for i in range(1): sender = clients_list[0] target = clients_list[1]
# Client program from Client import client my_client = client() my_client.client_begin()