473,385 Members | 1,384 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Seralisation the final question

Hi

i want to be able to check if information read that came from over a socket
is serilisable, if it isnt i want to handle it differently. Basically i am
trying to make a generic receivedata function that i can send any form of
data over the wire too and it will handle it appropriately.

I know i could do a try catch on a serilisation exception but i dont think
this is a good way to check as other things could cause such an error.

I did think of writing into the first 4 bytes of the send stream an
indenitifier for the response, then the slient can read those bytes and
decide, but again it starts to become less generic. Ideally i would like
anyone to send any info and i can handle it

Any ideas?

Also i am stuck on a scenario where i send data and cant proceed until i get
a response. One of my functions on the client fires a request but if the
client continues before getting a response it will crash. If i get it to
wait i end up poling and everything freezes for a second. I was thinking of
moving my interface logic and my actual application logic to 2 separate
threads. Then i can make the app logic wait while the sent message waits for
a reply, meanwhile the interface thread continues and i get no apparent
freeze. But i am sure this is not good for performance or is this ok?

thanks
Feb 11 '06 #1
3 1337
Daniel,

I would consider your objects to be messages. Either that, or you have
a wrapper object that has a reference to the object being serialized, as
well as any other information that needs to be sent along (like the status
code).

Then, you would send the length across the wire first, so you know how
many bytes to read.

With serialization, you just need a byte array that represents the
serialized instant. It doesn't matter wha the transport mechanism is.

I would also recommend having each of those types implement an interface
which will make accessing the objects in a consistent way easier.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Daniel" <Da*****@vestryonline.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi

i want to be able to check if information read that came from over a
socket is serilisable, if it isnt i want to handle it differently.
Basically i am trying to make a generic receivedata function that i can
send any form of data over the wire too and it will handle it
appropriately.

I know i could do a try catch on a serilisation exception but i dont think
this is a good way to check as other things could cause such an error.

I did think of writing into the first 4 bytes of the send stream an
indenitifier for the response, then the slient can read those bytes and
decide, but again it starts to become less generic. Ideally i would like
anyone to send any info and i can handle it

Any ideas?

Also i am stuck on a scenario where i send data and cant proceed until i
get a response. One of my functions on the client fires a request but if
the client continues before getting a response it will crash. If i get it
to wait i end up poling and everything freezes for a second. I was
thinking of moving my interface logic and my actual application logic to 2
separate threads. Then i can make the app logic wait while the sent
message waits for a reply, meanwhile the interface thread continues and i
get no apparent freeze. But i am sure this is not good for performance or
is this ok?

thanks

Feb 11 '06 #2

"Daniel" <Da*****@vestryonline.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi

i want to be able to check if information read that came from over a
socket is serilisable, if it isnt i want to handle it differently.
Basically i am trying to make a generic receivedata function that i can
send any form of data over the wire too and it will handle it
appropriately.

I know i could do a try catch on a serilisation exception but i dont think
this is a good way to check as other things could cause such an error.

I did think of writing into the first 4 bytes of the send stream an
indenitifier for the response, then the slient can read those bytes and
decide, but again it starts to become less generic. Ideally i would like
anyone to send any info and i can handle it

Any ideas?
It can't really be "generic" -- it can only handle the instances for which
you anticipate and senders agree to.
You need to send the length with any message (this is a stream), and I'd go
for the ID over the partial-read and expection, especially if your data can
be large, so that you can keep pending data in stream format, so consumers
that can take it this way are able to. If your data is mostly small, you can
read it using the length into a buffer and use your trial/error approach -
chances are derialzation will fail very quickly - although of course,
there's always a chance it will not fail at all - dangerous.

If you want to be more expressive, maybe you should go for a string (which
could even be XML someday) for the message identifier rather than an int --
for instance, you could send the name of a class to use to deserialize your
data on the other side, and use refection or a factory on the other side to
create the proper de-serializer instance. Versioning could be up to you in
your message preamble, or handled by each serialization protocol itself.

