Using sys/socket.h functions on windows

前端 未结 3 1835
余生分开走
余生分开走 2020-12-01 09:33

I\'m attempting to utilize the socket.h functions within Windows. Essentially, I\'m currently looking at the sample code at https://beej.us/guide/bgnet/html/multi/clientserv

3条回答
  •  攒了一身酷
    2020-12-01 10:08

    Writing cross platform network applications is not easy with what the BSD standard provides you. Sure it will work but you'll have to make some replacements like replacing ioctl (if needed) with ioctlsocket (on windows). More differences here.

    My advice is to use a library that hides these ugly differences and provides a unified way of communicating. I personally use ACE. You have plenty of examples that show you how to create a server and a client. Copy from the samples and see how they do it there. Their mailing lists are of great help also (don't forget to use the PRF - see the source tree for the Problem-Report-Form). You can borrow the books for more information. Important note: by using ace you can use ACE wrapper functions like socket, setsockopt, ioctl etc. without worry that they will not work. Unfortunately this adds a library dependency which is not always an option. But ACE has more powerfull features which I'm sure you'll like once you discover them. Hints: Reactor, Proactor.

提交回复
热议问题