Esempio n. 1
0
def ForwardCommandToServer(command, server_addr, server_port):
    
    client_socket = library.CreateClientSocket(server_addr, server_port)
    client_socket.send(command + '\n')
    server_response = library.ReadCommand(client_socket)
    client_socket.close()

    return server_response + '\n'
Esempio n. 2
0
def ForwardCommandToServer(command, server_addr, server_port):
  s = library.CreateClientSocket(server_addr,server_port)
  s.sendall(command)
  data = library.ReadCommand(s)
  data=data.strip('/n')
  s.close()
  return data
  """Opens a TCP socket to the server, sends a command, and returns response.
Esempio n. 3
0
def requestFromServer(serverAddr, serverPort, cmdLine, filename):
    clientSock = library.CreateClientSocket(serverAddr, serverPort)

    try:
        # Send the command line request to server and return the response.
        rttStart = time.time()
        clientSock.send(aes.encrypt(cmdLine.encode()))
        processResponse(serverAddr, clientSock, filename, rttStart)

    finally:
        clientSock.close()
Esempio n. 4
0
def ForwardCommandToServer(command, server_addr, server_port):
    """Opens a TCP socket to the server, sends a command, and returns response.
        
        Args:
        command: A single line string command with no newlines in it.
        server_addr: A string with the name of the server to forward requests to.
        server_port: An int from 0 to 2^16 with the port the server is listening on.
        Returns:
        A single line string response with no newlines.
        """
    sock = library.CreateClientSocket(server_addr, server_port)
    sock.send('%s\n' % command)
    result = library.ReadCommand(sock)
    sock.close()
    return result.strip('\n')
Esempio n. 5
0
def ForwardCommandToServer(command, server_addr, server_port):
    """Opens a TCP socket to the server, sends a command, and returns response.

    Args:
      command: A single line string command with no newlines in it.
      server_addr: A string with the name of the server to forward requests to.
      server_port: An int from 0 to 2^16 with the port the server is listening on.
    Returns:
      A single line string response with no newlines.
    """
    socket = library.CreateClientSocket(server_addr, server_port)
    socket.send(command)

    # Wait to receive the data from the server socket.
    return library.ReadCommand(socket)
Esempio n. 6
0
def ForwardCommandToServer(command, server_addr, server_port):
    """Opens a TCP socket to the server, sends a command, and returns response.

  Args:
    command: A single line string command with no newlines in it.
    server_addr: A string with the name of the server to forward requests to.
    server_port: An int from 0 to 2^16 with the port the server is listening on.
  Returns:
    A single line string response with no newlines.
  """
    client_sock = library.CreateClientSocket(server_addr, server_port)
    client_sock.sendall(command)
    data = client_sock.recv(library.COMMAND_BUFFER_SIZE)
    client_sock.close()
    data.replace("\n", "")
    return data
Esempio n. 7
0
def ForwardCommandToServer(command, server_addr, server_port):
    """Opens a TCP socket to the server, sends a command, and returns response.

    Args:
      command: A single line string command with no newlines in it.
      server_addr: A string with the name of the server to forward requests to.
      server_port: An int from 0 to 2^16 with the port the server is listening on.
    Returns:
      A single line string response with no newlines.
    """

    transfer_socket = library.CreateClientSocket(
        server_addr, server_port)  # connect to actual server
    transfer_socket.sendall(command.encode())  # transfer command to server
    result = library.ReadCommand(
        transfer_socket)  # obtain response from server
    transfer_socket.close()  # close server connection
    return result
def ForwardCommandToServer(command, server_addr, server_port):
    """Opens a TCP socket to the server, sends a command, and returns response.

    Args:
    command: A single line string command with no newlines in it.
    server_addr: A string with the name of the server to forward requests to.
    server_port: An int from 0 to 2^16 with the port the server is listening on.
    Returns:
    A single line string response with no newlines.
    """

    proxy_as_client = library.CreateClientSocket(server_addr, server_port)

    # proxy_as_client.sendto(command, (server_addr, server_port) )
    proxy_as_client.send(command)
    response_from_server = library.ReadCommand(proxy_as_client)
    # proxy_as_client.close()

    return response_from_server.strip()
Esempio n. 9
0
def ForwardCommandToServer(msg_to_server):
    """Opens a TCP socket to the server, sends a command, and returns response.

    Args:
      msg_to_server: Contains the cmdline, server_addr, and server_port
    Returns:
      A single line string response with no newlines.
    """
    command_line, server_addr, server_port = msg_to_server
    client_socket = library.CreateClientSocket(server_addr, server_port)
    
    res = None

    try:
        # Relay command_line to server and return the response.
        client_socket.sendall(command_line.encode())
        res = library.ReadCommand(client_socket).strip('\n')

    finally:
        client_socket.close()
    
    return res