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

Windows UDP sockets: recvfrom() fails with error 10054

Hello everyone. I'm trying to use Windows sockets to send and receive UDP packets (in C++). It worked well until three days ago, when the program stopped behaving properly. To summarize the situation: When calling WSAPoll() on my socket, it always…
Heowyn
  • 111
  • 1
  • 1
  • 5
11
votes
3 answers

Long delays in sending UDP packets

I have an application that receives, processes, and transmits UDP packets. Everything works fine if the port numbers for reception and transmission are different. If the port numbers are the same and the IP addresses are different it usually works…
ravenspoint
  • 19,093
  • 6
  • 57
  • 103
11
votes
1 answer

Is .NET Socket Send()/Receive() thread-safe?

Since a socket is full duplexed, meaning you can send and recieve simultaneously. So, is the .NET Socket Send()/Receive() thread-safe? I need to Send() and Receive() in 2 threads.
Dagang
  • 24,586
  • 26
  • 88
  • 133
11
votes
3 answers

how to get remote_ip from socket in phoenix-framework?

How to get remote_ip from socket in phoenixframework? I can get it from conn in View, but not in Channel. Many thanks for help!
11
votes
1 answer

How to get the underlying socket when using Python requests

I have a Python script that creates many short-lived, simultaneous connections using the requests library. I specifically need to find out the source port used by each connection and I figure I need access to the underlying socket for that. Is there…
Elektito
  • 3,863
  • 8
  • 42
  • 72
11
votes
2 answers

Android - how to run a socket in a long lives background thread

I'm building a simple chat that connects between an android client and a java server (running on my pc). The user can send and receive messages to/from the android app and the desktop server. I'm dealing now with the question of how to run the…
Presen
  • 1,809
  • 4
  • 31
  • 46
11
votes
1 answer

python socket send immediately

The problem with sockets is that they buffer data and send it when buffer fills or in given interval. Any way to avoid it and send something through socket with high priority, without any delay? In my case milliseconds count.
Flash Thunder
  • 11,672
  • 8
  • 47
  • 91
11
votes
3 answers

Measuring the latency of Unix domain sockets

I want to compare the performance of Unix domain sockets between two processes with that of another IPC. I have a basic program that creates a socket pair and then calls fork. Then, it measures the RTT to send the 8192 bytes to the other process and…
user4099632
11
votes
3 answers

Connect MySQL through localhost not working but 127.0.0.1 is working

OS: Ubuntu 14.04 LTS php version control : phpbrew php version : 5.5.10 I pinged localhost which resolved to 127.0.0.1. This indicates that my host (/etc/hosts) file is correct. 127.0.0.1 localhost Whenever I try connecting to MySQL using a php…
JoeCodeCreations
  • 660
  • 2
  • 6
  • 19
11
votes
7 answers

How to get your own (local) IP-Address from an udp-socket (C/C++)

You have multiple network adapters. Bind a UDP socket to an local port, without specifying an address. Receive packets on one of the adapters. How do you get the local ip address of the adapter which received the packet? The question is, "What is…
Christopher
  • 8,912
  • 3
  • 33
  • 38
11
votes
3 answers

recv with MSG_NONBLOCK and MSG_WAITALL

I want to use recv syscall with nonblocking flags MSG_NONBLOCK. But with this flag syscall can return before full request is satisfied. So, can I add MSG_WAITALL flag? Will it be nonblocking? or how should I rewrite blocking recv into the loop…
osgx
  • 90,338
  • 53
  • 357
  • 513
11
votes
3 answers

What things are exactly happening when server socket accept client sockets?

I'm studying socket programming, and the server socket accept() is confusing me. I wrote two scenarios for server socket accept(), please take a look: When the server socket does accept(), it creates a new (client) socket that is bound to a port…
Jongbin Park
  • 659
  • 6
  • 14
11
votes
5 answers

SignalR Websocket Exception when closing client

When starting and stopping a SignalR client that is connected to a basic self hosted server like this: async public void Start(string url) { _connection = new HubConnection(url); _proxy = _connection.CreateHubProxy("hubname"); await…
dsfgsho
  • 2,731
  • 2
  • 22
  • 39
11
votes
2 answers

Can a socket be made non-blocking only for the recv() function?

I want to be able to call recv() without having to block, so I want to make it non-blocking, but I do not want it to be non blocking when sending data. So can a socket be made non-blocking only for the recv() function, or does the…
user4182981
11
votes
1 answer

I need the server to send messages to all clients (Python, sockets)

This is my server program, how can it send the data received from each client to every other client? import socket import os from threading import Thread import thread def listener(client, address): print "Accepted connection from: ", address …