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
48
votes
2 answers

Long connections with Node.js, how to reduce memory usage and prevent memory leak? Also related with V8 and webkit-devtools

Here is what I'm trying to do: I'm developing a Node.js http server, which will hold long connections for pushing purpose(collaborate with redis) from tens of thousands of mobile clients in a single machine. Test environment: 1.80GHz*2 CPU/2GB…
Aaron Wang
  • 1,091
  • 1
  • 11
  • 17
48
votes
8 answers

How Do I Use Raw Socket in Python?

I am writing an application to test a network driver for handling corrupted data. And I thought of sending this data using raw socket, so it will not be corrected by the sending machine's TCP-IP stack. I am writing this application solely on Linux.…
Avihu Turzion
  • 3,284
  • 4
  • 25
  • 34
48
votes
8 answers

Python Socket Multiple Clients

So I am working on an iPhone app that requires a socket to handle multiple clients for online gaming. I have tried Twisted, and with much effort, I have failed to get a bunch of info to be sent at once, which is why I am now going to attempt…
Alec
  • 919
  • 2
  • 10
  • 25
47
votes
3 answers

How to disconnect from tcp socket in NodeJs

I connect to socket server in NodeJs using this command: client = net.createConnection() How can I then properly disconnect from the server? I tried client.end() and even client.destroy() but when I check the connection status using netstat it…
mgamer
  • 13,580
  • 25
  • 87
  • 145
47
votes
3 answers

.NET sockets vs C++ sockets at high performance

My question is to settle an argument with my co-workers on C++ vs C#. We have implemented a server that receives a large amount of UDP streams. This server was developed in C++ using asynchronous sockets and overlapped I/O using completion ports. …
mdarsigny
  • 607
  • 1
  • 6
  • 9
47
votes
7 answers

How to abort socket's BeginReceive()?

Naturally, BeginReceive() will never end if there's no data. MSDN suggests that calling Close() would abort BeginReceive(). However, calling Close() on the socket also performs a Dispose() on it, as figured out in this great answer, and consequently…
Day_Dreamer
  • 3,311
  • 7
  • 34
  • 61
47
votes
10 answers

How to set a timeout on blocking sockets in boost asio?

Is there a way to cancel a pending operation (without disconnect) or set a timeout for the boost library functions? I.e. I want to set a timeout on blocking socket in boost asio? socket.read_some(boost::asio::buffer(pData, maxSize),…
Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636
47
votes
7 answers

Sending a file over TCP sockets in Python

I've successfully been able to copy the file contents (image) to a new file. However when I try the same thing over TCP sockets I'm facing issues. The server loop is not exiting. The client loop exits when it reaches the EOF, however the server is…
Swaathi Kakarla
  • 2,227
  • 1
  • 19
  • 27
47
votes
1 answer

How is SSH_AUTH_SOCK setup and used by ssh-agent?

I have been able to setup the sharing of ssh-agent for public-key authentication after reading https://superuser.com/a/230872/301446 The environment file thus generated has the following contents: SSH_AUTH_SOCK=/tmp/ssh-OwqeSuxmEsQN/agent.4744;…
user3104542
47
votes
4 answers

Difference between TCP Listener and Socket

As far as I know I can create a server using both TCPListener and Socket, so what is the difference between the two of them? Socket private Socket MainSock; MainSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream,…
Roman Ratskey
  • 5,101
  • 8
  • 44
  • 67
46
votes
2 answers

what does fd:// mean exactly in dockerd -H fd://

Docker daemon documentation suggests the following hosts option for most setups: dockerd -H fd:// I guess fd stands for file descriptor. I don't understand how fd is used for socket communication. I understand the following options: -H…
Mert Nuhoglu
  • 9,695
  • 16
  • 79
  • 117
46
votes
7 answers

Linux and I/O completion ports?

Using winsock, you can configure sockets or seperate I/O operations to "overlap". This means that calls to perform I/O are returned immediately, while the actual operations are completed asynchronously by separate worker threads. Winsock also…
someguy
  • 7,144
  • 12
  • 43
  • 57
46
votes
1 answer

How to make a simple multithreaded socket server in Python that remembers clients

How do I make a simple Python echo server that remembers clients and doesn't create a new socket for each request? Must be able to support concurrent access. I want to be able to connect once and continually send and receive data using this client…
nettux
  • 5,270
  • 2
  • 23
  • 33
46
votes
2 answers

Memory leak when emitting messages with Socket.IO + Node.js + ZMQ

I have three applications talking to each other. A websocket server (1) that accepts connections from browsers, parses url to see what data is required, serves it to client if it has the data in memory, if not asks for it from another application…
Deniz Ozger
  • 2,565
  • 23
  • 27
46
votes
1 answer

Catch "socket.error: [Errno 111] Connection refused" exception

How could I catch socket.error: [Errno 111] Connection refused exception ? try: senderSocket.send("Hello") except ?????: print "catch !"
URL87
  • 10,667
  • 35
  • 107
  • 174