Checking the Socket Status
There will be a lot of output for this, but the lines you want to look for are those with the port numbers your server is listening to as it’s running. The columns of interest include the first one,
tcp4, which indicates it’s a TCP socket connection using version four addressing, which you remember from the initializer in the server program.
macOS and Linux also provide another tool called
lsof, which stands for list open files. At some level of abstraction, sockets look similar to files where you read or save data instead of receiving or sending data.
If your copy of Linux doesn’t have
lsof, it shouldn’t be too hard to acquire. Both of these programs have additional command-line options. Be sure to check the documentation for other information the programs can give you. So, when should you use them?
Here are a couple of errors you might see that suggest you should look at socket status. The first is a
ConnectionRefusedError. If a client produces this error, it means that the server is probably running, but not accepting connections from the port, or maybe the host, that the client used. So you should check the status of the socket on the server to see if it’s active. You could also get a
Connection timed out error.
Become a Member to join the conversation.