Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Socket programming - how to identify accepted data?

Reply
 
Old 02-02-2009   #1 (permalink)
Zalabado


 
 

Socket programming - how to identify accepted data?

Hi!

I am a newby in socket programming (C#) and after a lot of googling I
succeeded in connecting and sending (asynchronous) a data over socket
between a server and client :-)
However, I would like to accept data via socket (e.g. from client) but for a
few different purposes (e.g. textmessage, login, password) and therefore i
would like to know what am i accepting (id, textmessage, login, password)...

Well, the question is: How to identify what kind of data am I accepting (id,
textmessage, login, password)?



My System SpecsSystem Spec
Old 02-02-2009   #2 (permalink)
Alberto Poblacion


 
 

Re: Socket programming - how to identify accepted data?

"Zalabado" <zala@xxxxxx> wrote in message
news:gm6k7d$jov$1@xxxxxx
Quote:

> I am a newby in socket programming (C#) and after a lot of googling I
> succeeded in connecting and sending (asynchronous) a data over socket
> between a server and client :-)
> However, I would like to accept data via socket (e.g. from client) but for
> a few different purposes (e.g. textmessage, login, password) and therefore
> i would like to know what am i accepting (id, textmessage, login,
> password)...
>
> Well, the question is: How to identify what kind of data am I accepting
> (id, textmessage, login, password)?
The socket will merely deliver a stream of bytes. It is up to you to
define your own convention as to how you are encoding information in those
bytes. For instance, you may decide that the first byte represents the type
of data (1=textmessage, 2=login, etc), then the next two bytes are an
integer representing the length of data, and then the next 'n' bytes (as
encoded in the preceding variable) are the content of the message itself. As
a sanity check, you may append a final byte or bytes with a 'magic value'
(or a checksum) to verify that your encoding and decoding have worked
properly. All of this can, of course, be modified as needed depending on the
information that you are transmitting. It may be useful to apply one of the
Serialization mechanisms provided with the Framework to encode the various
types of objects that you are transmitting.


My System SpecsSystem Spec
Old 02-02-2009   #3 (permalink)
Zalabado


 
 

Re: Socket programming - how to identify accepted data?


"Alberto Poblacion" <earthling-quitaestoparacontestar@xxxxxx> wrote
in message news:eW9iDuShJHA.4880@xxxxxx
Quote:

> cut
>
> The socket will merely deliver a stream of bytes. It is up to you to
> define your own convention as to how you are encoding information in those
> bytes. For instance, you may decide that the first byte represents the
> type of data (1=textmessage, 2=login, etc), then the next two bytes are an
> integer representing the length of data, and then the next 'n' bytes (as
> encoded in the preceding variable) are the content of the message itself.
> cut
> It may be useful to apply one of the Serialization mechanisms provided
> with the Framework to encode the various types of objects that you are
> transmitting.
>
>
Well, according to google :-), Serialization is the process of converting
complex objects into stream of bytes for storage. Deserialization is its
reverse process, that is unpacking stream of bytes to their original form.

Therefore, i dont get it what the serialization has to do with convention of
information encoding that is defined by me...

An additional explanation or example would be great :-)

Thanks in advance!


My System SpecsSystem Spec
Old 02-02-2009   #4 (permalink)
Jamesb


 
 

Re: Socket programming - how to identify accepted data?


"Alberto Poblacion" <earthling-quitaestoparacontestar@xxxxxx> wrote
in message news:eW9iDuShJHA.4880@xxxxxx
Quote:

> "Zalabado" <zala@xxxxxx> wrote in message
> news:gm6k7d$jov$1@xxxxxx
Quote:

>> I am a newby in socket programming (C#) and after a lot of googling I
>> succeeded in connecting and sending (asynchronous) a data over socket
>> between a server and client :-)
>> However, I would like to accept data via socket (e.g. from client) but
>> for a few different purposes (e.g. textmessage, login, password) and
>> therefore i would like to know what am i accepting (id, textmessage,
>> login, password)...
>>
>> Well, the question is: How to identify what kind of data am I accepting
>> (id, textmessage, login, password)?
>
> The socket will merely deliver a stream of bytes. It is up to you to
> define your own convention as to how you are encoding information in those
> bytes. For instance, you may decide that the first byte represents the
> type of data (1=textmessage, 2=login, etc), then the next two bytes are an
> integer representing the length of data, and then the next 'n' bytes (as
> encoded in the preceding variable) are the content of the message itself.
> As a sanity check, you may append a final byte or bytes with a 'magic
> value' (or a checksum) to verify that your encoding and decoding have
> worked properly. All of this can, of course, be modified as needed
> depending on the information that you are transmitting. It may be useful
> to apply one of the Serialization mechanisms provided with the Framework
> to encode the various types of objects that you are transmitting.
>