m

Also i am stuck on a scenario where i send data and cant proceed until i
get a response. One of my functions on the client fires a request but if
the client continues before getting a response it will crash. If i get it
to wait i end up poling and everything freezes for a second. I was
thinking of moving my interface logic and my actual application logic to 2
separate threads. Then i can make the app logic wait while the sent
message waits for a reply, meanwhile the interface thread continues and i
get no apparent freeze. But i am sure this is not good for performance or
is this ok?

thanks

Feb 11 '06 #3
All the native types (i.e. string, int, etc) can be serialize and any type
that has [Serializable] attribute. That is pretty generic. If you just
want to send a string, then serialize the string and send it. So your
"contract" can be anything serializable can be sent as long as you have the
proper type and version on the server side. If you can't deserialize it,
then there is not much you could do with the type anyway except log it and
close the client connection. What do you plan to do with types you don't
have a type for? Just curious.

--
William Stacey [MVP]

"Daniel" <Da*****@vestryonline.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
| Hi
|
| i want to be able to check if information read that came from over a
socket
| is serilisable, if it isnt i want to handle it differently. Basically i am
| trying to make a generic receivedata function that i can send any form of
| data over the wire too and it will handle it appropriately.
|
| I know i could do a try catch on a serilisation exception but i dont think
| this is a good way to check as other things could cause such an error.
|
| I did think of writing into the first 4 bytes of the send stream an
| indenitifier for the response, then the slient can read those bytes and
| decide, but again it starts to become less generic. Ideally i would like
| anyone to send any info and i can handle it
|
| Any ideas?
|
| Also i am stuck on a scenario where i send data and cant proceed until i
get
| a response. One of my functions on the client fires a request but if the
| client continues before getting a response it will crash. If i get it to
| wait i end up poling and everything freezes for a second. I was thinking
of
| moving my interface logic and my actual application logic to 2 separate
| threads. Then i can make the app logic wait while the sent message waits
for
| a reply, meanwhile the interface thread continues and i get no apparent
| freeze. But i am sure this is not good for performance or is this ok?
|
| thanks
|
|
Feb 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Anthony Martin | last post by:
I've been reading the Java Language Specification, and in Chapter 16 there's an interesting topic called Definite Assignment. http://tinyurl.com/3fqk8 I'm wondering about the idea of "Deferred...
14
by: Medi Montaseri | last post by:
Hi, I think my problem is indeed "how to implement something like java's final in C++" The long version.... I have an abstract base class which is inherited by several concrete classes. I...
0
by: Hans Forbrich | last post by:
Section 1. Ballot: ------------------- 1.YES NO: I agree that there should be a periodic post describing the newsgroup charter and providing a FAQ on newsgroup usage. 2.MONTHLY BI-WEEKLY...
10
by: Bezalel Bareli | last post by:
I know I have seen some threads on the subject long time ago and it was using a virtual base class ... in short, what is the nicest way to implement the Java final class in c++ Thanks.
14
by: My4thPersonality | last post by:
Has the fact that both Java and C# are garbage collected, and C++ in not, anything to do with the fact that there is no language item to prevent a class from being inherired from? I once read that...
7
by: Csaba Gabor | last post by:
I feel like it's the twilight zone here as several seemingly trivial questions are bugging me. The first of the following three lines is a syntax error, while the last one is the only one that...
16
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument...
2
by: Janick Bernet | last post by:
I recently learned about the "SELECT FROM NEW/OLD/FINAL TABLE" statement and I wanted to replace our old code, where we used "identity_val_local()" to get auto generated values after an insert. So...
14
by: Rahul | last post by:
Hi Everyone, I was searching for final class in c++, and i came across few links which suggests to have the constructor of the, to be final class, as private so that any derived class's...
11
by: ITrishGuru | last post by:
Hi all, I'm doing my FYP using csharp and MS Outlook to develope a plugin app. My question isn't about programming as such, Its more about project managment. Does anybody have a good URL that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.