How to Create Sockets With MinGW
- 1). Open a text editor or a C and C-derivative editor, such as Microsoft Visual Studio.
- 2). Type the preprocessor directive that tells the compiler in MinGW what other files to include when compiling your code. Type:
#include <stdio.h>
The "Stdio.h" header file that comes in MinGW features many functions you are likely to need for your program, including the print and getchar functions, which are needed in practically any application. - 3). Type another preprocessor directive and specify the file to get as "socket.h," which is the header file in MinGW that features the socket functions. Your code now looks like this:
#include <stdio.h>
#include <socket.h>
Include any other dependency files your new executable needs to run, such as stdlib.h or errno.h. Check through the MinGW documentation that comes with the package to see all of the header files. - 4). Begin the main () function, which the rest of your programming goes inside. Include the open curly bracket that encloses the code:
#include <stdio.h>
#include <socket.h>
int main
{ - 5). Add your source code to add functionality to your socket program and compile it. Define what kind of socket you are making, such as a stream or datagram socket and the structure of aggregate data types.
Source...