efeemir103 / project-code-unleashed

Just a repo to code with team.
GNU General Public License v3.0
0 stars 0 forks source link

About cross-platform networking. #3

Closed Nycrera closed 2 years ago

Nycrera commented 5 years ago

So, yes. I can't seem to find any possible cross-platform library's in C such that we can easily listen to a port and send simple TCP or UDP packets.

This problem happens because, Unix uses <sys/socket.h> while Windows uses for sockets. There a couple of solutions to this tho.

Possible Solution 1

https://stackoverflow.com/a/4642169/10768104

Compile both for Unix and Windows independently

`#ifdef WIN32

include

else

include <sys/socket.h>

endif `

Even if this seems quite easy. There is also some other differences and problems with winsock2.h (Checkout the StackOverflow question.) Yet this can be a solution still.

Possible Solution 2

Use Cygwin as compiler. Cygwin has the headers such that <sys/socket.h> and other Unix headers that don't simply exist in Windows. As long as we don't use fork() which is really buggy as I heard of it. fork() could have been used for some async jobs that are actually quite important so I don't know if this is the right answer to this problem.

Possible Solution 3

No Cross-platform for us. :(

efeemir103 commented 5 years ago

Solution 1 is the conventional one so we will go with it.