Using sys/socket.h functions on windows

You have two options: Use Cygwin (Unix emulation library). Port to Winsock (Windows standard library). Cygwin: lets you compile your Unix sources mostly untouched, but ties you to the Cygwin emulation library. This have two implications: general performance -no only network- will probably be less than optimal; and the target environment must have (at run … Read more

Reasoning behind C sockets sockaddr and sockaddr_storage

I’m looking at functions such as connect() and bind() in C sockets and notice that they take a pointer to a sockaddr struct. I’ve been reading and to make your application AF-Independent, it is useful to use the sockaddr_storage struct pointer and cast it to a sockaddr pointer because of all the extra space it … Read more

Python Socket Multiple Clients

So I am working on an iPhone app that requires a socket to handle multiple clients for online gaming. I have tried Twisted, and with much effort, I have failed to get a bunch of info to be sent at once, which is why I am now going to attempt socket. My question is, using … Read more

Handling a timeout error in python sockets

adds all the names without leading underscores (or only the names defined in the modules __all__ attribute) in foo into your current module. In the above code with from socket import * you just want to catch timeout as you’ve pulled timeout into your current namespace. from socket import * pulls in the definitions of everything inside of socket but doesn’t add socket itself. Many people consider import * problematic and try … Read more

Getting the IP address of the current machine using Java

This way works well when there are multiple network interfaces. It always returns the preferred outbound IP. The destination 8.8.8.8 is not needed to be reachable. Connect on a UDP socket has the following effect: it sets the destination for Send/Recv, discards all packets from other addresses, and – which is what we use – transfers the socket … Read more