What header files and libraries do you include for socket programming?

Answer:

Below is the header files and pakage mentioned with respect to language/platform.

Java:

	import java.net.*; //pakage.

C#

	using System.Net;
	using System.Net.Sockets;
	using System.Net.NetworkInformation;

C/C++ Windows

       #include <winsock2.h>
       #include <ws2tcpip.h> 

	Need to link with Ws2_32.lib
	#pragma comment (lib, "Ws2_32.lib")

WinCE

       #include <winsock2.h>
       #include <ws2tcpip.h>

	Need to link with Ws2.lib
	#pragma comment(lib,"ws2.lib")

C/C++ Linux

        #include <sys/socket.h>	// for socket(), bind(), listen(), accept()
	#include <netinet/in.h>	// for PF_INET, SOCK_STREAM, IPPROTO_TCP 
	#include 	// for read(), write(), close()

Note: This Question & answers sound simple but in interview many people forget it. Generally, it is asked to fresher but it is also asked to experience people too.

Related Posts