Socket.Select returns error “An operation was attempted on something that is not a socket”
It turns out the sockets were closed. That’s a really dumb error for .NET to be generating though just because of a closed socket.
It turns out the sockets were closed. That’s a really dumb error for .NET to be generating though just because of a closed socket.
There are 2 issues in your program: You use the port 80 which is part of the well-known ports or system ports (0 to 1023), so you need to launch your server with the admin rights or change it for 8080 for example. You forgot to call bw.newLine() after each bw.write(sendMessage) such that it waits for ever since on the other side you call br.readLine() which means that it … Read more
You are facing a connection breakdown. Does this happen in 3G, WiFi or “plain” connection on a computer? Anyway, you must assume that the connection may be lost from time to time, when writing your app. For example, with mobiles, this happens frequently in the tube, in basements, etc. With PC apps, this is less … Read more
Here is a rough explanation of the concepts. [ACK] is the acknowledgement that the previously sent data packet was received. [FIN] is sent by a host when it wants to terminate the connection; the TCP protocol requires both endpoints to send the termination request (i.e. FIN). So, suppose host A sends a data packet to host B and then host B wants … Read more
I tested your code, and it works as expected on my machine. Your issue might not be your code. It could be a firewall or something else blocking all the packets on the loopback interface (127.0.0.1). Depending on your operating system, try testing with a packet monitor like Wireshark. Also, here are a few suggestions … Read more
TCP/IP is a stream-based protocol, not a message-based protocol. There’s no guarantee that every send() call by one peer results in a single recv() call by the other peer receiving the exact data sent—it might receive the data piece-meal, split across multiple recv() calls, due to packet fragmentation. You need to define your own message-based protocol on top of TCP in order to differentiate message … Read more
The typical approach is to use select() to wait until data is available or until the timeout occurs. Only call recv() when data is actually available. To be safe, we also set the socket to non-blocking mode to guarantee that recv() will never block indefinitely. select() can also be used to wait on more than one socket at a time. If you have … Read more
Since this answer still gets voted up, I want to point out that you should almost never need to look in the header files. If you want to write reliable code, you’re much better served by looking in the standard. So, the answer to “where can I find the complete definition of off_t” is “in a … Read more
After restarting MAMP, I noticed the MySQL Server checkbox didn’t turn green as it usually does. I clicked ‘Start Servers’ again and got a message stating, “Apache couldn’t be started because port 8888 is in use by some other software.” Weird since I haven’t made any changes to the system or application, or installed any … Read more
Is it possible that the serverSocket is being closed from another thread? That will cause this exception.