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

read and write to same socket (TCP) using select

We're writing a client and a server to do (what I thought was) pretty simple network communications. Mulitple clients connect to the server which then is supposed to send the data back to all other clients. The server just sits in a blocking select…
MarcWan
  • 2,943
  • 3
  • 28
  • 41
11
votes
4 answers

C socket get IP address from filedescriptor returned from accept

I know this question seems typical and multiple times answered but I think if you read the details it is not so common (I did not find it). The point is that I am developing a unix service in c that opens a socket and waits for connections, when I…
Aleix
  • 663
  • 1
  • 8
  • 22
11
votes
4 answers

How to Create a TCP socket connect using C to a predefined port

I have a very simple question. I want to test whether a particular port is currently under use or not. For this, I want to bind a TCP socket to the port, if the connection is refused means the port is in use and if not that mean the port is…
krabhishek
  • 155
  • 3
  • 4
  • 6
11
votes
1 answer

Specify the outgoing IP address to use with TCPClient / Socket in C#

I've a server with several IP Addresses assigned to the network adapter. On that server is a client app to connect to another server app via TCPClient. For all outgoing communications my servers default IP address is being used, however for this one…
Dave Hogan
  • 3,201
  • 6
  • 29
  • 54
11
votes
4 answers

Socket.Close doesn't really close tcp socket? (c#)

It seems that using socket.Close() for a tcp socket, doesn't fully close the socket. In the following example I'm trying to connect to example.com at port 9999, which is not opened, and after a short-timeout, I'm trying to close the socket. for…
r0u1i
  • 3,526
  • 6
  • 28
  • 36
11
votes
1 answer

QT: socket notifiers cannot be enabled from another thread

I have a QTcpSocket and I need to control it - write + read using multiple threads. This works fine in QT4 but in QT5 I am getting this error and it seems that only 1 thread has access to socket at a same time. How do I make it possible for a socket…
Petr
  • 13,747
  • 20
  • 89
  • 144
11
votes
5 answers

Protect a socket in VpnService

I'm exploring the capabilities of Android's VpnService. Presently, I've built a very rudimentary request forwarder by essentially rebuilding the IP stack in user space: I read IP packets from the VpnService's input stream, parse them, and for…
11
votes
1 answer

Java - Getting a server's hostname and/or ip address from client

So here is my situation. I need to use sockets in creating connections between server and client. This cannot be negotiated. I have a server running and listening using something like this ServerSocket serverSocket = new ServerSocket(portNumber); …
Javier Pena
  • 115
  • 1
  • 2
  • 6
11
votes
2 answers

Minimizing copies when writing large data to a socket

I am writing an application server that processes images (large data). I am trying to minimize copies when sending image data back to clients. The processed images I need to send to clients are in buffers obtained from jemalloc. The ways I have…
Rajiv
  • 2,587
  • 2
  • 22
  • 33
11
votes
3 answers

Linux socket: How to make send() wait for recv()

I am making a simple client-server application using TCP protocal. I Know that by default. recv() will block until the other side call a send() to this socket. But is it possible that send() block itself until the other side has recv()ed the msg…
user2151995
  • 113
  • 1
  • 1
  • 4
11
votes
3 answers

python raw socket: Protocol not supported

I am trying to open a raw socket with Python under linux. My simple code: s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) s.bind((HOST, 5454)) And I got this error: [ERROR] Protocol not supported By the way, I am using python…
Jerry Meng
  • 1,466
  • 3
  • 21
  • 40
11
votes
1 answer

Socket communication, Java client C server

I am trying to communicate through sockets a Java client and a C server All seems to work fine if I try the server using nc on the command line to connect or if I use nc as a server and connect with my Java client, but when I try to connect Java…
Jebe
  • 135
  • 1
  • 1
  • 9
11
votes
6 answers

Getting "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'" error when setting up mysql database for Ruby on Rails app

I have been working on this all day long, and I need some help. I am trying to setup the mysql database for a RoR project I'm working on from github. When I try to setup the db in the terminal, I get the following error: Eric-MacBook:~ eric$ cd…
novicePrgrmr
  • 18,647
  • 31
  • 81
  • 103
11
votes
3 answers

Why can I connect to http://127.0.0.1:8000/ but not to http://192.168.1.6/

I'm running OS X Mountain Lion on a machine with local IP address 192.168.1.6 (as reported by both the Network utility and ifconfig) and am running a local (Django) development web server on port 8000 that I would like to connect to from a virtual…
shanusmagnus
  • 2,340
  • 2
  • 20
  • 19
11
votes
4 answers

Socket programming read() is reading all of my writes()

I have a client and a server. I have two read() in my client and two write() in my server code. The server sends data to the client on the first write(), the client reads and stores to a buffer but it doesn't stop reading, it keeps reading through…
user2644819
  • 1,787
  • 7
  • 28
  • 41
1 2 3
99
100