Greetings.
I'm trying to build a messanger application.I managed to build peer-to-
peer and now I'm trying to build one with a server.
First I'll give a short summary of how I built the application.
I create an Envelope class with two properties: Message (which is an
abstract class) and Enum named contentType which indicates which type
of message is inside the Envelope object.
Then I created a class named HeartbeatMessage which inherits Message.
I created another class which inherits Message named
ServerUpdateMessage.
I created a Server class which has a TcpListener and a method named
Listen which waits for stream.Once a stream arrives it deserialize
it,while casting to Envelope.Then fire an event (which I created
earlier) who receives this envelope for further processing.
Both client and server has an instance of the Server class.
The procedure is as follows:
When the server form is up it starts the Server.Listen method on a
separate thread so the GUI keeps on responding.
Then the chat form is up sending a heartbeat message to the server.
The Server.Listen method of the server form process the
stream,deserialize it while casting to envelope and the event is
fired.
Then it check the content and see it is heatbeat.If the user is new to
the server it sends an Envelope with ServerUpdateMessage to all users
he knows (in my environment only one).
When the chat form Server.Listen (which also operates on a separate
thread for GUI response) the problem starts.
I work in debug and go line by line.
I can see a stream with data arriving,then I put it in memory stream
in order to deserialize it (all this is part of Server.Listen which
operates fine on the server form.),Then I deserialize it while casting
to Envelope and put the result in an Envelope object.
In Visual Studio I can see the Envelope object with the fields and
values I sent from the server.
Then I try to fire the event with this envelope and receive : "object
reference not set to an instance of an object".
I searched the net and asked my colleagues but didn't manage to find
an answer.
I then put a message box after the deserialization with one of the
properties if the ServerUpdateMessage object inside the deserialized
envelope object and I can see the text in the message box.And then
again the exception occurred when fired the event!!!
I'm very frustrated and will be thankful to any crumb who will lead to
a solution.
Thanks in advance,
YZ.
|