Questions tagged [sockets]

An endpoint of a bi-directional inter-process communication flow. This often refers to a process flow over a network connection, but by no means is limited to such. Not to be confused with WebSocket (a protocol) or other abstractions (e.g. socket.io).

In computer networking, a socket* is an endpoint of a bidirectional inter-process communication flow across an Internet Protocol-based computer network, such as the Internet.

An internet socket address is the combination of an IP address (the location of the computer) and a port (which is mapped to the application program process) into a single identity, much like one end of a telephone connection is the combination of a phone number and a particular extension. It is primarily used in the Transport Layer.

An example IPv4 socket appears as: 10.1.1.1:80

An example IPv6 socket appears as: [fe80::1]:80 (Note the brackets)

The term is believed to have originated with the Berkeley Sockets API for Unix ca. 1983.

Related tags are , , , and .

* Not to be confused with (a protocol) or other abstractions (e.g. ).

Note to programmers, especially beginners, using the socket module: A great many questions about non-working socket programs seem to be based on a common misunderstanding that is discussed and corrected in this answer as well as this one. Please take the time to read and understand that answer if you are having problems.

66255 questions
89
votes
13 answers

Cannot find mysql.sock

I just had to re-install mysql and I am having a problem starting it up. It cannot find the socket (mysql.sock). The problem is that neither can I. In my Mac OS X 10.4 terminal, I type: locate mysql.sock, and I get back /private/tmp/mysql.sock. …
Tony
  • 18,776
  • 31
  • 129
  • 193
89
votes
8 answers

How many socket connections possible?

Has anyone an idea how many tcp-socket connections are possible on a modern standard Linux server? (There is in general less traffic on each connection, but all the connections have to be up all the time.)
TheHippo
  • 61,720
  • 15
  • 75
  • 100
88
votes
1 answer

How do Unix Domain Sockets differentiate between multiple clients?

TCP has the tuple pairs (IP Addr/port/type) to tell one client from another. UDP passes the client IP and port. How does the unix domain keep track of different clients? In other words the server creates a socket bound to some path say…
Translucent Pain
  • 1,441
  • 2
  • 14
  • 18
88
votes
4 answers

When should I use TCP_NODELAY and when TCP_CORK?

I understood that both of them disable Nagle's algorithm. When should/ shouldn't I use each one of them?
user360455
88
votes
1 answer

What is the difference between socket.send() and socket.sendall()?

I'm confused about socket.send() and socket.sendall() functions in Python. As I understand from the documentation send() function uses TCP protocol and sendall() function uses UDP protocol for sending data. I know that TCP is more reliable for most…
cengineer
  • 1,362
  • 1
  • 11
  • 18
88
votes
4 answers

What does Python's socket.recv() return for non-blocking sockets if no data is received until a timeout occurs?

Basically, I've read in several places that socket.recv() will return whatever it can read, or an empty string signalling that the other side has shut down (the official docs don't even mention what it returns when the connection is shut down...…
El Ninja Trepador
  • 1,013
  • 1
  • 10
  • 14
88
votes
4 answers

How to detect a remote side socket close?

How do you detect if Socket#close() has been called on a socket on the remote side?
Kevin Wong
  • 14,656
  • 11
  • 42
  • 52
88
votes
4 answers

What does it mean to bind a multicast (UDP) socket?

I am using multicast UDP between hosts that have multiple network interfaces. I am using boost::asio, and am confused by the 2 operations receivers have to make: bind, then join-group. Why do you need to specify the local address of an interface,…
haelix
  • 4,245
  • 4
  • 34
  • 56
87
votes
6 answers

shell script to kill the process listening on port 3000?

I want to define a bash alias named kill3000 to automate the following task: $ lsof -i:3000 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME ruby 13402 zero 4u IPv4 2847851 0t0 TCP *:3000 (LISTEN) $ kill -9 13402
Jonathan
  • 10,936
  • 8
  • 64
  • 79
87
votes
15 answers

Instantly detect client disconnection from server socket

How can I detect that a client has disconnected from my server? I have the following code in my AcceptCallBack method static Socket handler = null; public static void AcceptCallback(IAsyncResult ar) { //Accept incoming connection Socket listener…
Smart Alec
87
votes
8 answers

java.net.SocketTimeoutException: Read timed out under Tomcat

I have a Tomcat based web application. I am intermittently getting the following exception, Caused by: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at…
Victor
  • 1,207
  • 2
  • 13
  • 21
85
votes
8 answers

Cannot bind to some ports due to permission denied

For the last 3 months or so I'm having random errors where I can't bind a specific port where our Identity server is running on my local development workstation. At first I thought it's my broken machine, so I reset everything, which kinda fixed the…
peter
  • 14,348
  • 9
  • 62
  • 96
84
votes
5 answers

How to find the socket buffer size of linux

What's the default socket buffer size of linux? Is there any command to see it?
Freewind
  • 193,756
  • 157
  • 432
  • 708
83
votes
8 answers

Is it possible to use Socket.io with AWS Lambda?

Is it possible to build a function in AWS Lambda that creates a websocket and send data to subscribed applications? Something like this: John has the app SuperPhotoApp opened in his phone but decides to use the desktop browser to upload a photo to…
Vladislav
  • 1,392
  • 1
  • 12
  • 21
83
votes
6 answers

TypeError: a bytes-like object is required, not 'str'

The following is the code that tries to modify the input supplied by a user by using sockets: from socket import * serverName = '127.0.0.1' serverPort = 12000 clientSocket = socket(AF_INET, SOCK_DGRAM) message = input('Input lowercase…
sri
  • 831
  • 1
  • 6
  • 3