/*
* Connect via TCP to game server
*/
NioSocketConnector connector = new NioSocketConnector();
connector.getFilterChain().addLast("codec",
new ProtocolCodecFilter(
new TextLineCodecFactory(Charset.forName("US-ASCII"))));
connector.setHandler(new TcpProtocolHandler(this));
ConnectFuture cf = connector.connect(new InetSocketAddress(HOST, 7002));
cf.addListener(new IoFutureListener() {
public void operationComplete(IoFuture s) {
try {
if(s.getSession() != null && s.getSession().isConnected()) {
m_packetGen.setTcpSession(s.getSession());
} else {
messageDialog("Connection timed out.\n"
+ "The server may be offline.\n"
+ "Contact an administrator for assistance.", getDisplay());
HOST = "";
m_packetGen = null;
}
}catch(RuntimeIoException e){
messageDialog("Connection timed out.\n"
+ "The server may be offline.\n"
+ "Contact an administrator for assistance.", getDisplay());
HOST = "";
m_packetGen = null;
}catch (Exception e) {
e.printStackTrace();
messageDialog("Connection timed out.\n"
+ "The server may be offline.\n"
+ "Contact an administrator for assistance.", getDisplay());
HOST = "";
m_packetGen = null;
}
}
});
/*
* Connect via UDP to game server
*/
NioDatagramConnector udp = new NioDatagramConnector();
udp.getFilterChain().addLast("codec",
new ProtocolCodecFilter(
new TextLineCodecFactory(Charset.forName("US-ASCII"))));
udp.setHandler(new UdpProtocolHandler(this));
cf = udp.connect(new InetSocketAddress(HOST, 7005));
cf.addListener(new IoFutureListener() {
public void operationComplete(IoFuture s) {
try {
if(s.getSession().isConnected()) {
m_packetGen.setUdpSession(s.getSession());
} else {
messageDialog("Connection timed out.\n"
+ "The server may be offline.\n"
+ "Contact an administrator for assistance.", getDisplay());
HOST = "";
m_packetGen = null;
}
}catch(RuntimeIoException e){
messageDialog("Connection timed out.\n"
+ "The server may be offline.\n"
+ "Contact an administrator for assistance.", getDisplay());
HOST = "";
m_packetGen = null;
} catch (Exception e) {
e.printStackTrace();
messageDialog("Connection timed out.\n"
+ "The server may be offline.\n"
+ "Contact an administrator for assistance.", getDisplay());
HOST = "";
m_packetGen = null;
}
}
});
/*
* Connect via TCP to chat server
*/
NioSocketConnector chat = new NioSocketConnector();
chat.getFilterChain().addLast("codec",
new ProtocolCodecFilter(
new TextLineCodecFactory(Charset.forName("US-ASCII"))));
chat.setHandler(new ChatProtocolHandler());
ConnectFuture cf2 = connector.connect(new InetSocketAddress(CHATHOST, 7001));
cf2.addListener(new IoFutureListener() {
public void operationComplete(IoFuture s) {