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
11
votes
1 answer

Does SO_RCVTIMEO affect accept()?

Does the SO_RCVTIMEO option affect accept (causing it to return EAGAIN or EWOULDBLOCK if the timeout expires)? Is there any behavior specified by the standard? I can't find it in the documentation for accept or use of…
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
11
votes
2 answers

How to get amount of non-ACK-ed TCP data for the socket?

Linux has ioctl SIOCOUTQ described in man-page tcp(7) that returns amount of unsent data in socket buffers. If I understand kernel code right, all the non-ACKed data is counted as "unsent". The ioctl is available at least since 2.4.x. Is there…
darkk
  • 824
  • 7
  • 13
11
votes
2 answers

R socketConnection/make.socket(): any way to keep listen()ing?

[Disclaimer: my knowledge of sockets is very rusty, and I'm just getting into R, so if I missed something completely obvious, please point it out!] If I understand the (sparsely-documented) R functions for creating and managing sockets, namely…
Derrick Turk
  • 4,246
  • 1
  • 27
  • 27
11
votes
5 answers

Java Detect Closed Stream

I have a general socket implementation consisting of an OutputStream and an InputStream. After I do some work, I am closing the OutputStream. When this is done, my InputStream's read() method returns -1 for an infinite amount of time, instead of…
Derek
  • 113
  • 1
  • 4
11
votes
3 answers

In Win32, is there a way to test if a socket is non-blocking?

In Win32, is there a way to test if a socket is non-blocking? Under POSIX systems, I'd do something like the following: int is_non_blocking(int sock_fd) { flags = fcntl(sock_fd, F_GETFL, 0); return flags & O_NONBLOCK; } However, Windows…
Daniel Stutzbach
  • 74,198
  • 17
  • 88
  • 77
11
votes
2 answers

How to make 2 clients connect each other directly, after having both connected a meeting-point server?

I'm writing a toy meeting-point/relay server listening on port 5555 for two clients "A" and "B". It works like this: every byte received by the server from the firstly-connected client A will be sent to the secondly-connected client B, even if A…
Basj
  • 41,386
  • 99
  • 383
  • 673
11
votes
3 answers

How can I wait until I receive data using a Python socket?

I am creating a socket client and trying to obtain some data. In order to do so, I need to connect to a web server via socket and the server actually creates another socket which listens and awaits for the data after which sends back to the client.…
aikhs
  • 949
  • 2
  • 8
  • 20
11
votes
2 answers

How to send raw bytes through a Dart TCP socket

I'm stuck on the dumbest possible hindrance I can think of. I'm developing a flutter app that should send via TCP socket (on a local wifi network) an array of bytes. Said bytes are raw and not representative of meaningful characters in any encoding…
Maldus
  • 10,548
  • 4
  • 24
  • 36
11
votes
3 answers

Sockets in C#: How to get the response stream?

I'm trying to replace this: void ProcessRequest(object listenerContext) { var context = (HttpListenerContext)listenerContext; Uri URL = new Uri(context.Request.RawUrl); HttpWebRequest.DefaultWebProxy = null; HttpWebRequest…
Tute
  • 6,943
  • 12
  • 51
  • 61
11
votes
3 answers

C# Using span with SocketAsyncEventArgs

I would like to use new Span to send unmanaged data straight to the socket using SocketAsyncEventArgs but it seems that SocketAsyncEventArgs can only accept Memory which cannot be initialized with byte * or IntPtr. So please is there a way to…
Teamol
  • 733
  • 1
  • 14
  • 42
11
votes
2 answers

Android Push Notifications Without using Firebase Cloud Messaging or any other similar service

I am developing an android chat application for learning purposes that uses a server- client architecture. I wrote the server side myself in Java (because I am trying to learn) and the client side is an android app. I am using TCP sockets for…
Evyatar Saias
  • 698
  • 7
  • 18
11
votes
5 answers

Unix sockets: when to use bind() function?

I've not a clear idea about when I have to use the bind() function. I guess it should be used whenever I need to receive data (i.e. recv() or recvfrom() functions) whether I'm using TCP or UDP, but somebody told me this is not the case. Can anyone…
The Coding Monk
  • 7,684
  • 12
  • 41
  • 56
11
votes
1 answer

Socket servers, SocketAsyncEventArgs and concurrent connections in .Net

I've been writing a socket server based around the one on CodeProject which itself derives from the original Microsoft example. In both cases, the inbound message is immediately returned to the sender using the same SocketAsyncEventArgs. In my case,…
Alan
  • 215
  • 1
  • 2
  • 10
11
votes
1 answer

ReactJS + Socket.IO - Best way to handle socket connection

I'm trying to make a ReactJS realtime application with Node and Socket.IO, but I'm having a hard time figuring out the best way to handle my socket connection on the clientside. I have multiple React components that all need some information from…
Phoenix1355
  • 1,589
  • 11
  • 16
11
votes
1 answer

Spring RestTemplate SocketException Connection reset on quick consecutive executions

Setup Simple server and client applications running locally. Server endpoint receives a POST request with a sleep time to simulate work. Client is a SpringBoot app using RestTemplate for HTTP calls. Simulating a 500ms delay at the server per request…
frpet
  • 155
  • 1
  • 9