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
51
votes
5 answers

How to enable Socket in PHP?

Could any one tell me how to enable SOCKET support in PHP ?
Fero
  • 12,969
  • 46
  • 116
  • 157
50
votes
6 answers

NGINX: connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory)

I'm trying to follow this Ansible tutorial while adjusting it for Ubuntu 16.04 with php7. Below this message you'll find my Ansible file. After running it and trying to visit the page in the browser I get a 404, and the following in the nginx error…
kramer65
  • 50,427
  • 120
  • 308
  • 488
50
votes
10 answers

How do I change a TCP socket to be non-blocking?

How do you make a socket non-blocking? I am aware of the fcntl() function, but I've heard it's not always reliable.
Sachin
  • 20,805
  • 32
  • 86
  • 99
50
votes
5 answers

what is RAW socket in socket programming

When I gone through socket programming I could not clearly understand RAW_SOCKET. My understanding is If I open a socket with this option AF_INET , RAW_SOCKET mean's I can create my own header before AF_INET headers but finally the data is send in…
kar
  • 2,505
  • 9
  • 30
  • 32
50
votes
2 answers

Why should I use non-blocking or blocking sockets?

At first, I must ask that which is the best in which states ? For example a real-time MMORPG server. What if i create a thread per client instead of using non-blocking sockets ? Or What if i use one thread that contains all non-blocking sockets ?…
deniz
  • 2,427
  • 4
  • 27
  • 38
49
votes
4 answers

Only one usage of each socket address (protocol/network address/port) is normally permitted?

I've been looking for a serious solution on google and I only get "Registry solutions" kind of stuff which I don't think even relate to my problem. For some reason I get this Error, while I'm only starting the TcpListner once, and when and if it…
WeinForce
  • 1,264
  • 2
  • 11
  • 17
49
votes
2 answers

Sockets - How to find out what port and address I'm assigned

I'm having trouble figuring this out - I'm working with sockets in C using this guide - http://binarii.com/files/papers/c_sockets.txt I'm trying to automatically get my ip and port using: server.sin_port = 0; /* bind() will choose a…
stringo0
  • 2,720
  • 7
  • 38
  • 52
49
votes
3 answers

How to get ip address from sock structure in c?

I'm writing simple server/client and trying to get client IP address and save it on server side to decide which client should get into critical section. I googled it several times but couldn't find proper way to get IP address from sock structure. I…
REALFREE
  • 4,378
  • 7
  • 40
  • 73
49
votes
2 answers

What is SOL_SOCKET used for?

As it is stated in the Linux man page Use this constant as the level argument to getsockopt or setsockopt to manipulate the socket-level options described in this section But I don't get this explanation. What is the purpose of SOL_SOCKET? What…
Blake
  • 7,367
  • 19
  • 54
  • 80
49
votes
3 answers

simultaneously read and write on the same socket in C or C++

I am implementing a simple server, that accepts a single connection and then uses that socket to simultaneously read and write messages from the read and write threads. What is the safe and easy way to simultaneously read and write from the same…
Jimm
  • 8,165
  • 16
  • 69
  • 118
49
votes
2 answers

Message queues vs sockets

I don't have much of a socket programming experience but I tried read a little about it. I am quite familiar with MDB and messaging queues. Someone has told me that queue(e.g. MDB) is "Not much more than a direct socket connection". Can someone…
Sara
  • 2,417
  • 7
  • 35
  • 52
48
votes
9 answers

Is there a way to flush a POSIX socket?

Is there a standard call for flushing the transmit side of a POSIX socket all the way through to the remote end or does this need to be implemented as part of the user level protocol? I looked around the usual headers but couldn't find anything.
Gordon Wrigley
  • 11,015
  • 10
  • 48
  • 62
48
votes
1 answer

Understanding set/getsockopt SO_SNDBUF size doubles

Hi I have the following program to check the send buffer size for a UDP socket. However, I the return value is a bit confusing to me. I use the following simple app: #include #include int main(int argc, char **argv) { int…
mortenvp
  • 1,095
  • 1
  • 7
  • 13
48
votes
9 answers

What is the difference between Socket and ServerSocket?

If Socket represents client side and ServerSocket represents server side, why Socket.read reads the data from server side? I'm really confused, Can you please clarify it to me?
sevugarajan
  • 9,717
  • 12
  • 34
  • 31
48
votes
5 answers

Program received signal SIGPIPE, Broken pipe

I write a client program based on posix sockets. The program creates multiple threads and is going to lock the server. But during debug in gdb time the program gives an info (error) (gdb) n Program received signal SIGPIPE, Broken pipe. [Switching…
user1886376