Writings Photos Code Contact Resume
Don't fear the socket: 1, The socket.

You are here

Submitted by msameer on Thu, 16/02/2006 - 1:27pm


This is the first of a network programming tutorials.

I hate such theoretical boring things, So I'll just copy and paste whatever I think'd be useful.

What is a socket ? A socket is an end point for communications, A socket is the corner stone of networking. You can consider it as a method of communication between two processes, Those two processes can be either running on the same computer on two different computers.
A socket is also an identifier that the application can use to identify that end point.

Each socket must have a type, The type defines the communication semantics, IT can be:

  • SOCK_STREAM: full duplex reliable connection, It insures that data is not lost or duplicated, TCP connections are SOCK_STREAM type.
  • SOCK_DGRAM: Used to send datagrams, Unreliable messages and it's connection-less, UDP is of SOCK_DGRAM type.

We have more types but you can RTFM to know more, I don't really care about them now.

Each socket must also have a protocol, It can be:

  • PF_LOCAL: Local interprocess communication, Also called PF_UNIX. It's used as a method of communication between processes on the same machine. The connection is represented by a file that exists in your file system.
  • PF_INET: Used to communicate between processes running on different computers.\ using the Internet Protocol "IP protocol", It can also be used with processes on the same machines, Especially for crappy operating systems like the Microsoft DOS extension called windows because they don't have PF_LOCAL.

Also probably more but that's what I'm going to list.

You can use the sockets to mainly create 2 things:

  • A server, Creates a socket, Binds it to a local address, Listens for incoming connections and accepts or rejects them.
  • A client, Creates a socket, Connects to a server.

Add new comment

Subscribe to /  digg  bookmark