-
Notifications
You must be signed in to change notification settings - Fork 0
/
Connection.java
67 lines (58 loc) · 1.46 KB
/
Connection.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package distsys;
import javax.swing.event.ListSelectionEvent;
import java.rmi.ConnectException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
/**
* Created by thb on 04.02.14.
*/
public class Connection extends UnicastRemoteObject implements ConnectionInterface
{
private TicTacToe game;
private char mark;
public Connection(TicTacToe game) throws RemoteException
{
this.game = game;
}
@Override
public void connect(String url) throws RemoteException
{
System.out.println("Server started");
try {
LocateRegistry.createRegistry(1314);
}
catch (RemoteException e) {
System.err.println("Java RMI registry already exists");
}
try
{
Naming.rebind(url, this);
System.out.println("Connected");
}
catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void disconect() throws RemoteException
{
game.disconect();
}
public void doMove(int x, int y, int player)
{
game.setMark(x, y, player);
game.setMyTurn(true);
}
public void passServer(ConnectionInterface server)
{
game.setServer(server);
}
public void passPlayerID(int id)
{
game.setPlayerID(id);
game.setMyTurn(true);
}
}