8

I realize this question is similar to some others, but I figured my situation is sufficiently different to warrant its own question (hopefully).

What I'm planning on is deploying a program on another person's computer which will open a connection to my computer after which, I'm assuming, the computers should be able to communicate with each other. Once the program starts, it should be able to pull the address information and port (if they aren't blocked) to create a connection, right?

What's more is the internet configuration of the dorm I'm living in. Every room is assigned a unique port and a static IP address assigned by a DHCP server. How do I factor this into the design of my program?

I'm thinking that this setup does not require a server as an intermediate access point, as my address details will always remain the same and the host computer can simply connect to my computer without further information. Is this correct?

Finally, I am reading a few pages about creating a connection, but am confused with all the possibilities of TcpConnection, WCF, CORBA, etc. Which one would actually be the simplest one for me to start with assuming I only want to send messages to the other machine?

Update:

The address is static in the sense that it doesn't change. My IP address is of the form 130.83.20.xxx and I can either wait for the DHCP server to assign me this address, or I can manually enter it myself using a static IP configuration.

As for the messages itself, simple text messages will suffice for the start. The ports mentioned before are the switch ports and do not come into play during network programming I believe.

Community
  • 1
  • 1
IAE
  • 2,213
  • 13
  • 37
  • 71
  • To guide you, we'll need to know more about your objective. Depending on the nature of the data you need to send, TcpConnection might be good, but then maybe a simple WCF service would be better. I don't understand what you mean when you say each room is assigned a port and static ip... do you mean physical port, if so, that does not come into play during network programming. TCP/UDP Ports however, are important. You'll need to what ports are available for your use. – Nate Aug 18 '11 at 15:41
  • @Nate: Thanks for the heads up. For right now, I just want to test this program on a friend's computer and I think simple text messages such as, "Hello, how are you?" should be fine. Well, for example my IP address is 130.83.20.103 or something like that. It does not change. The DHCP server assigns me this address or I can manually enter it. Each room has a port that can be blocked by the central IT administration. These are the switch ports I believe. – IAE Aug 18 '11 at 15:46
  • If the DHCP server can assign you an IP address of `130.83.20.103` then you shouln't manually configure yourself to have that IP address. If you did and the DHCP server assigns that address to someone else then you would end up with an IP address conflict, and effectively a denial of service attack against the poor sucker who got given that IP address by the DHCP server. – Justin Aug 18 '11 at 16:00
  • @Kragen: The network here is designed so that each room, or rather computer in a room, has a unique IP address. It will not be assigned to another room. – IAE Aug 18 '11 at 16:04

1 Answers1

7

I would go with TcpClient and TcpListener. Check out the example code on MSDN, copy and paste it into two C# console projects and build them.

I would use 127.0.0.1 (localhost) for testing purposes on port 5001 (a commonly used test port).

TcpListener server = new TcpListener(IPAddress.Parse("127.0.0.1"), 5001); 

Then you should be able to test a simple client/server that runs on your computer only. Once you get that working, you can take the client to another computer in your dorm and make sure it still works. Once that works, you can go to a local coffee shop and take the client with you. Leave the server running at a known IP address in your dorm. In this case, have the server bind to your actual external IP (not localhost). You can do this by just specifying a port to the TcpListener constructor: `

TcpListener server = new TcpListener(5001);

Once you get all that working by yourself or with a friend, then send it external. Better to get these things working in a demo before sending it to your customer and having him troubleshoot with you. :)

Reasoning behind my answer:

Simple TCP client/server is very straightforward and will allow a simple chat program between two computers. Then you can beef it up to send any data stream you want. You can add code like this to get access to a StreamWriter:

NetworkStream stream = client.GetStream( );
StreamWriter writer = new StreamWriter(stream);
mattypiper
  • 1,222
  • 8
  • 8
  • 2
    Is there any Limit to transfer large files? – whihathac Jan 02 '12 at 17:29
  • 1
    Not really. You just implement Upload/Download methods in your server and client classes and in those methods you will stream blocks of data to a file. So you don't send all the data at once. Just send 1K at a time or so. You can get yourself into protocol design at this point if you want to implement acknowledgements, data integrity validation, etc. But at a basic level you just read from a network stream and write to a file stream, and vice-versa on the other side. No limit (other than maybe the file stream's limit, such as a FAT32 file system's 4GB file size limit). – mattypiper Jan 10 '12 at 18:04