Which means the connect () call is not blocked on the TCP stack (java)

I have a question about calling connect () on a TCP socket implementation. Which means that the call to connect () is not blocked. The connect () call performs a three-way handshake with another socket, sending syn, waiting for SYNACK, and then sending an ACK. The connect () call also returns true if the connection was successful or false if it failed.

If the call does not block, I assume that this means that the connection should return immediately, even if it is still waiting for SYNACK, but in this case it will never be able to return false when it cannot connect, because by that time it has already returned .

So my questions are: - What does it mean that the connect () call is not blocked. - How is the call connect () achieved? Is this only possible with threads? - Im mimicking the tcp stack in java, could you please simplify an example of what a non-blocking version would look like? I included a sketch of what apparently looks something like this: (more complex psuedo code than actual java):

public boolean connect(IpAddress dst, int port){
    // create a syn packet and send it
    ipLayer.send(.....,<synpacket>);
    try{
        // wait for a synack and store it in receive_packet
        ipLayer.receive(...., receivePacket,<timeout>);
    } catch( TimeoutException e ){
        // timed out.
        return false;
    }
    // use information from a receivePacket to create an ack-packet then send it.
    ipLayer.send(<ackpacket>);
    return true;
}
+4
source share
2 answers

So my questions are: - What does it mean that the connect () call is not blocked.

Exactly what you said. It does not wait for network traffic.

How is connect () called? Is this only possible with threads?

, . , . . , , .

Im, tcp java, , ? , , -, : ( psuedo, java):

. , SYN. , . , SYN. - , , , .

- . , , . , . , , TCP- . , , TCP-. , ? , RST - ?

+2

Java API. : connect(), SYN , finalConnect(), . , , OP_CONNECT .

Java "return false" , .

0

Source: https://habr.com/ru/post/1539051/


All Articles