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
42
votes
3 answers

How to know whether any process is bound to a Unix domain socket?

I'm writing a Unix domain socket server for Linux. A peculiarity of Unix domain sockets I quickly found out is that, while creating a listening Unix socket creates the matching filesystem entry, closing the socket doesn't remove it. Moreover, until…
Simon Malinge
  • 523
  • 1
  • 4
  • 5
42
votes
5 answers

How to inspect websocket traffic with charlesproxy for iOS simulator/devices

I would like to inspect network traffic going through web sockets, I have no control over the networking code as this is a binary lib for which I do not have the source code, so I cannot do any log/breakpoint in the networking part of the code. I…
matanwrites
  • 812
  • 1
  • 10
  • 18
42
votes
5 answers

WebSocket server in Python: 'module' object has no attribute 'AF_INET'

I am trying to run this simple Python WebSocket, with a couple very minor changes. I am running Python 2.4.3 because I cannot use an newer version, but I'm not sure how much that matters. Here is the error I'm getting: Traceback (most recent call…
Gus
  • 1,905
  • 6
  • 23
  • 37
42
votes
2 answers

UDP Socket Set Timeout

I am trying to set a 100ms timeout on a UDP Socket. I am using C. I have posted relavent pieces of my code below. I am not sure why this is not timing out, but just hangs when it doesn't receive a segment. Does this only work on sockets that are…
rharrison33
  • 1,252
  • 4
  • 18
  • 34
42
votes
3 answers

Socket connections and Polling. Which is a better solution in terms of battery life?

So... I'm making an application for Android. The application needs to send and receive realtime chat data (needs to be a socket) but it also needs to send commands (which don't as the client knows when it is sending something). I need to know what…
shadrx
  • 941
  • 1
  • 8
  • 22
41
votes
3 answers

Where to place Unix Domain (AF_UNIX) sockets' end points (files)?

Is there a convention where to place the 'files' representing the end points to Unix Domain Sockets? I tend to put them to /tmp/some-application-specific-subdir-name/, but I wonder if there is a more common place. The background is, that POSIX is…
alk
  • 69,737
  • 10
  • 105
  • 255
41
votes
2 answers

What's the purpose of using sendto()/recvfrom() instead of connect()/send()/recv() with UDP sockets?

I can grasp the concept of TCP vs UDP, but still I don't know why are there 2 ways of sending UDP packets, and with that I still don't understand if this is absolutely necessary to bind() and accept()...
jokoon
  • 6,207
  • 11
  • 48
  • 85
41
votes
2 answers

Reading inputStream using BufferedReader.readLine() is too slow

I am using following code. BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line = null; StringBuilder responseData = new StringBuilder(); while((line = in.readLine()) != null) { …
Lohit
  • 891
  • 5
  • 14
  • 26
41
votes
6 answers

JS file gets a net::ERR_ABORTED 404 (Not Found)

I am trying to create a simple Io-web-chat. I recently wanted to seperate my