/MY PROGRAM ARE COMPILED IN FEDORA15 ..WITH 4.6 gcc compiler...../
/* DIFFRENCE BETWEEN FILE DESCRIPTOR OF FILE & SOCKET.....*/ #include<stdio.h> #include<stdlib.h> #include<string.h> #include<fcntl.h> #include<unistd.h> #include<linux/in.h> #include<sys/socket.h> int main() { int fd; //"struct sockaddr_in { " is defined in in.h with all socket families definations....whose variable will be defined to enter values to elements of that structure elements...so that socket may be connected,listen()...accepted ...binded ..so on.. struct sockaddr_in client_addr; client_addr.sin_family=AF_INET;//family of address client_addr.sin_port=htons(5466);//port no. client_addr.sin_addr.s_addr=inet_addr("127.0.0.1");//ip address of system.. fd=socket(AF_INET,SOCK_STREAM,0);//if we will tell it ..in what way we want to send data from this socket...& what address family we are going to use..for IP address...then while creating socket it will use that data in its socket creating protocol ...use to create socket in that way...according to that information or way in which we want to send the data printf("fd=%d\n",fd);//we had not given name to this client socket ..bcz we did not have need to give name to client socket...bcz/..it is better ..that client socket left secrat ..so that no one could find that socket ...access that socket..get fd of one side of that socket...or read or write data into client's socket........ fd=socket(AF_INET,SOCK_STREAM,0); printf("fd=%d\n",fd);//fd=4 fd=socket(AF_INET,SOCK_STREAM,0); printf("fd=%d\n",fd);//fd=5 close(fd);//if i close(fd) of this socket....then next file will open on same fd.... fd=open("ANU",O_WRONLY); printf("fd=%d\n",fd);//fd=6......so fd of socket will be the lowest available number.. return 0; }