Fog Creek Software
Discussion Board

Definition of a "socket" ?

I have used sockets in various languages , but am unsure about what actually happpens when a Scoket class's object is created or it's method is called ( like in the Berkley Socket's API).

I read a definition of a socket as "an end point of communication" if anyone could pls elaborate on that

Joel Moses
Sunday, May 30, 2004


Even though is a Java specific there is good general info about sockets there

Code Monkey
Sunday, May 30, 2004

End-points are like train terminals or airports. People
come in  one terminal and come out at another.
From one perspective you aren't much concerned
what happens inbetween.

End-point means that's where data arrives and is
accessible regardless of the underlying protocol
and network used.  You can logically think of data
just be sent between your socket and the socket
on the other side. That's why they are end-points.
What goes on inbetween can bey very complex
or quite simple, but that has been abstracted away.

son of parnas
Sunday, May 30, 2004

google, "define:socket"

Sunday, May 30, 2004

Well they have different implementations and quirks on different platforms but you might want to look at the POSIX standards for sockets...?

Essentially they're kinda just a filesystem-like abstraction of an underlying network protocol... allowing you to communicate across a network as though you were reading/writing data to/from a file (with some important differences but hey).

There's not really a lot to 'get', sound like you already know what they are and what they do if you've used the APIs. If you're interested in how the underlying socket implementations work read up on TCP/IP and stuff...

Sunday, May 30, 2004

Hello to you Joel.

I have learnt of sockets back at my school in Japan.

It is all very simple ,maybe? A socket is really a just story to make it easy for you to be understanding the Internet. Each of the computers wanting to talk to each other are having sockets. Pretend they like the ones in your wall and at the end of the wire coming from your light. You having connect the to buy sticking the plug into the hole in he wall ,so you can turn the light on ,maybe? So you can be having the functions like this:


But it just a story ,just pretend. Sockets are being simple file descriptors in UNIX. The rest is not needing of youre concern. Just pretend and do the file manipulations like you alwas do and check for errors and donnot worry.

Junichiro Kawaguchi
Sunday, May 30, 2004

>A socket is really a just story

Thank you Junichiro. That is it. A socket is a number. When you have created it, you can associate it with a port, which is another number that identifies IP sources and destinations.

Once the socket is associated with a port, you can send or recieve data.

The socket itself is an abstraction, the same way that the number you get back from a regular Unix open() call is an abstraction.

anon married man
Sunday, May 30, 2004

Anon you said "a socket is a number" . Care to elaborate ??

Joel Moses
Monday, May 31, 2004

A socket is a number just like a file handle.

If a packet hits a pocket on a socket on a port,
And the bus is interrupted as a very last resort,
And the address of the memory makes your floppy disk abort,
Then the socket packet pocket has an error to report!

If your cursor finds a menu item followed by a dash,
And the double-clicking icon puts your window in the trash,
And your data is corrupted 'cause the index doesn't hash,
Then your situation's hopeless, and your system's gonna crash!

If the label on the cable on the table at your house,
Says the network is connected to the button on your mouse,
But your packets want to tunnel on another protocol,
That's repeatedly rejected by the printer down the hall,

And your screen is all distorted by the side effects of gauss
So your icons in the window are as wavy as a souse,
Then you may as well reboot and go out with a bang,
'Cause as sure as I'm a poet, the sucker's gonna hang!

When the copy of your floppy's getting sloppy on the disk,
And the microcode instructions cause unnecessary risc,
Then you have to flash your memory and you'll want to RAM your ROM.
Quickly turn off the computer and be sure to tell your mom!

Monday, May 31, 2004

Give credit:

Monday, May 31, 2004

In order to make a TCP-IP connection to a machine, you need the IP address of that machine, and an integer 'Port' address on that machine.

The machine you are trying to connect to must have opened that 'Port' address, and be 'listening' on it. 

Once these things have happened, you can 'connect' to that thing (the IP Address and Port Address being held open on the foreign machine) from your local machine.

Once connected, that entity is called a 'socket'.  It locally looks like a file.  You can use the write() call with it.  You can use the read() call with it.  Really, it is a structure on your local machine which 'wraps' all the underlying complexity of the TCP-IP communication stack.  When you 'write()' to it, the data written is transferred over TCP-IP to the 'foreign' machine's TCP-IP code.

All these other analogies and stories add up to 'leaky abstractions', as Joel puts it.  Really, it is a small set (5? 6?) of library calls to manage these connections and make them look exactly like file accesses.

Monday, May 31, 2004

Junichiro Kawaguchi what do you do for a living? Just curious :D

Li-fan Chen
Monday, May 31, 2004

*  Recent Topics

*  Fog Creek Home