How to detect a remote side socket close? [duplicate]

The isConnected method won’t help, it will return true even if the remote side has closed the socket. Try this: public class MyServer { public static final int PORT = 12345; public static void main(String[] args) throws IOException, InterruptedException { ServerSocket ss = ServerSocketFactory.getDefault().createServerSocket(PORT); Socket s = ss.accept(); Thread.sleep(5000); ss.close(); s.close(); } } public class … Read more

How to write a scalable TCP/IP based server

I’ve written something similar to this in the past. From my research years ago showed that writing your own socket implementation was the best bet, using the asynchronous sockets. This meant that clients not really doing anything actually required relatively few resources. Anything that does occur is handled by the .NET thread pool. I wrote … Read more

Simulate delayed and dropped packets on Linux

netem leverages functionality already built into Linux and userspace utilities to simulate networks. This is actually what Mark’s answer refers to, by a different name. The examples on their homepage already show how you can achieve what you’ve asked for: Examples Emulating wide area network delays This is the simplest example, it just adds a … Read more

How can I make a browser to browser (peer to peer) connection? [closed]

Here on Stackoverflow are several topics about P2P connections in browsers: Will HTML5 allow web apps to make peer-to-peer HTTP connections? What techniques are available to do P2P in the browser? Does HTML5 Support Peer-to-Peer (and not just WebSockets) Can HTML5 Websockets connect 2 clients (browsers) directly without using a server (P2P) Is it possible … Read more

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

Since you’re using a TcpClient, that means you’re checking open TCP ports. There are lots of good objects available in the System.Net.NetworkInformation namespace. Use the IPGlobalProperties object to get to an array of TcpConnectionInformation objects, which you can then interrogate about endpoint IP and port. int port = 456; //<— This is your value bool … Read more