Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Client uygulaması main metod
package simplechat;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Set;
import simplechat.common.ChatClient;
import simplechat.common.ChatServer;
import simplechat.common.Client;
/**
*
* @author Kadir Korkmaz
*/
public class ClientApp {
private static ChatServer chatServer;
private static Client client;
private static ChatClient clientStub;
public static void main(String[] args) throws RemoteException, NotBoundException, IOException {
String username = "Kadir";
String serverAddress = "localhost";
Registry registry = LocateRegistry.getRegistry(serverAddress, 2020);
if (registry == null) {
System.err.println("Error : Registry is null :(. Did you run a server");
return;
}
client = new Client(username);
clientStub = (ChatClient) UnicastRemoteObject.exportObject(client, 0);
chatServer = (ChatServer) registry.lookup("ChatServerObject");
String[] currentUsers = chatServer.registerClient(clientStub);
client.addCurrentUsers(currentUsers);
System.out.println("Connected to server...");
handleUserRequests();
}
......
.....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment