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

Error Domain=NSPOSIXErrorDomain Code=61 "The operation couldn\u2019t be completed. Connection refused"

I am using asyncSocket as client side, aim running my application on iPhone simulator, and the server side coded with C#. its working perfectly if i try to connect with a server on my LAN but the connection refused with the server out of my…
Mohammad Shraim
  • 1,173
  • 12
  • 21
11
votes
5 answers

c++ linux accept() blocking after socket closed

I have a thread that listens for new connections new_fd = accept(Listen_fd, (struct sockaddr *) & their_addr, &sin_size); and another thread that closes Listen_fd when when it's time to close the program. After Listen_fd is closed however, it…
BrandonToner
  • 111
  • 1
  • 1
  • 3
11
votes
5 answers

How can I set a timeout against a BufferedReader based upon a URLConnection in Java?

I want to read the contents of a URL but don't want to "hang" if the URL is unresponsive. I've created a BufferedReader using the URL... URL theURL = new URL(url); URLConnection urlConn =…
dacracot
  • 22,002
  • 26
  • 104
  • 152
11
votes
4 answers

Sending emails using C

I have just started learning about socket programming and learned about winsock and achieved some progress. my question is basically: I want to send emails, what should I do? points to be mentioned: I learned about initializing winsock. SMTP port…
joker
  • 3,416
  • 2
  • 34
  • 37
11
votes
1 answer

lua socket client

I am trying to make a simple lua socket client for the Socket Server example, from the Lua Socket page. The server part works though, I tried it with telnet. But the client part isn't working. local host, port = "127.0.0.1", 100 local socket =…
user1058431
  • 185
  • 1
  • 3
  • 12
11
votes
2 answers

Send image using socket programming Python

I am trying to send an image file using socket programming in python. I am able to send a text file. But I have been trying to send an image file, by opening it and reading the contents of the image file in a string and then sending the string and…
mihirk
  • 299
  • 1
  • 5
  • 10
11
votes
2 answers

How can I send anything other than strings through Python sock.send()

I'm very very new to programming in Python, but out of necessity I had to hack something together very quick. I am trying to send some data over UDP, and I have everything working except for the fact that when I do socket.send(), I have to enter the…
Adam
  • 289
  • 2
  • 3
  • 7
11
votes
6 answers

Question about server socket programming model

Over the last couple of months I've been working on some implementations of sockets servers in C++ and Java. I wrote a small server in Java that would handle & process input from a flash application hosted on a website and I managed to successfully…
Charles
  • 2,615
  • 3
  • 29
  • 35
11
votes
3 answers

How to mock an outgoing Socket connection?

In integration tests (JDK 6) I'm trying to catch all outgoing TCP connections and mock them. Looks like I should use java.net.Socket#setSocketImplFactory() method. Works fine at the moment, but I can't understand how I can get an access to original…
yegor256
  • 102,010
  • 123
  • 446
  • 597
11
votes
1 answer

ObjectInputStream(socket.getInputStream()); does not work

I'm programming a class to communicate to a server but when it tries to construct the ObjectInputStream with the help of the inputstream the program is freezing. Theres is no Exception and the program is still running but hanging in the line where…
Big_Foot1989
  • 311
  • 1
  • 3
  • 11
11
votes
1 answer

Why does my service always bind to ipv6 localhost instead of ipv4?

I have a service that creates a ServerSocket and binds to localhost:7060. When I did "netstat -an" on my android device, I see it is using ipV6 localhost instead of ipv4 localhost interface. The output is like this: tcp6 0 0…
videoguy
  • 1,732
  • 2
  • 24
  • 49
11
votes
1 answer

Keeping the WebSocket connection alive

I'm doing a study on WebSocket protocol and trying to implement a simple ECHO service for now with Python on the backend. It seems to work fine but the connection drops right after being established. Here is my client:
Dreen
  • 6,976
  • 11
  • 47
  • 69
11
votes
2 answers

Non-blocking client and server sockets in C

I started to read and learn about "sockets", but I'm looking for a small code-sample written in C for a client and server which will be non-blocking The code should be able to send input from the client and the server must be able to receive the…
user1022734
  • 297
  • 2
  • 4
  • 11
11
votes
7 answers

Is it possible to connect a socket between two mobile devices (iPhones) over the internet?

Is it possible to connect a socket between two mobile devices (iPhones) over the internet? I am trying to discover the IP of each device and connect directly. I know it can be done with Bonjour but that only works on local networks. I need a high…
Jamey McElveen
  • 18,135
  • 25
  • 89
  • 129
11
votes
2 answers

Track a packet as it goes through the kernel (linux)

I have two machines which are set up to use Ip-Security and machine A (lets call them A and B) has a socket which is bound to a particular UDP port on the local machine and it polls it frequently to see if anything is received on it. When I disable…
mmtauqir
  • 8,499
  • 9
  • 34
  • 42