Michael
Michael

Reputation: 133

Server and client on same machine with no loopback

I'm running a server an a client on the same machine(linux). How do I force the packets to go through the network(switch) and not through the loopback?

Thanks,

Michael

Upvotes: 2

Views: 1069

Answers (4)

MSalters
MSalters

Reputation: 179930

Since you're asking this on a programming site, I'll assume you have source code.

When you create the client-side socket, you can limit it to a specific interface. Usually you don't (you just call connect() without bind()ing it first) , and let the OS figure out the best outgoing interface, but this is not mandatory.

Upvotes: 3

gby
gby

Reputation: 15218

You can try setting the SO_BINDTODEVICE socket option on both the client and the server sockets and give it the external NIC interface as parameter.

See: http://codingrelic.geekhold.com/2009/10/code-snippet-sobindtodevice.html for an example

I am not sure this is enough - there might be a sanity check in the kernel IP stack to drop packets whose Ethernet destination and source are both you. There might be a sysctl to disable this check or you can compile your own kernel without the check for this specific test.

Upvotes: 2

David Schwartz
David Schwartz

Reputation: 182789

You can't, unless you have some device out there on a network whose job it is to send the data back to you. Normally, there is nothing that would do that. If you send the data out onto the network, you won't get it back.

If you have set something up to return the data to you, send the data to that, following whatever mechanism it supports.

Upvotes: 0

Septagram
Septagram

Reputation: 9785

Maybe you should try connecting via a proxy server?

Upvotes: 0

Related Questions