Jump to content

socket programming

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
kenna

kenna

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
How do I use sockets in Windows? I have tried so hard to find the socket headers required for linux-like sockets (Berkley/POSIX/whatever), but I just can't find them. I AM NOT GOING TO USE VISUAL C OR SIMILAR!

If it doesn't work with TCC or at least GCC, then F**K it! amateur crap!

I am getting quite pissed, for such a simple task to be so difficult T_T

#2
sea

sea

    Newbie

  • Members
  • Pip
  • 7 posts
I recommend you look up Beej's networking tutorials. I don't think you would need the tutorial parts but the examples will show you the headers needed. I'll give you a quick example though:

#ifdef WIN32

#include <ws2tcpip.h>

#include <windows.h>

#include <winsock2.h>

#include <w32api.h>

#define sock_cleanup() WSACleanup();

#endif


int sock_init ( void )

{

#ifdef WIN32

	WORD wVersionRequested;

	WSADATA wsadata;

	wVersionRequested = MAKEWORD(1,1);

	WSAStartup(wVersionRequested,&wsadata);

#endif

	return 1;

}


int main ( int argc, char ** argv )

{

        init_socks();

//Your socket-related code here.

        sock_cleanup();

}




#3
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,719 posts
Sea, I've noticed you've been answering threads that are really old. Please try not to answer anything whose last post is more than a month or so old, as the people involved are probably no longer paying attention. It also pushes down newer threads, with people still involved, in the recent list. Welcome to CodeCall, by the way. :)
sudo rm -rf /