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
1114
votes
38 answers

What is the difference between a port and a socket?

This was a question raised by one of the software engineers in my organisation. I'm interested in the broadest definition.
Richard Dorman
  • 23,170
  • 16
  • 45
  • 49
899
votes
2 answers

What does "connection reset by peer" mean?

What is the meaning of the "connection reset by peer" error on a TCP connection? Is it a fatal error or just a notification or related to the network failure?
Franck Freiburger
  • 26,310
  • 20
  • 70
  • 95
842
votes
2 answers

How do SO_REUSEADDR and SO_REUSEPORT differ?

The man pages and programmer documentations for the socket options SO_REUSEADDR and SO_REUSEPORT are different for different operating systems and often highly confusing. Some operating systems don't even have the option SO_REUSEPORT. The WWW is…
Mecki
  • 125,244
  • 33
  • 244
  • 253
794
votes
17 answers

TypeError: 'module' object is not callable

File "C:\Users\Administrator\Documents\Mibot\oops\blinkserv.py", line 82, in __init__ self.serv = socket(AF_INET,SOCK_STREAM) TypeError: 'module' object is not callable Why am I getting this error? I'm confused. How can I solve this error?
user551717
  • 8,217
  • 5
  • 18
  • 9
423
votes
19 answers

How do I debug error ECONNRESET in Node.js?

I'm running an Express.js application using Socket.io for a chat webapp and I get the following error randomly around 5 times during 24h. The node process is wrapped in forever and it restarts itself immediately. The problem is that restarting…
Samson
  • 2,801
  • 7
  • 37
  • 55
352
votes
17 answers

Can two applications listen to the same port?

Can two applications on the same machine bind to the same port and IP address? Taking it a step further, can one app listen to requests coming from a certain IP and the other to another remote IP? I know I can have one application that starts off…
nadiv
  • 3,531
  • 3
  • 16
  • 4
343
votes
19 answers

Getting the IP address of the current machine using Java

I am trying to develop a system where there are different nodes that are run on different system or on different ports on the same system. Now all the nodes create a Socket with a target IP as the IP of a special node known as a bootstrapping node.…
sasidhar
  • 7,523
  • 15
  • 49
  • 75
309
votes
38 answers

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

I am getting the following error when I try to connect to mysql: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Is there a solution for this error? What might be the reason behind it?
Atul
  • 4,463
  • 5
  • 23
  • 19
281
votes
5 answers

What is AF_INET, and why do I need it?

I'm getting started on socket programming, and I keep seeing this AF_INET. Yet, I've never seen anything else used in its place. My lecturers are not that helpful and just say "You just need it". So my questions: What is the purpose of AF_INET? Is…
Smashery
  • 57,848
  • 30
  • 97
  • 128
276
votes
6 answers

Difference between socket and websocket?

I'm building web app that needs to communicate with another application using socket connections. This is new territory for me, so want to be sure that sockets are different than websockets. It seems like they're only conceptually similar. Asking…
Jonathon
  • 2,793
  • 2
  • 15
  • 5
260
votes
6 answers

mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists

While starting mysql server 5.7.17 using mysqld_safe, following error occcours. 2017-02-10T17:05:44.870970Z mysqld_safe Logging to '/var/log/mysql/error.log'. 2017-02-10T17:05:44.872874Z mysqld_safe Logging to…
Rajadip
  • 2,799
  • 2
  • 11
  • 15
259
votes
9 answers

What is the Difference Between read() and recv() , and Between send() and write()?

What is the difference between read() and recv(), and between send() and write() in socket programming in terms of performances, speed and other behaviors?
Sajad Bahmani
  • 17,325
  • 27
  • 86
  • 108
254
votes
7 answers

What is the difference between AF_INET and PF_INET in socket programming?

What is the difference between AF_INET and PF_INET in socket programming? I'm confused between using AF_INET and PF_INET in socket() and bind(). Also, how to give ip-address in sin_addr field?
SP Sandhu
  • 2,718
  • 3
  • 20
  • 18
253
votes
25 answers

An attempt was made to access a socket in a way forbidden by its access permissions. Why?

private void StartReceivingData(string ipAddress, int iPort) { try { if (!_bContinueReciving) { //initializeMainSocket(ipAddress, iPort); _mSocket = new Socket(AddressFamily.InterNetwork,…
andrew
  • 2,797
  • 3
  • 18
  • 16
251
votes
9 answers

close vs shutdown socket?

In C, I understood that if we close a socket, it means the socket will be destroyed and can be re-used later. How about shutdown? The description said it closes half of a duplex connection to that socket. But will that socket be destroyed like close…
user188276
1
2 3
99 100