示例#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'
示例#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.
示例#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()
示例#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')
示例#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)
示例#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
示例#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()
示例#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