tags:

views:

440

answers:

4

Hi,

I have a 'C# server' program listening to '127.0.0.1', port 5500, using .NET socket, and i have a corresponding C# client program sending messages to this socket from the same PC. They both work fine.

Now if i run the 'client' and 'server' programs on seperate PC's and connect them via a cable connecting their serial ports (RS232), should i make changes to code to make them work ? I am asking since i dont have 2 PC's to check , but need it to work when deployed.

Thanks.

+6  A: 

Well, if both computers have appropriate drivers to treat the serial port as a network connection, it should work without any changes.

Otherwise, you'll have to use the SerialPort class. to explicitly talk over the serial port.

You may find it best to abstract your code so that it works over streams - then you can get the stream from a network connection or a serial connection, and most of your code won't need to change.

Jon Skeet
+1 for stream abstraction.
Cogsy
A: 

You're in for a lot of pain if you continue down this path :-)

TCP/IP generally works over ethernet - I've never seen a driver that would run the physical layer on RS232 serial ports although it's by no means impossible.

You'd be better off connecting those two machines using a standard network cable.

paxdiablo
+1  A: 

If the server is bound to 127.0.0.1 then yes, you need to set it to 0.0.0.0

The reason is that if a socket is bound to an IP address, it will only accept requests on that IP address. 127.0.0.1 is only used as a machines IP address if the originator is on the same machine (it's a separate network interface, set up as a loopback). 0.0.0.0 means 'any IP address', so you can open a socket that will accept incoming connections from any network interface on the machine.

As for running it over a serial cable... no idea if that will work or not, and most likely requires a lot of setup to do.

workmad3
A: 

TCP/IP also works over SLIP. Remember that old way you used to connect to the internet? PPP would work as well. But I don't think that that's what he's looking for.

Mike
TCP/IP with Stream abstraction , as Jon Skeet said is what i am working with now. Am testing - OK so far.
Chakra