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

GetQueuedCompletionStatus can't dequeue IO from IOCP if the thread which originally issued the IO is blocking in ReadFile under windows 8

My app stop working after switching to windows 8. I spend hours to debug the problem, found out IOCP behave differently between windows 8 and previous versions. I extract the necessary code to demonstrate and reproduce the problem. SOCKET…
czz
  • 474
  • 3
  • 9
12
votes
10 answers

Good Readings on Unix/Linux Socket Programming?

though I haven't worked with sockets professionally, I find them interesting. I read some part of Unix Network Programming by Richard Stevens (considered to be the Bible I suppose as it is referred by everyone I ask) but the problem is the examples…
rocknroll
  • 1,128
  • 2
  • 15
  • 30
12
votes
4 answers

Do TCP sockets automatically close after some time if no data is sent?

I have a client server situation where the client opens a TCP socket to the server, and sometimes long periods of time will pass with no data being sent between them. I have encountered an issue where the server tries to send data to the client, and…
Nick Banks
  • 4,298
  • 5
  • 39
  • 65
12
votes
2 answers

Android illegalstatexception

I am trying to send UDP packets with Android to a server written in C# on my computer. When I run the app on my phone, I get an illegal state exception. I think it may have something to do with performing network operations on the main activity, but…
Lockhead
  • 2,423
  • 7
  • 35
  • 48
12
votes
2 answers

Get network address and network mask in Python

In my Python script I need to retrieve both the IP address of the machine the script is running on and its network address and its network bytes. As for the IP address, I found the solution in the archive: import socket s =…
Ricky Robinson
  • 21,798
  • 42
  • 129
  • 185
12
votes
1 answer

Simulate effect of select() and poll() in kernel socket programming

One of the Linux kernel drivers I am developing is using network communication in the kernel (sock_create(), sock->ops->bind(), and so on). The problem is there will be multiple sockets to receive data from. So I need something that will simulate a…
Joshua
  • 525
  • 5
  • 17
12
votes
2 answers

How to close (kill, release?) a socket, which is in FIN_WAIT_2 state?

I have a client application, which uses a unmanaged dll for communicating with a server. All network-related operations are perormed inside the unmanaged dll. After a number of operations with the server, the client is running out of TCP ports. If…
ulughbekula
  • 371
  • 1
  • 3
  • 12
12
votes
2 answers

get stream of a socket object in c#

I have a client-server application which communicates over TCP/IP. I use System.Net.Sockets.Socket type object for ascnyronous communication over TCP. Basicly i open connection send/receive data and close connection. And my implementation is based…
Fer
  • 1,962
  • 7
  • 29
  • 58
12
votes
3 answers

how do I find in C that a port is free to use?

The OS is Linux. I have a server process that can change its port realtime. However I would like to know in advance if a port is free before binding. Scenario: Server binds localhost:5000 and receives a request to bind at localhost:6000. The server…
cateof
  • 6,608
  • 25
  • 79
  • 153
12
votes
3 answers

Socket error 10052 on UDP socket

We have a .NET 2.0 desktop application which sends and receives network packets over UDP. Several users have reported an occasional socket error 10052 which happens when the code calls socket.BeginReceiveFrom on a the UDP socket. What does this…
Jesper
  • 903
  • 2
  • 6
  • 16
12
votes
6 answers

Is it possible to use an std::string for read()?

Is it possible to use an std::string for read() ? Example : std::string data; read(fd, data, 42); Normaly, we have to use char* but is it possible to directly use a std::string ? (I prefer don't create a char* for store the result) Thank's
Zat42
  • 2,471
  • 4
  • 22
  • 36
12
votes
3 answers

set timeout for socket receive

I want to send data to server, then wait for an answer for one minute and then close the socket. How to do it? DatagramPacket sendpack = new ......; socket.send(pack); DatagramPacket recievepack = new .....; //wait 1 minute{ …
11
votes
3 answers

Difference between recursive and iterative dns lookup

I am making a resolver and a nameserver program with out using dns libraries(such as netdb.h) by directly sending a dns message. but i have few problems. As far as i find out when we send a recursive request, the nameserver queried finds out the…
mohit jain
  • 397
  • 1
  • 3
  • 14
11
votes
4 answers

Performance of ReceiveAsync vs. BeginReceive

I'm currently programming a client application and I'm wondering whether I should use the Socket class' ReceiveAsync or BeginReceive method. I have been using the latter so far, however, I found that it seems to stress the CPU quite a bit. Here is…
haiyyu
  • 2,194
  • 6
  • 22
  • 34
11
votes
2 answers

How to create a WebSocket server using SuperWebSocket

I am creating an application which needs WebSocket Communication. All I need is a simple WebSocketServer with threading possibilities. I found that SuperWebSocket can satisfy my needs. But, my poor familiarity with C# makes trouble in understanding…
prabhakaran
  • 5,126
  • 17
  • 71
  • 107