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

Socket vs SocketChannel

I am trying to understand SocketChannels, and NIO in general. I know how to work with regular sockets and how to make a simple thread-per-client server (using the regular blocking sockets). So my questions: What is a SocketChannel? What is the…
Ramzi Khahil
  • 4,932
  • 4
  • 35
  • 69
82
votes
4 answers

Close multiple resources with AutoCloseable (try-with-resources)

I know that the resource you pass with a try, will be closed automatically if the resource has AutoCloseable implemented. So far so good. But what do I do when i have several resources that I want automatically closed. Example with sockets; try…
asmb
  • 1,015
  • 2
  • 8
  • 11
82
votes
11 answers

How to check if a socket is connected/disconnected in C#?

How can you check if a network socket (System.Net.Sockets.Socket) is still connected if the other host doesn't send you a packet when it disconnects (e.g. because it disconnected ungracefully)?
lesderid
  • 3,388
  • 8
  • 39
  • 65
81
votes
4 answers

Python socket connection timeout

I have a socket that I want to timeout when connecting so that I can cancel the whole operation if it can't connect yet it also want to use the makefile for the socket which requires no timeout. Is there an easy way to do this or is this going to…
anonymous
  • 811
  • 1
  • 6
  • 3
81
votes
3 answers

socket.io Removing specific listener

I'm using Socket.io v0.9.16 and Chrome 34 I'm trying to remove a specific listener, or unsubscribe from a specific subscription Something like this: socket.on('testComplete',function(data){ console.log('test complete',data); }); function…
user773737
80
votes
2 answers

How to terminate a thread blocking on socket IO operation instantly?

In the context of Java, I create a new thread to read network input when open a GUI window, and when i close the window, i want to release the socket resource and terminate the thread immediately. Now i am using setSoTimeout method, but i don't want…
dingx
  • 1,621
  • 3
  • 20
  • 38
79
votes
5 answers

Are message queues obsolete in linux?

I've been playing with message queues (System V, but POSIX should be ok too) in Linux recently and they seem perfect for my application, but after reading The Art of Unix Programming I'm not sure if they are really a good…
Purple Tentacle
  • 1,606
  • 1
  • 17
  • 19
79
votes
7 answers

socket.error:[errno 99] cannot assign requested address and namespace in python

My server software says errno99: cannot assign requested address while using an ip address other than 127.0.0.1 for binding. But if the IP address is 127.0.0.1 it works. Is it related to namespaces? I am executing my server and client codes in…
user2833462
  • 805
  • 1
  • 7
  • 6
79
votes
4 answers

Difference between UNIX domain STREAM and DATAGRAM sockets?

This question is NOT for the difference between STREAM type and DATAGRAM type INTERNET sockets. I know that STREAM sockets use TCP, Datagram sockets use UDP and all the TCP,UDP stuff, packets arriving in order, ACK, NACK etc. I understand the…
Manik Sidana
  • 2,005
  • 2
  • 18
  • 29
78
votes
4 answers

How do I use setsockopt(SO_REUSEADDR)?

I am running my own http server on a raspberry pi. The problem is when I stop the program and restart it, the port is no longer available. Sometimes I get the same issue when receiving lots of requests. I want to use SO_REUSEADDR so that I can keep…
user3735849
  • 893
  • 1
  • 6
  • 6
77
votes
6 answers

Good tool for testing socket connections?

I'm writing a TCP/IP client and I would need a "test server" to be able to test easily. It should listen on a configurable port, show me when a client connects, and what the client sent. It should allow me to manually enter text to send back to the…
Name
  • 3,430
  • 4
  • 30
  • 34
77
votes
8 answers

Error: Address already in use while binding socket with address but the port number is shown free by `netstat`

I tried to bind my socket(server socket) at port number 8000. It worked and did the job for me. At the end of the code I close the socket as well. The very next instant I run my code again and it shows me that the address is already in use. I have…
Durin
  • 2,070
  • 5
  • 23
  • 37
77
votes
4 answers

io.emit vs socket.emit

I'm new to socket.io and have run in to something that seems pretty weird. I don't actually know the difference between socket.emit and io.emit but I can't find an explanation anywhere. io.on('connection', function(socket){ io.emit('connected') …
Manu Masson
  • 1,667
  • 3
  • 18
  • 37
77
votes
10 answers

centos: Another MySQL daemon already running with the same unix socket

I have a strange error when starting mysqld service: Another MySQL daemon already running with the same unix socket. I've tried to list running services and stopping them but the same error happens when starting mysqld service. I can try to remove…
Mas
  • 1,267
  • 1
  • 14
  • 13
76
votes
13 answers

Python Socket Receive Large Amount of Data

When I try to receive larger amounts of data it gets cut off and I have to press enter to get the rest of the data. At first I was able to increase it a little bit but it still won't receive all of it. As you can see I have increased the buffer on…
user2585107
  • 783
  • 1
  • 7
  • 5