0

I'm new the world of TCP / IP, Networking, Sockets etc.. during my internship I should replace the Nanomsg Library with java-only code. My supervisor has also sent me the following protocol and wants me to write a implement it: https://github.com/nanomsg/nanomsg/blob/master/rfc/sp-tcp-mapping-01.txt .

So here are some questions that still arise in my mind:

  • The written code should be executed once the connection has been established. do you have any suggestions how I can do this ? I have tried it but I am not sure if that will work, here is what I have done:

`public void connectionInitiation(AsynchronousSocketChannel connectReq, AsynchronousSocketChannel connectionPair) {

    if(connectReq)

    Future<Integer> writeBytes = connectReq.write(header);
    writeBytes.get();

    ByteBuffer receivedbytes = ByteBuffer.allocate(4);
    Future<Integer> readBytes = connectionPair.read(receivedbytes);

    header.flip();
    receivedbytes.flip();

    if (!header.equals(receivedbytes)) {
        connectReq.close();
    } else if (receivedbytes.get(6) != 0x00 || receivedbytes.get(7) != 0x00) {
        connectReq.close();
    } else {
        System.out.println("Protocol Header is successfully verified.");
    }

}`

this method comes right after the connection has been established.

  • He asked me to do this in a separated class, how can I do this ? ( sorry if the question is quiet dumb )

I apologize if the questions are not clear enough or if the answer is tooo obvious.... I still in the learning phase and want to make sure I grasped this in the right way.

Ilyass
  • 1
  • 1
  • not sure what more advice there is than either telling you to learn NIO and just do it, or writing your code for you – user253751 Feb 09 '23 at 09:34

0 Answers0