0

I know the client and server are connecting because my connect/disconnect events are firing. However, my custom events are not. I am using socket.io java client, and netty-socketio on the server. I usually use the socket.io javascript library which works seamlessly, so I am a bit lost as to why this is happening. I am writing this in Kotlin.

Client-Side

fun connectToServer(ipAddress : String)
    {
        socket = IO.socket("$ipAddress")

        socket!!.on(Socket.EVENT_CONNECT) {  obj ->


            println("Connected To Server!!!")

        }.on(EventNames.signOn) { obj ->

            println(EventNames.signOn)
            //cast value to string from server, hope for encrypted password
            val encryptedPassword = obj[0] as String


            when(encryptedPassword)
            {
                "no user" -> {

                }

                else -> {

                    val result = encryptedPassword!!.split("OR")
                    val isMatch = passwordTextField.text == dataProcessing.Encryption3().decryptValue("decrypt", result[0],result[1])

                    if(isMatch)
                    {

                    }
                }
            }

            println("Encrypted Password: "+encryptedPassword)
        }

//        socket!!.on(Socket.EVENT_DISCONNECT, object : Emitter.Listener {
//
//            override fun call(vararg args: Any) {}
//
//        })


        socket!!.connect()
//        socket!!.open()

//        socket!!.emit(Socket.EVENT_CONNECT, "Hello!")


        socket!!.send("hey")
       socket!!.emit(EventNames.requestClientSignOn, usernameTextField.text)

    }

Server-Side

@Throws(InterruptedException::class, UnsupportedEncodingException::class)

    fun server()
    {
        val config = Configuration()
        config.setHostname("localhost")
        config.setPort(PORT)
        server = SocketIOServer(config)

        server!!.addConnectListener {
            println("Hello World!")
        }


            server!!.addEventListener(EventNames.requestClientSignOn, String::class.java) { client, data, ackRequest ->

               println("Hello from  requestClientSignOn..")

        }
        server!!.addDisconnectListener {

                    println("Client Disconnecting...")

        }

        server!!.addConnectListener {

            println("client connected!! client: $it")
        }

        server!!.start()
wizeOnes
  • 119
  • 16

1 Answers1

0

You cannot use lambda expression in your event listeners, using netty-socketio on the sever.

Using the traditional EventListener solves this problem. I also converted the server to Kotlin, as it was easier to use the demo project as a reference.

server.addEventListener(EventNames.requestClientSignOn, String.class, new DataListener<String>() {


            @Override
            public void onData(SocketIOClient client, String username, AckRequest ackRequest) {


                String isEncryptedPassword = new KOTS_EmployeeManager().getKOTS_User(KOTS_EmployeeManager.kotsUserType.CLIENT, username)

                if(isEncryptedPassword != null)
                {
                    //send back ack with encrypted password
                    ackRequest.sendAckData(isEncryptedPassword);

                }else{
                    //send back ack with no user string
                    ackRequest.sendAckData("no user");
                }
            }

        });
wizeOnes
  • 119
  • 16