java.net.connectexception client socket failure

Im trying to create a server, and running the server and client classes on 2 different computers under the same wifi. however, i always run into this exception when attempting to create a client socket

Exception in thread "main" java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at Client.main(Client.java:34)

my server class:

public static void main (String[]args) throws IOException{

    Scanner in = new Scanner(System.in);

    String fromClient;
    String toClient;

    boolean made = false;

    ServerSocket serverSocket = null;

    while (!made){
        System.out.println("Please input the port number");
        int port = in.nextInt();
        try {
            serverSocket = new ServerSocket(port);
            made = true;
        } catch (IOException e){
            System.out.println("could not listen on port " + port);
        }
    }

    System.out.println("server socket established");

    //ServerSocket serverSocket = new ServerSocket(port, 8, InetAddress.getByName(ip));
    Socket client = serverSocket.accept();

    System.out.println("accepted");

    Scanner sc = new Scanner (client.getInputStream());
    PrintStream ps = new PrintStream(client.getOutputStream());

    ps.println("agiftfromserver");

    while (sc.hasNext()){
     fromClient = sc.next();

     System.out.println("from client " + fromClient);

     toClient = in.next();
     ps.println(toClient);

    }

    in.close();
    sc.close();
    serverSocket.close();
    serverSocket.close();
}

client:

public static void main (String[]args) throws UnknownHostException, IOException{


    Scanner in = new Scanner(System.in);

    String fromServer;
    String toServer;


    //System.out.println("Please input the ip address");
    //String ip = in.next();

    System.out.println("Please input the port number");
    int port = in.nextInt();

    Socket clientSocket = new Socket("localhost", port); //ERROR

    System.out.println("client established");

    //Socket cs = new Socket(ip, port);
    Scanner sc = new Scanner(clientSocket.getInputStream());
    PrintStream ps = new PrintStream(clientSocket.getOutputStream());

    while (sc.hasNext()){
        fromServer = sc.next();

        System.out.println("from server " + fromServer);

        toServer = in.next();
        ps.println(toServer);

    }

    in.close();
    clientSocket.close();
    sc.close();

} 

I have looked at other threads and i:
tried using different port numbers,
turned off firewalls,
and made sure i ran my server before client

it works when i run both classes on the same computer but gives me the error on 2 different devices.

does cross computer connection work like this?

if so, does anyone know how to fix this error. thank you