EzDevInfo.com

tcp interview questions

Top tcp frequently asked interview questions

In C#, how to check if a TCP port is available?

In C# to use a TcpClient or generally to connect to a socket how can I first check if a certain port is free on my machine?

more info: This is the code I use:

TcpClient c;
//I want to check here if port is free.
c = new TcpClient(ip, port);

Source: (StackOverflow)

Simulate delayed and dropped packets on Linux

I would like to simulate packet delay and loss for UDP and TCP on Linux to measure the performance of an application. Is there a simple way to do this?


Source: (StackOverflow)

Advertisements

How do ports work with IPv6?

Conventional IPv4 dotted quad notation separates the address from the port with a colon, as in this example of a webserver on the loopback interface:

127.0.0.1:80

but with IPv6 notation the address itself can contain colons. For example, this is the short form of the loopback address:

::1

How are ports (or their functional equivalent) expressed in a textual representation of an IPv6 address/port endpoint?


Source: (StackOverflow)

Can two applications listen to the same port?

As simple as it gets - can two applications on the same machine bind to the same port and ip address? Taking it a step further, can one app listen to requests coming from a certain ip and the other to another remote ip? I know I can have one application that starts off two threads (or forks) to have similar behavior, but can two applications that have nothing in common do the same?

thanks.


Source: (StackOverflow)

UDP vs TCP, how much faster is it?

For general protocol message exchange, which can tolerate some packet loss. How much more efficient is UDP over TCP?


Source: (StackOverflow)

Freeing up a TCP/IP port?

netstat -tulnap shows me what ports are in use. How to free up a port in Linux?


Source: (StackOverflow)

Linux: is there a read or recv from socket with timeout?

How can I try to read data from socket with timeout? I know, select, pselect, poll, has a timeout field, but using of them disables "tcp fast-path" in tcp reno stack.

The only idea I have is to use recv(fd, ..., MSG_DONTWAIT) in a loop


Source: (StackOverflow)

Sniffer for localhost (Windows OS) [closed]

I am looking for a sniffer that can work with the loopback address in Windows.

So far, I found Microsoft Network Monitor which is a nice tool, but for localhost it's useless because on Windows, localhost packets don't pass through the regular network stack, so they're invisible to an ethernet sniffer like MS Network Monitor.

How do you debug applications that send data in the loopback mechanism? Any good (open source) sniffers that can work with localhost?

UPDATE: If you have experience with a tool, it would be nice to have a short description for future reference


Source: (StackOverflow)

How do multiple clients connect simultaneously to one port, say 80, on a server?

I understand the basics of how ports work. However, what I don't get is how multiple clients can simultaneously connect to say port 80. I know each client has a unique (for their machine) port. Does the server reply back from an available port to the client, and simply state the reply came from 80? How does this work?


Source: (StackOverflow)

How can I connect to Android with ADB over TCP?

I am attempting to debug an application on a Motorola Droid, but I am having some difficulty connecting to the device via USB. My development server is a Windows 7 64-bit VM running in Hyper-V, and so I cannot connect directly via USB in the guest or from the host.

I installed a couple of different USB-over-TCP solutions, but the connection appears to have issues since the ADB monitor reports "devicemonitor failed to start monitoring" repeatedly. Is there a way to connect directly from the client on the development machine to the daemon on the device using the network instead of the USB connection or possibly another viable options?


Source: (StackOverflow)

Who is listening on a given TCP port on Mac OS X?

On Linux, I can use netstat -pntl | grep $PORT or fuser -n tcp $PORT to find out which process (PID) is listening on the specified TCP port. How do I get the same information on Mac OS X?


Source: (StackOverflow)

What does "connection reset by peer" mean?

What is the meaning of the "connection reset by peer" error on a TCP connection? Is it a fatal error or just a notification?


Source: (StackOverflow)

When is it appropriate to use UDP instead of TCP?

Since TCP guarantees packet delivery and thus can be considered "reliable", whereas UDP doesn't guarantee anything and packets can be lost. What would be the advantage of transmitting data using UDP in an application rather than over a TCP stream? In what kind of situations would UDP be the better choice, and why?

I'm assuming that UDP is faster since it doesn't have the overhead of creating and maintaining a stream, but wouldn't that be irrelevant if some data never reaches its destination?


Source: (StackOverflow)

Why is SCTP not much used/known

I recently checked out the book "UNIX Network Programming, Vol. 1" by Richards Stevens and I found that there is a third transport layer standard besides TCP and UDP: SCTP.

Summary: SCTP is a transport-level protocal that is message-driven like UDP, but reliable like TCP. Here is a short introduction from IBM DeveloperWorks.

Honestly, I have never heard of SCTP before. I can't remember reading about it in any networking books or hearing about it in classes I had taken. Reading other stackoverflow questions that mentions SCTP suggests that I'm not alone with this lack of knowledge.

Why is SCTP so unknown? Why is it not much used?


Source: (StackOverflow)