开发者

Internet communication between programs, without worry in C#?

I want to provide a direct connection between two instances of my program, which are located on two different computers.开发者_运维知识库

I already have the means to obtain the IP addresses, but how do I make a connection between my programs and have no trouble with the firewall or ports?

I need to send serialized objects through the connection.

Edit2: The specific term is peer-to-peer connection.

Edit: I see I need to explain the "no trouble" part.

First, when a program attempts to communicate to the internet, the annoying Windows Firewall permission dialog opens.

On Windows 7, you have two checkboxes:

1. Allow on private (home/work) networks, which is checked by default and, sometimes, cannot be unchecked.

2. Allow on public networks, which is either checked or unchecked by default...

NO ONE I know makes sure that all the check boxes are checked. NO ONE.

This can interrupt the program sometimes in bad ways, without people knowing!

Next... Most people are behind a router and routers usually block all the requests to undefined ports, unless the rules are changed.

Nobody will accept to add these rules just to use a program. Nobody.


You can use WCF for this purpose.

It doesn't solve 'all' network problems though, but I doubt any technology would.


It kind of sounds like you're looking for a way to bypass firewalls so that your users won't have to deal with that kind of stuff while using your program.

If that's indeed the case, think about it this way. Would the Windows Firewall be good at its job if it allowed you (or anyone else) to do that?

What you might want to do is open up a port using TCP and send serialized objects over it to a target listener, which knows how to decode those bits back to objects.

If you need that port open, your users will have to allow that. If they're running a firewall that blocks it, then that firewall needs to be properly configured to allow your program to interact with the target computer.

You can use TcpClient, TcpListener (System.Net) and BinaryFormatter (System.Runtime.Serialization) to send serialized objects over TCP. Remember you need to specify your custom classes as [Serializable].


So, using a TcpClient and a TcpListener works... as long as I forward the ports on the listener's router.
So this is not an option.

I ended up using my database to queue commands and check for them every once in a while, and dequeue them when necessary.

For the moment, I cannot find any good answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