I can't send data from the client to the server. I checked and found out that the server didn't catch the data sending event from the client, but they connected to each other. enter image description here
// server public void startServer() { Configuration config = new Configuration(); config.setPort(PORT_NUMBER); server = new SocketIOServer(config); server.addConnectListener(new ConnectListener() { @Override public void onConnect(SocketIOClient arg0) { textArea.append("One client connect \n"); } }); server.addEventListener("register", Server_Model_Register.class, new dataListener<Server_Model_Register>() { @Override public void onData(SocketIOClient arg0, Server_Model_Register arg1, AckRequest arg2) throws Exception { System.out.println( "data received"); } }); server.start(); textArea.append("Server has start on port : " + PORT_NUMBER + "\n" ); }
//client public void startServer() throws URISyntaxException { try { System.out.println("start"); client = IO.socket("http://" + IP + ":"+ PORT_NUMBER); client.connect(); client.on(Socket.EVENT_CONNECT, new Emitter.Listener() { @Override public void call(Object... args) { System.out.println("Connected to server successfully."); } }).on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() { @Override public void call(Object... args) { System.out.println("Connection to server failed."); for (Object arg : args) { System.out.println("Error message: " + arg); } } }); } catch (URISyntaxException e) { error(e); } }
this is action button register, then press data will process and emit to server. it was print Emited to server
@Override public void register(Client_Model_Register data) { Client_Service.getInstance().getClient().emit("register", data, new Ack() { @Override public void call(Object... arg0) { if (arg0.length > 0) { Object response = arg0[0]; if (response instanceof String) { String message = (String) response; System.out.println("Server response: " + message); } } else { System.out.println("No response from server."); } } }); System.out.println("Emited to server"); }