Exception in thread “main” java.net.ConnectException: Connection refused: connect Socket Programming Java

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

java.net.SocketException: Network is unreachable: connect

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

What is the reason and how to avoid the [FIN, ACK] , [RST] and [RST, ACK]

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

UDP Client/Server Socket in Python

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

Python Socket Receive Large Amount of Data

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

How to set timeout on python’s socket recv method?

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

MAMP “Apache couldn’t be started because port is in use.” AND “Can’t connect to local MySQL server through /tmp/mysql.sock

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