| FlazX | Categories | Forum | Links | Blog | Login |
|
Socket Basicsby basileisSocket BasicsWhat is a socket?Socket is a piece of code which we wrote to enable communication between two separate entities (here it means computers) or within the entity itself. For e.g., like we use telephone and dial telephone number of the person whom we wish to talk, in this process we create a end point of communication between two telephones same principle is applied in sockets. Identifying a socketEach socket have address of their own (except nameless socket) to identify specifically. On a broader view there are three types of sockets:
Local Sockets or Nameless SocketsThese types of sockets do not have address because they connect within the machine itself also known as UNIX domain sockets. The function socketpair() is used to create such types of sockets. Local domain sockets uses AF_LOCAL prefix here AF stands for Address Family. Internet Domain SocketsInternet domain sockets are used when we want to establish communication between process running on two different computers. Internet domain sockets Local socket address structureThis type of address format is used by the sockets
The sun_family variable must have the AF_LOCAL or AF_UNIX assigned to it.There is no null byte required at the end of character array. Internet Domain (IPv4) address structureThe socket address sockaddr_in is used in Internet domain structures, it is defined in
sin_family should be initialized to PF_INET, sin_port represents the TCP/IP port number for the socket address ( this value should be in network byte order ), sin_addr represents the internet protocol (IP) Creating nameless socketFor creating a socket we should do
Arguments used in the socketpair() function are:
This function returns 0 on success and -1 otherwise. Performing Input Output operations on socket.Read and write operation on a socket can be done just like an open file. We do
read returns the input that is available from the file descriptor fd,into the supplied buffer buf of a maximum size of count bytes.The return value represents the number of bytes read. A return count of zero represents the end-of-file. Write writes the data to the file descriptor fd, into the supplied buffer buf for a total amount of count bytes.The return value represents the actual number of bytes written. If the return value of any of the above function is -1 that means some error has occurred and the reason for error is defined in external variable errno to use this variable we need to include Closing socketSockets are closed in the same manner like we close the file. In sockets the other end will receive an end-of-file indication when the other endpoint (socket) has been closed. The problem occurs when the local socket is closed from one end and acknowledgement is expected from remote end but since the local socket is closed so it cannot receive the acknowledgement to solve this problem we use the half closing of socket using the function
sock_desc specifies the socket descriptor which is to be shutdown. Int method describes how the socket is to be shutdown, possible values for this argument are:
Possible errors returned by shutdown () function
Little endian (Host byte ordering) and Big endian (Network byte order)There are two types of conversions used, these are:
By Host order we mean the byte ordering that the CPU uses |
Top 100 Search Keywords Last 100 Search Keywords Nokia Themes Free Download Daily Internet Guide EgyDown Share4All FreeBookCity.Com Providings.com DownArchive Allulook4.com eu-warez.net |