Advertisement

sending data & text

Started by April 20, 2002 07:26 PM
1 comment, last by element2001 22 years, 9 months ago
I''m making a small turn based online game with chat and trying to decide how to send the data info along with text. Right now I''ve got the text sending and recieving fine using TCP/IP, now I need to send the data also. So I was thinking I could send the data embedded in the text with a little ''this is data'' code preceding it, and parse it out of the text on the other end, or I could send all the data seperately on a different port I gather. So which is the best method to combine data and text?
you could do it that way, but a more elegant (and object orientated way) would be like this:

first make a MyPacket object which has an identifier varible, then subclass this into two different objects: textPacket, and dataPacket.

the textPacket object will hold all the ''chat'' text you want to send (what you''re sending now), while the dataPacket will hold the data you want to send.

When you send the stuff over the network, simply make an instance of the required class (either textPacket, or dataPacket), and put in the stuff you want to send over the network. When you receive data over the network, cast it as a MyPacket object, have a look at the identifier variable (this says whether it''s data or text), then cast it as the relevent object (textPacket or dataPacket). You can then grab the stuff that was send, and do things with it.

This is nice, since you can add functions in the subclasses to put in the data/text/pictures/etc more easily (as well as retrieval)
All done with Cash:www.venini.co.uk/arthursdeparture/
Advertisement
Thanks deanolium, that is a much more elegant way to do it. I'll give it a shot.

[edited by - element2001 on April 20, 2002 9:00:25 PM]

This topic is closed to new replies.

Advertisement