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
104
votes
6 answers

Chrome hangs after certain amount of data transfered - waiting for available socket

I've got a browser game and I have recently started adding audio to the game. Chrome does not load the whole page and gets stuck at "91 requests | 8.1 MB transferred" and does not load any more content; and it even breaks the website in all other…
Foxhoundn
  • 1,766
  • 2
  • 13
  • 19
104
votes
4 answers

What can cause a “Resource temporarily unavailable” on sock send() command

What can cause a Resource temporarily unavailable error on a socket send() command? The socket is setup as AF_UNIX, SOCK_STREAM. It works most of the time, but occasionally gets this error. The receiving end of the socket appears to be working…
giroy
  • 2,203
  • 6
  • 27
  • 38
103
votes
10 answers

Is there a way for multiple processes to share a listening socket?

In socket programming, you create a listening socket and then for each client that connects, you get a normal stream socket that you can use to handle the client's request. The OS manages the queue of incoming connections behind the scenes. Two…
Daniel Earwicker
  • 114,894
  • 38
  • 205
  • 284
99
votes
3 answers

UNIX nonblocking I/O: O_NONBLOCK vs. FIONBIO

In every example and discussion I run across in the context of BSD socket programming, it seems that the recommended way to set a file descriptor to nonblocking I/O mode is using the O_NONBLOCK flag to fcntl(), e.g. int flags = fcntl(fd, F_GETFL,…
Alex Balashov
  • 3,218
  • 4
  • 27
  • 36
98
votes
12 answers

Bind failed: Address already in use

I am attempting to bind a socket to a port below: if( bind(socket_desc,(struct sockaddr *) &server, sizeof(server)) < 0) { perror("bind failed. Error"); return 1; } puts("bind done"); But it gives: $ ./serve Socket created bind…
TamiL
  • 2,706
  • 4
  • 24
  • 44
97
votes
10 answers

Detecting TCP Client Disconnect

Let's say I'm running a simple server and have accept()ed a connection from a client. What is the best way to tell when the client has disconnected? Normally, a client is supposed to send a close command, but what if it disconnects manually or loses…
Zxaos
  • 7,791
  • 12
  • 47
  • 61
95
votes
12 answers

Why is it impossible, without attempting I/O, to detect that TCP socket was gracefully closed by peer?

As a follow up to a recent question, I wonder why it is impossible in Java, without attempting reading/writing on a TCP socket, to detect that the socket has been gracefully closed by the peer? This seems to be the case regardless of whether one…
Alexander
  • 9,302
  • 2
  • 26
  • 22
95
votes
10 answers

java.net.SocketException: Software caused connection abort: recv failed

I haven't been able to find an adequate answer to what exactly the following error means: java.net.SocketException: Software caused connection abort: recv failed Notes: This error is infrequent and unpredictable; although getting this error means…
grammar31
  • 2,000
  • 1
  • 12
  • 17
94
votes
4 answers

Where to find the complete definition of off_t type?

I am sending file from client to server using TCP. To mark the end of the file I like to send file size before the actual data. So I use stat system call to find the size of the file. This is of type off_t. I like to know how many bytes it occupies…
FourOfAKind
  • 2,298
  • 5
  • 31
  • 34
94
votes
5 answers

What is SOCK_DGRAM and SOCK_STREAM?

I just came across this strange thing I got to see application is that by default they use SOCK_STREAM function. Why is it so? Is this SOCK_STREAM just creating multiple streams? Or is it the standard SOCK_STREAM function available for creating…
echo9
  • 1,159
  • 1
  • 13
  • 15
93
votes
4 answers

Simple Socket Server in Bash?

Is there a way to quickly bind to a TCP port/ip address and simply print out all information to STDOUT? I have a simple debugging solution which writes things to 127.0.0.1:4444 and I'd like to be able to simply bind up a port from bash and print…
Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
92
votes
6 answers

Setting a timeout for socket operations

When I create a socket: Socket socket = new Socket(ipAddress, port); It throws an exception, which is OK, because the IP address is not available. (The test variables where String ipAddress = "192.168.0.3" and int port = 300.) The problem is: how…
Jennifer
  • 921
  • 1
  • 7
  • 3
90
votes
13 answers

Socket accept - "Too many open files"

I am working on a school project where I had to write a multi-threaded server, and now I am comparing it to apache by running some tests against it. I am using autobench to help with that, but after I run a few tests, or if I give it too high of a…
Scott
  • 2,557
  • 5
  • 26
  • 32
90
votes
21 answers

WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400

I am trying to integrate Socket.io with Angular and I'm having difficulties making a connection from the client-side to the server. I've looked through other related questions but my issue is happening locally, so there's no web server in the…
ashe540
  • 2,041
  • 2
  • 17
  • 17
90
votes
5 answers

What does EAGAIN mean?

As in the title what does EAGAIN mean?
David van Dugteren
  • 3,879
  • 9
  • 33
  • 48