Click to See Complete Forum and Search --> : event handling error


luvcloud
June 28th, 2002, 12:17 AM
Can anyone help me figure out what was causing the error. Here's the problem area:

i wrote a client/server app. The client will send msgs to the server and the server will raise the appropriate event (through delegates) and call the appropriate classes to process the msg. for example:

Try{
if (sMsgToken[0] == "GAMEJOIN")
{
Game(sMsgToken);
ReceiveMsgCallback(sock);
}


else if (sMsgToken[0] == "HOSTREMOVE")
{

Game(sMsgToken);
ReceiveMsgCallback(sock);
}
}
catch
{
Disconnect();
}


sMsgToken = the message received from the client
Game = an event. another class will be listening to this event and will call the event handler to process the necessary tasks.

First the GAMEJOIN message was sent. appropriate replies were then received from the server. But when the HOSTREMOVE message was sent next, the client is disconnected instead, which means the catch statement was executed.

So i tried to change the name of the event Game (for HOSTREMOVE) to a different name; GameRemove. And a different event handler was created for it. And it turned out fine.

So my question is, is it not possible to have same events raised by the different msgs? i mean, what was the problem?

jparsons
June 28th, 2002, 07:55 AM
Originally posted by luvcloud

Try{
if (sMsgToken[0] == "GAMEJOIN")
{
Game(sMsgToken);
ReceiveMsgCallback(sock);
}


else if (sMsgToken[0] == "HOSTREMOVE")
{

Game(sMsgToken);
ReceiveMsgCallback(sock);
}
}
catch
{
Disconnect();
}



I know it's unlikely that your events will be null in this case but try changing your code to look like this becuase it could be generating and error.


else if (sMsgToken[0] == "HOSTREMOVE")
{
if ( Game != null )
Game(sMsgToken);
ReceiveMsgCallback(sock);
}


Also if this doesn't work then add an actual exception handler at the end and print out the error. It will be a lot easier to debug your problem if we at least know what exception is being thrown.



So my question is, is it not possible to have same events raised by the different msgs? i mean, what was the problem?

It is possible to have more than one thing fire off an event. It was designed witht aht intent

luvcloud
July 5th, 2002, 10:24 PM
okiee..i tried both ways...the first way did not work...
the exception message i received was:

Index was outside the bounds of the array

but i don't understand which part of the array is out of bounds....it can't be the smsgToken as all the other if/else conditions use this same array....
and the length of the message is not long too which is

HOSTREMOVE|<tablenum>|<playername>