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

Differences on Java Sockets between Windows and Linux - How to handle them?

I am having a lot of trouble in understanding the differences about how Java handles Sockets on Windows and Linux - Particularly when one of the sides (Client or Server) closes the connection abruptly. I have written the following very simple Server…
icmp_request
  • 123
  • 1
  • 5
11
votes
3 answers

non-blocking udp socket programming in C: what do I get?

I have a problem in understanding what recv()/recvfrom() return from an non-blockig UDP socket. A bit more specific and compared to TCP (please correct me if I'm wrong): A blocking socket (either TCP or UDP) won't return from a recv() until there…
Uwe
  • 113
  • 1
  • 1
  • 5
11
votes
1 answer

what is the purpose to set SOCK_CLOEXEC flag with accept4() same as O_CLOEXEC

Basically, I need to know what is the purpose of setting the SOCK_CLOEXEC when sitting it with accept4(). how can I check the functionality of this flag with the returned file descriptor from the accept. accepted_fd = accept4(sd, (struct sockaddr…
Hatem Mashaqi
  • 610
  • 1
  • 7
  • 18
11
votes
4 answers

Good lightweight library for HTTP POST/GET for C?

I'm planning of creating a Last.FM scrobbler plugin for a music player in Windows. Last.FM submissions API relays on HTTP/1.1 GET and POST. I've never done Internet oriented programming and I've still to know about the HTTP protocol but I'd like to…
Markus R.
  • 145
  • 1
  • 1
  • 4
11
votes
2 answers

Socket listen doesn't unbind in C++ under linux

I have a socket that listens on some port. I send the SIGSTOP signal to the thread that waits on the port (using accept) and terminate it. then I close the fd of the socket that I waited on. But for the next run of my project it doe's not allow me…
Shayan
  • 2,758
  • 7
  • 36
  • 55
11
votes
5 answers

Convert "little endian" hex string to IP address in Python

What's the best way to turn a string in this form into an IP address: "0200A8C0". The "octets" present in the string are in reverse order, i.e. the given example string should generate 192.168.0.2.
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
11
votes
5 answers

Flushing the socket streams in C socket programming

I wanted to know how to flush the socket streams while doing socket programming in C. I tried all the options- setting TCP_NODELAY using the following code- setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)); Note: all…
MohamedSanaulla
  • 6,112
  • 5
  • 28
  • 45
11
votes
4 answers

Can we send data from an android device to another android device directly (p2p) without server in the middle?

I need to send data from one android device to another android device directly(p2p) after they find each other through a server. I read some stuff that this can't be done but I don't understand why a device that can access the internet (it has an IP…
armin
  • 1,985
  • 6
  • 38
  • 52
11
votes
2 answers

Send multiple OBD commands together and get response simultaneously

I'm working on application which connects OBD2 adapter and getting the real time data like speed,rpm,throttle position etc..When I read one command at a time, it works fine like by sending command "010C\r", I get current RPM. I think that sending…
NSS
  • 721
  • 1
  • 10
  • 23
11
votes
1 answer

C++ Read From Socket into std::string

I am writing a program in c++ that uses c sockets. I need a function to receive data that I would like to return a string. I know this will not work: std::string Communication::recv(int bytes) { std::string output; if (read(this->sock,…
735Tesla
  • 3,162
  • 4
  • 34
  • 57
11
votes
2 answers

SO_ERROR vs. errno

For getting socket syscall (like recv) error, which is better (at performance level) ? Use the plain old errno Or use SO_ERROR as getsockopt() optname ? I think errno (defined to __error() on my system) is faster because it's not a system call. Am…
Félix Faisant
  • 191
  • 1
  • 1
  • 11
11
votes
2 answers

What does SO_TIMEOUT and CONNECT_TIMEOUT_MILLIS means in Netty's ChannelOption?

What does SO_TIMEOUT and CONNECT_TIMEOUT_MILLIS mean and what is the difference between them? I have found that: many request cost 3.004s and my handler always cost 0.003s or 0.004s and I set the SO_TIMEOUT to 3000 , is there a relationship among…
BabyDuncan
  • 131
  • 1
  • 1
  • 7
11
votes
2 answers

Send byte array in node.js to server

I can't figure out to send byte array while being connected to server on Debian. Is there any alternative to sending string via client.write()? I tried client.write(new Buffer("something")) but this gives Invalid data error. Here is my code: var net…
Daniel Kmak
  • 18,164
  • 7
  • 66
  • 89
11
votes
2 answers

TcpListener vs Socket

Hello i would like to ask what is difference between using this : public TcpListener Listener; public TcpClient Client; Listener = new TcpListener(DeafultPort); Client = default(TcpClient); Listener.Start(); and this : serverSocket = new…
Vacko
  • 163
  • 2
  • 10
11
votes
2 answers

socket.io force disconnect client

I may be doing something wrong here but I can't get my head around this. The following does not work: client $("#disconnectButton").click(function() { socket.emit("disconnect"); }); server socket.on("disconnect", function() { console.log("this…
Tamas
  • 10,953
  • 13
  • 47
  • 77
1 2 3
99
100