Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include #include #include include int main () // Step 1: Create a socket int so

ID: 3734403 • Letter: #

Question

#include #include #include include int main () // Step 1: Create a socket int sockfd socket (AF_INET, SOCK_STREAM, 0) // Step 2: Set the destination information struct sockaddr_in dest; memset (&dest;, 0, sizeof (struct sockaddr_in)); dest. sin-family AF_INET; dest . sin-addr. s_addr = inet_addr ( " 10 . 0 . 2 . 17" ) ; dest . sin_port = htons (9090); // Step 3: Connect to the server connect (sockfd, (struct sockaddr)&dest; sizeof (struct sockaddr_in)); // Step 4: Send data to the server char *buffer! - "He 0 Server ! "; char buffer2 - "Hello Again! "; write (sockfd, bufferl, strlen (bufferl)); write (sockfd, buffer2, strlen (buffer2)); // Step 5: Close the connection close (sockefd) return 0

Explanation / Answer

Answers:

1 We can should use the Port number or Server name to get access from server than only we can access the server machine.

2

Once the application has called listen(), the TCP stack will perform the 3-way handshake for any incoming connections. These connections are queued in the kernel, and accept() then retrieves the next connection from the queue and returns it.

There's a backlog argument to listen, and it specifies how large this queue should be (although I think some implementations ignore this, and use a limit built into the stack). When the queue is full, the stack will no longer perform the handshake for incoming connections; the clients should retry, and their connections will succeed when the queue has room for them.

It's done this way so that the client receives the SYN/ACK as quickly as possible in the normal case (when the backlog queue has room), so it doesn't have to retransmit the SYN.

3 Yes, need separate TCP packer for every each write function.