コード例 #1
0
    def connect_socket(self, s: socket, host_ip: str, port: int,
                       destination: int):
        '''
		Method takes a socket and connection parameters and connects to that 
		destination. 

		@Param:
			s:: socket to be used to establish connection
			host_ip::   destination IP
			port::      destination Port
			destination::   node ID of destination. 
		'''
        counter = 0
        while True:
            try:  # attempt to connect socket to other node
                s.connect((host_ip, port))
                #print("out socket from self ", self.nodeID, " to ", destination, " at ", self.out_sockets[destination])
                print("Out socket connected to :", destination)
                break
            except socket.error:
                # while the connection fails, wait, and retry
                if counter == 12:
                    print("Connecting to node ", destination, " at ", host_ip,
                          port, ' ......')
                    counter = 0
                # debug print statemet to see how in socket thread count changes
                #for sthread in self.in_socket_threads:
                #	print(type(sthread))
                counter += 1
                sleep(.25)
                continue
コード例 #2
0
def make_connection(mysocket: socket) -> None:
    '''
	This is an information of connection. 
	After made, socket connect to the address.
	'''
    connect_address = ('circinus-32.ics.uci.edu', 4444)
    mysocket.connect(connect_address)
コード例 #3
0
def message_handle_thread(sock: socket, app: Application):
    sock.connect((host, PORT))

    get_color(sock)
    proceed_server_message(sock, app)
    get_game_state(sock)

    while True:
        proceed_server_message(sock, app)
コード例 #4
0
ファイル: socket.py プロジェクト: TheQue42/qsip
def connect_socket(my_socket : socket, dst_addr : str, dst_port : int):
    """This is needed to get the local IP and Port"""

    #print(f"Will (attempt to) connect with: socket({my_socket.fileno()}), towards {dst_addr}, {dst_port}")
    try:
        my_socket.connect((dst_addr, dst_port))
    except socket.error as err:
        print("Socket connect failed: ", my_socket, " ", err)
        return "", 0

    (localAddr, localPort) = my_socket.getsockname()
    return (localAddr, localPort)
コード例 #5
0
def do_server_socket_logic(server_socket: socket, required_host: str,
                           required_port: int, request_byte_arr,
                           client_socket: socket):
    print(f"required_host: {required_host}")
    print(f"required_port: {required_port}")
    server_socket.connect((required_host, int(required_port)))
    server_socket.send(request_byte_arr)
    response = bytearray()
    while True:
        http_response = server_socket.recv(4096)
        response += http_response
        if (len(http_response) == 0):
            break

    server_socket.close()

    return response
def connect_to(sock: socket, port: int, host: str) -> None:
    ''' Establishes a connection to a server, given hostname, port #, and a
        socket '''
    sock.connect((host,port))
    print("Got connection from (",host, ",", port,")")
コード例 #7
0
def connect(s: socket) -> None:
    '''Reconects to server'''

    s = socket(AF_INET, SOCK_STREAM)
    s.connect((config['HOST'], config['PORT']))