Forum C# gotMessage

gotMessage

Postby rabbitFriends » March 21st, 2010, 1:15 pm

Hi there,

i was just wondering if the gotMessage function on the server side is thread safe?
That means, what happens if player A sends a message and gotMessage is called on the server, what happens if in the meantime, while the server is still processing the message from player A, another player B sends a message to the server and thus, calls the gotMessage function too?

best regards and thanks,
flo
rabbitFriends
 
Posts: 3
Joined: March 19th, 2010, 2:14 pm

Re: gotMessage

Postby Cyclone103 » March 21st, 2010, 5:07 pm

Yes, if more than one message is received it is called twice, this is not an issue I think.
Cyclone103
 
Posts: 155
Joined: January 18th, 2010, 6:47 pm

Re: gotMessage

Postby rabbitFriends » March 22nd, 2010, 9:16 am

is it called the second time after the first call has finished? or are the functions called in different instances of that class?
rabbitFriends
 
Posts: 3
Joined: March 19th, 2010, 2:14 pm

Re: gotMessage

Postby Oliver » March 22nd, 2010, 9:58 am

The functions are called in the same instance, simultaneous. That is, they might be executing on top of each other.

This is not an issue unless
a) You have a ton of users sending a ton of messages to the same room AND
b) you're modifying some shared data in the execution of those methods.

My normal advice would be to not worry about it, and if you must, simply use the C# lock(){} statement to guarantee only one piece of your code is running at a time.
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: gotMessage

Postby rabbitFriends » March 22nd, 2010, 10:09 am

thx a lot, btw. playerIO is AWESOME :)
rabbitFriends
 
Posts: 3
Joined: March 19th, 2010, 2:14 pm

Re: gotMessage

Postby Cyclone103 » March 22nd, 2010, 7:53 pm

rabbitFriends wrote:thx a lot, btw. playerIO is AWESOME :)

I'll second that ;)
Cyclone103
 
Posts: 155
Joined: January 18th, 2010, 6:47 pm


Return to C#