I did something similar but probably more amateurish, in that I sent
information between my client and server as a simple array- the first item
was always a string containing a code, so the receiving app would cast the
first item in the array to a string, check the code, and then deal with any
following items as necessary. This was usign remoting and events though, but
I imagine the same process could be applied with socket data.

The sanity checks and stuff listed above are probably a good idea though!

My System SpecsSystem Spec
Old 02-02-2009   #5 (permalink)
Bill Richards


 
 

Re: Socket programming - how to identify accepted data?

Hi Zalabado,

as Alberto pointed out, the socket is merely a mechanism by which a message
is transported, and therefore it presupposes no messaging protocol.

The protocol is for you to specify, or maybe you would find it easy to use
a pre-existing protocol. Within healthcare, for example a protocol called
HL7 is used to describe HOW the data look when they are transmitted across
the wire.

I believe that Alberto was trying to tell you that you can simply use your
..net objects, use the .net provided serialization mechanisms to de/serialize
these objects and transmit those objects between your client and server.
Obviously if you do this you will need to have the objects defined within a
common assembly which can be deployed to both your server and your client.

Good luck )


"Zalabado" <zala@xxxxxx> wrote in message
news:gm6k7d$jov$1@xxxxxx
Quote:

> Hi!
>
> I am a newby in socket programming (C#) and after a lot of googling I
> succeeded in connecting and sending (asynchronous) a data over socket
> between a server and client :-)
> However, I would like to accept data via socket (e.g. from client) but for
> a few different purposes (e.g. textmessage, login, password) and therefore
> i would like to know what am i accepting (id, textmessage, login,
> password)...
>
> Well, the question is: How to identify what kind of data am I accepting
> (id, textmessage, login, password)?
>
My System SpecsSystem Spec
Old 02-02-2009   #6 (permalink)
Alberto Poblacion


 
 

Re: Socket programming - how to identify accepted data?

"Zalabado" <zala@xxxxxx> wrote in message
news:gm6p6s$33o$1@xxxxxx
Quote:

> "Alberto Poblacion" <earthling-quitaestoparacontestar@xxxxxx> wrote
> in message news:eW9iDuShJHA.4880@xxxxxx
> Well, according to google :-), Serialization is the process of converting
> complex objects into stream of bytes for storage. Deserialization is its
> reverse process, that is unpacking stream of bytes to their original form.
>
> Therefore, i dont get it what the serialization has to do with convention
> of information encoding that is defined by me...

No! Not necessarily for storage. Serialization converts your complex
objects into a Stream of bytes, which you can certainly send to storage, but
you can also pump into a Socket, which will transmit them into the
destination socket, where you can then Deserialize them back into a
"replica" of the original objects. The Binary Serializer in the .net
Framework encodes the type of object into the stream that it produces, and
the deserializer throws an exception if you try to "extract" the wrong type,
so it serves as a sanity check to verify that the convention you used to
encode the type of object into your stream is working correctly.

My System SpecsSystem Spec
Old 02-02-2009   #7 (permalink)
Peter Duniho


 
 

Re: Socket programming - how to identify accepted data?

On Mon, 02 Feb 2009 04:32:10 -0800, Zalabado <zala@xxxxxx> wrote:
Quote:

> Well, according to google :-), Serialization is the process of converting
> complex objects into stream of bytes for storage. Deserialization is its
> reverse process, that is unpacking stream of bytes to their original
> form.
>
> Therefore, i dont get it what the serialization has to do with
> convention of
> information encoding that is defined by me...
It has everything to do with it. Socket i/o is strictly based on bytes.
You can only send bytes and you can only receive bytes. If you have some
other data structure to send and receive, you need to convert it to bytes,
and then convert it from bytes. Which, as you have already seen, is
exactly what serialization is about.

Now, there are other ways to go about it. You can define your own way to
package up the data, and that may well produce fewer bytes to send than
using the built-in serialization. But at some point you have to convert
the data to bytes so that it can be sent via the Socket, and then convert
the bytes back to your desired data structure.

Note that .NET includes a couple of features meant to abstract away from
the Socket class: remoting, and WCF. Unfortunately, I don't know a lot
about either so I can't really answer questions about them, but they
provide a way for your program to simply deal with objects and not worry
about the serialization part. Using either of those, you won't even use
the Socket class directly.

Pete
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Socket error 10052 on UDP socket .NET General
facing data loss problem in socket programming while using IIS .NET General
Memory configurations in socket?2x256 socket 1/3 and 2x512 socket Vista hardware & devices
Problems sending data with System.Net.Sockets.Socket PowerShell
Product Key not Accepted Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46