2014-03-01 19:47:03 -05:00
|
|
|
package org.spacehq.packetlib.test;
|
2013-11-29 17:34:06 -05:00
|
|
|
|
2014-03-01 19:47:03 -05:00
|
|
|
import org.spacehq.packetlib.Client;
|
|
|
|
import org.spacehq.packetlib.Server;
|
|
|
|
import org.spacehq.packetlib.tcp.TcpSessionFactory;
|
2013-12-14 19:41:25 -05:00
|
|
|
|
|
|
|
import javax.crypto.KeyGenerator;
|
|
|
|
import javax.crypto.SecretKey;
|
2014-03-01 19:47:03 -05:00
|
|
|
import java.security.NoSuchAlgorithmException;
|
2013-11-29 17:34:06 -05:00
|
|
|
|
|
|
|
public class PingServerTest {
|
2015-07-20 14:02:42 -04:00
|
|
|
public static void main(String[] args) {
|
|
|
|
SecretKey key = null;
|
|
|
|
try {
|
|
|
|
KeyGenerator gen = KeyGenerator.getInstance("AES");
|
|
|
|
gen.init(128);
|
|
|
|
key = gen.generateKey();
|
|
|
|
} catch(NoSuchAlgorithmException e) {
|
|
|
|
System.err.println("AES algorithm not supported, exiting...");
|
|
|
|
return;
|
|
|
|
}
|
2013-11-29 17:34:06 -05:00
|
|
|
|
2015-07-20 14:02:42 -04:00
|
|
|
Server server = new Server("127.0.0.1", 25565, TestProtocol.class, new TcpSessionFactory()).bind();
|
|
|
|
server.addListener(new ServerListener(key));
|
2013-12-14 19:41:25 -05:00
|
|
|
|
2015-07-20 14:02:42 -04:00
|
|
|
Client client = new Client("127.0.0.1", 25565, new TestProtocol(key), new TcpSessionFactory());
|
|
|
|
client.getSession().connect();
|
2013-11-29 17:34:06 -05:00
|
|
|
|
2015-07-20 14:02:42 -04:00
|
|
|
while(server.isListening()) {
|
|
|
|
try {
|
|
|
|
Thread.sleep(500);
|
|
|
|
} catch(InterruptedException e) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-29 17:34:06 -05:00
|
|
|
}
|