Reputation: 55
I need to run a Server and Client in a application that trade string messages with each other(a chat), the code for this is working, part of it was provided by the teacher, but i'm stuck in one thing.
I want to run a class named "App", who creates a new Server and a new Client, but when i run both of then in the class, only one works.
package app;
import udp.Client;
import udp.Server;
public class App {
public static void main(String[] args) {
Server s = new Server();
s.Start();
Client c = new Client();
c.Start();
}
}
So to run the both of then, Server and Client, i need to comment out the client one, run the Server instance, then comment out the Server one, and run the Client instance, both classes initialize a thread.
How can i run both of then without that improvisation? I wanna hit "Run", and the code pops up the Server and the Client window.
I can provide the rest of the code if it's necessary.
Upvotes: 2
Views: 44
Reputation: 2821
new Thread(() ->
{
Server s = new Server();
s.Start();
}).start();
new Thread(() ->
{
Client c = new Client();
c.Start();
}).start();
Upvotes: 1