1

I'm still in the early stage of learning, and starting to write a simple HTTP application from scratch, however I was unsuccessful so far with the winsock and couldn't make it work.

What is the method to write a HTTP application, is using winsock a correct way to write HTTP application in Windows operating system environment?

I tried to merge includes from the mingw project to make winsock2 work, I really do not like the idea of merging something from fourth party.

I'd like to work directly with the Windows Operating system as intended instead of using some heavyweight precompiled files from such non-native project as mingw.

Initializing WinSock using Tiny C Compiler

By running Initialization of WinSock I'm getting an error

C:\Users\GCC Build\Desktop\Naujas aplankas\tcc>tcc initialize-winsock.c
initialize-winsock.c:6: error: include file 'winsock2.h' not found

initialize-winsock.c

/*
    Initialise Winsock
*/

#include<stdio.h>
#include<winsock2.h>

#pragma comment(lib,"ws2_32.lib") //Winsock Library

int main(int argc , char *argv[])
{
    WSADATA wsa;
    
    printf("\nInitialising Winsock...");
    if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
    {
        printf("Failed. Error Code : %d",WSAGetLastError());
        return 1;
    }
    
    printf("Initialised.");

    return 0;
}
user3789797
  • 450
  • 6
  • 15
  • https://www.binarytides.com/winsock-socket-programming-tutorial/ – OldProgrammer Aug 31 '20 at 15:08
  • The problem with Tiny C Compiler is that it does not come with the winsock2.h header. Although the comment does indeed have quality content to cover the most of the second part of the question in the Main Thread Description. – user3789797 Aug 31 '20 at 15:39
  • you can download the windows sdk and it should have all that. – OldProgrammer Aug 31 '20 at 16:16
  • I did found WinSock2.h and winsock.h in C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um However I have a bad feeling that Tiny C Compiler does not work with them, as hard as I tried to make them involved in the compilation of the initialize-winsock.c. – user3789797 Aug 31 '20 at 16:57
  • It's certainly possible to code an HTTP server or client using the winsock API directly, but you might be shocked at the amount of work it requires to do properly. That's particularly true if you need to handle encryption and/or data compression. I don't know (sorry) what's involved in making TinyC work in this context, but what's wrong with using MinGW? GCC on MinGW produces native WIndows executables with no particular dependencies. – Kevin Boone Aug 31 '20 at 17:05
  • MinGW and GCC have the same problem. They are internally overcomplicated for learning, with horrible explanations or none at all. It's like better to start from the basics all over again, starting with compiler. However I'm still lacking knowledge in C language, so I decided to practice by writing something small and interesting to learn along, like a small HTTP application from a small development environment such as that Tiny C Compiler has. But got stuck with winsock header not being included, as it turns out to be the major library to have anything done, here on Windows. – user3789797 Aug 31 '20 at 17:23
  • 1
    If you are lacking knowledge in C, how could you judge over the usability of MinGW as a compiler? I never had problems to let beginners use it. – the busybee Aug 31 '20 at 18:51
  • Yeah that is a big task to undertake if learning C. Maybe scale back and try something else for now. – OldProgrammer Aug 31 '20 at 18:59

0 Answers0