Guest User

Untitled

a guest
Jan 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. public class ServerStarter {
  2. Server server;
  3.  
  4. public ServerStarter() {
  5. server = new Server();
  6. server.getKryo().register(String.class);
  7.  
  8. server.addListener(new Listener() {
  9. public void received(Connection con, Object obj) {
  10.  
  11. System.out.println("Got something");
  12. if (obj instanceof String) {
  13. System.out.println(obj);
  14. }
  15. }
  16. public void connected (Connection c) {
  17. System.out.println("Connection acquired");
  18. }
  19. public void disconnected(Connection c) {
  20. System.out.println("There was a disconnection");
  21. }
  22. });
  23.  
  24. try {
  25. server.bind(6969,6969);
  26. } catch (IOException e) {
  27. e.printStackTrace();
  28. }
  29.  
  30. server.start();
  31. System.out.println("Server started");
  32. }
  33.  
  34. public static void main(String[] args) {
  35.  
  36. new ServerStarter();
  37.  
  38. }
  39.  
  40. public class ClientStarter {
  41. Client client;
  42. public ClientStarter() throws IOException, InterruptedException {
  43. client=new Client(6969,6969);
  44. client.getKryo().register(String.class);
  45. client.start();
  46. client.addListener(new Listener() {
  47. public void received(Connection con,Object obj) {
  48. if(obj instanceof String) {
  49. System.out.println(obj);
  50. }
  51. }
  52. });
  53. client.connect(2000, "localhost", 6969);
  54.  
  55. //For testing purposes
  56. Thread.sleep(2000);
  57. }
  58.  
  59. public static void main(String[] args) {
  60. try {
  61. new ClientStarter();
  62. } catch (IOException e) {
  63. e.printStackTrace();
  64. } catch (InterruptedException e) {
  65. e.printStackTrace();
  66. }
  67. }
Add Comment
Please, Sign In to add comment