-
Notifications
You must be signed in to change notification settings - Fork 3
/
BrokerServer.java
64 lines (58 loc) · 1.97 KB
/
BrokerServer.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package wtserver;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import wtserver.client.ClientMsg;
import wtserver.server.broker.*;
/**
*
* @author MSI
*/
public class BrokerServer extends Server {
public BrokerServer(int port)
{
super(port);
}
@Override
public void startServer() {
try {
ServerSocket socket = new ServerSocket(port);
System.out.println("Broker Server Started on port " + port);
while (true) {
Socket connectionSocket = socket.accept();
addClient(new Client(this, connectionSocket));
}
} catch (IOException ex) {
System.out.println(ex);
}
}
@Override
public void processMsg(Client client, int msgId, byte buffer [])
{
if(msgId == ClientMsg.CS_BR_CHAINLIST_REQ)
{
ChainListAck chainListAck = new ChainListAck();
client.write(chainListAck.getData(client.getSeqNum()), chainListAck.getSize());
}else if(msgId == ClientMsg.CS_BR_WORLDLIST_REQ)
{
WorldListAck worldListAck = new WorldListAck();
client.write(worldListAck.getData(client.getSeqNum()), worldListAck.getSize());
}else if(msgId == ClientMsg.CS_BR_WORLDINFO_REQ)
{
WorldInfoAck worldInfoAck = new WorldInfoAck();
client.write(worldInfoAck.getData(client.getSeqNum()), worldInfoAck.getSize());
}else if(msgId == ClientMsg.CS_BR_RELAYLIST_REQ)
{
RelayListAck relayListAck = new RelayListAck();
client.write(relayListAck.getData(client.getSeqNum()), relayListAck.getSize());
}
}
}