Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ServerStarter {
- Server server;
- public ServerStarter() {
- server = new Server();
- server.getKryo().register(String.class);
- server.addListener(new Listener() {
- public void received(Connection con, Object obj) {
- System.out.println("Got something");
- if (obj instanceof String) {
- System.out.println(obj);
- }
- }
- public void connected (Connection c) {
- System.out.println("Connection acquired");
- }
- public void disconnected(Connection c) {
- System.out.println("There was a disconnection");
- }
- });
- try {
- server.bind(6969,6969);
- } catch (IOException e) {
- e.printStackTrace();
- }
- server.start();
- System.out.println("Server started");
- }
- public static void main(String[] args) {
- new ServerStarter();
- }
- public class ClientStarter {
- Client client;
- public ClientStarter() throws IOException, InterruptedException {
- client=new Client(6969,6969);
- client.getKryo().register(String.class);
- client.start();
- client.addListener(new Listener() {
- public void received(Connection con,Object obj) {
- if(obj instanceof String) {
- System.out.println(obj);
- }
- }
- });
- client.connect(2000, "localhost", 6969);
- //For testing purposes
- Thread.sleep(2000);
- }
- public static void main(String[] args) {
- try {
- new ClientStarter();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment