- Socket is End to End Point Communication.
- Establishing a Connection Between two Applications or processes or threads.
- Creating interface between two programs ( Server and Client Programs ).
Socket System consist of client system as well as server system
Client System acts as a Receiver . In this system Requests to Server, and receive information from Server.
Server system acts as a provider of information. It acts as an Administrator, to control over Network Systems ( Clients ). Provide information depending on Client request and responds to the client request.Socket programming, requires you to create two applications
1) One is Server applications.
2) Second one is client applications ( number of clients )
Server application should be capable of handling more than one client if you have a requirement where number of clients will be connecting.
The below table illustrates server and client related socket functions
» To Initialize a SocketBind
» To attach an InterfaceListen
» Listen for Incoming ConnectionAccept
» Permits an Incoming ConnectionConnect
» Establish a Connection on a Specified socketSend
» Send data on Connected SocketOnly two types of Specifications supported for Windows
It provides sequenced, reliable connection oriented byte stream. It uses TCP [ Transmission control protocol ] to transmit data to the connected system in sequenced manner. It also waits for acknowledgement.
It provides unreliable connection less service. It uses UDP [ User datagram protocol ] transport layer protocol and its not required to connect the network systems.
UDP and TCP use the IP address and the port number to uniquely identify a particular process on a networked host.
Windows API supports networking capabilities (WNet Functions). WNet functions to add an cancel network connections and to retrieve information about the current configuration of the network. The WNet functions enable your application to query and control network connections directly, or to give direct control of the network connections to the user.
To enumerates network resource perform the following steps :
1. Pass the address of a NETRESOURCE structure that represents the resource to the WNetOpenEnum function.
2. Allocate a buffer large enough to hold the array of NETRESOURCE structures that the WNetEnumResource function returns, plus the strings to which their members point.
3. Pass the resource handle returned by WNetOpenEnum to the WNetEnumResource function.
4. Close the resource handle when it is no longer needed by calling the WNetCloseEnum function.
See the following Code :
AfxMessageBox("Network connection successful",MB_OK);
AfxMessageBox("Failure in opening connection",MB_OK);
LPNETRESOURCE lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer);
» Initiates use of Ws2_32.lib by a processgethostname
» Print the host name for the local machinegethostbyname
» gethostbyname function retrieves host information corresponding to a host name from a host database.Code for finding out Host Name and Ip Address using Windows Socket
void MyFrame::MySocket(WSADATA w)
char m="Host Name: ";
char s="Host Address :";