I am tr开发者_开发问答ying to connect two of the same app with winsock, but the connecting side has to use ConnectEx() which requires a bound socket. So the problem is that when I try to loop back using ip 127.0.0.1, I get error 10048(WSAEADDRINUSE).
Is there any way around this problem?
Thanks for any help
Although ConnectEx()
requires a bound socket you don't need to select a port and explicitly bind it you can bind to a wildcard address simply leave the port as 0 and the OS will select one for you as it normally does with outbound connections.
Make sure your two app instances are configured up to use different ports.
- Instance 1 listens on port X, connects to port Y
- Instance 2 listens on port Y, connects to port X
精彩评论