4

Is it possible to use sockets on Win32 and not have the firewall possibly block the port you are using?

In Unix, you can use IF_UNIX instead of IF_INET (i.e. named pipes instead of sockets). Right now in Windows you can open a socket using different protocols:

socket(AF_INET,    SOCK_RAW, IPPROTO_TCP);     //open an IPv4 socket
socket(AF_BTH,     SOCK_RAW, BTHPROTO_RFCOMM); //open a Bluetooth socket
socket(AF_NETBIOS, SOCK_RAW, IPPROTO_TCP);     //open an IPX/SPX socket
socket(AF_INET6,   SOCK_RAW, IPPROTO_TCP);     //open an IPv6 socket

Is there any way to open a named pipe socket? E.g. (hypothetical construct)

socket(AF_NAMEDPIPE, SOCK_RAW, IPPROTO_TCP);   //open a named pipe socket
4
  • 2
    Without getting into a holy war, what drives you to conclude that named pipes on win32 are <b>so</b> unreliable? I've been using the WCF NetNamedPipeBinding on Windows without any trouble at all.
    – Matt Davis
    Commented Sep 28, 2009 at 17:17
  • @Matt have you been capturing stats across a global distribution of clients? I have seen a failure rate near 1% failure, but only from stats, not reproducible in > 10 test machines ... trying to form an idea if it's poor code quality in a system or those things are really unreliable (I just drove a reduction of more than 10 times the error rate in a specific action by taking out an unnecessary use of pipes).
    – eglasius
    Commented Aug 21, 2012 at 16:43
  • @eglasius, no. I do not use pipes for communication across a network. My use of NetNamedPipeBinding is isolated to the local box, and that works reliably. I still use traditional sockets for crossing machine boundaries.
    – Matt Davis
    Commented Aug 21, 2012 at 17:56
  • Sorry, I badly phrased it, what I mean are deployments on lots of PCs out there where the pipe is used only locally in those PCs. So same scenario, local use / but instead of a controlled environment, the one users out there have.
    – eglasius
    Commented Aug 22, 2012 at 9:13

3 Answers 3

5

As John Cavan (who I think I once went to school with) says, using the loopback address should avoid the NIC and firewall altogether, and also gives you the ability of changing to a full client-server model (i.e. separate machines, possibly on different platforms) later on with minimal code changes.

I have also used shared memory successfully for same-machine communications. This is generally faster that TCP/IP and named pipes. However, I have found named pipes on Win32 to be reliable and relatively fast.

2
  • I'm interested in the named pipes reliability comment, can you share more? / please see the comment I just posted in the question.
    – eglasius
    Commented Aug 21, 2012 at 16:47
  • Another virtue of TCP/IP and Named Pipes, is synchronizing access to the shared memory, and indicating that data is ready.
    – Ian Boyd
    Commented Feb 22, 2013 at 21:57
3

I haven't tried this, but I'd suggest that if you bind to the loopback address then you should be clear of the firewall. You'd probably want to do that anyways if you're looking for an alternative to named pipes since it should be faster than actually communicating over the NIC.

Have you looked at other alternatives such as shared memory? Nevertheless, the advantage of switching to sockets is that you could, later on, put the two processes on seperate machines and still communicate without code change (assuming you avoid the mistake of hardcoding the IP address).

-1

There's an address, something like one ninety two one sixty eight dot var dot var that I brought up with Java, using a randomly selected port in the private use range and win let's it run with no complaint.

Not the answer you're looking for? Browse other questions tagged or ask your own question.