Skip to content

Sending (and then handling messages) to a server

Alex

Asked Jan 15, 2008, 12:13 AM EST2 answers
Share
LinkedInX
Good morning,

Say I have various types of messages to send across the network, but obviously I can only send them as an object. How do I split where the various messages are sent when they get to the server?

I've been going around in circles, and the obvious way (in my head) to handle this is to have some sort of header (using an interface), and then do a switch depending on what's in the header, and cast the object to the specific type.

But something's telling me this is a bad way of doing it, it doesn't feel very OO. any suggestions?

Alex

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Well the simplest method (and most common) is to take your objects (whatever type they may be) then covert them to byte arrays and use the Socket class (and partnering classes) to send them across a socket connection.

    A google search on chat programs using sockets will yield you many results. But, instead of sending byte[] of strings, you are sending you own objects.

    Hope that helps.
    0
  • 0
    Thanks for the reply, as we speak, this is the way I am implementing it, and was the way I had in mind originally, I was just curious as to whether or not there were any other best practices when it comes to this type of data transfer.
    0