Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding socket basics

I've been reading up on basic network programming, but am having a difficult time finding a straight-forward explanation for what exactly and socket is, and how it relates to either the OSI or TCP/IP stack.

  1. Can someone explain to me what a socket is? Is it a programmer- or API-defined data structure, or is it a hardware device on a network card?

  2. What layers of the mentioned network models deal with "raw" sockets? Transport layer? Network layer?

  3. In terms of the data they pass between them, are socket text-based or binary?

  4. Is there an alternative to sockets-based network programming? Or do all networked applications use some form of socket?

If I can get this much I should have a pretty clear understanding of everything else I'm reading. Thanks for any help!

like image 329
Eugie Avatar asked Jan 24 '11 12:01

Eugie


People also ask

What are the basic operations of sockets?

Basic socket operations: sending and receiving data, and closing the network connection. A socket opens a network connection, so that data can be requested by the XBee Cellular Modem. The request is sent to the specified destination, and then received by the module.

What is socket and how it works?

Sockets are commonly used for client and server interaction. Typical system configuration places the server on one machine, with the clients on other machines. The clients connect to the server, exchange information, and then disconnect. A socket has a typical flow of events.


1 Answers

Short answers:

  1. Socket is an abstraction of an IP connection endpoint - so if you think of it as an API structure, you are not very far off. Please do read http://en.wikipedia.org/wiki/Internet_socket
  2. Internet layer i.e. IP Protocol. In practice you usually use explicitly sockets that bind to a certain transport layer parameters (datagram/UDP or stream/TCP)
  3. Sockets send data, in network byte order - whether it is text or binary, depends on the upper layer protocol.
  4. Theoretically, probably yes - but in practice all IP traffic is done using 'sockets'
like image 178
Kimvais Avatar answered Sep 23 '22 04:09

Kimvais