I wrote little game like chess on Netbeans/Java with Server-Client structure. Two players are playing with each other if they are at same wifi or same lan. Now I want to make it " play with different networks ". How can I do that ? I have 2 idea but I need advice. Firstly I will write my Client-Server connection code.
Client.Start("127.0.0.1", 2000);
public static void Start(String ip, int port) {
try {
// Client Socket object
Client.socket = new Socket(ip, port);
Client.Display("Connected to server");
// input stream
Client.sInput = new ObjectInputStream(Client.socket.getInputStream());
// output stream
Client.sOutput = new ObjectOutputStream(Client.socket.getOutputStream());
Client.listenMe = new Listen();
Client.listenMe.start();
Message msg = new Message(Message.Message_Type.Name);
msg.content = Game.ThisGame.txt_name.getText();
Client.Send(msg);
} catch (IOException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
}
}
Main Purpose : Players on different network can play this.
my First idea is - rent a Server . and Use that server like my clients's server. But Idk , Servers can run Java code ?
Second idea is implementing my netbeans code for connect to online database and coding my moves , when client took enemy's moves on database , program will encode it and shows moves on my board. Thanks for advices,ideas
Aucun commentaire:
Enregistrer un commentaire