Synch or Asynch? [urgent question]

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

nig3d
Posts: 164
Joined: 02 Jul 2008, 09:42

Synch or Asynch? [urgent question]

Postby nig3d » 27 Dec 2008, 02:03

Hi,

are all the server side functions synchronous?
giving an example:
_server.sendRoomList(user)
waits for the client update before to continue the server script execution?
User avatar
cemuzunlar
Posts: 47
Joined: 26 Dec 2008, 00:45
Contact:

Postby cemuzunlar » 27 Dec 2008, 14:40

It doesn't have to wait. Because it doesnt matter if the client got the message or not. It is the client's problem. If a client doesn't respond for a predefined time, it disconnects the user.

If the server waits for every update it sent being processed by the client, it has to wait a considerable amount of time doing nothing.
Also, if there aren't enough threads serving for the requests, then most of the clients won't get an answer from the server because it is busy waiting other clients processing the messages.
Increasing the thread count is not a solution because, it doesn't scale with the number of clients.

Instead of wasting resources, server simply sends a message to a client, maybe updates the client's private data on the server side and go on its work.
Cem Uzunlar
Infosfer Game and Visualization Technologies
http://www.infosfer.com
contact@infosfer.com
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 29 Dec 2008, 08:07

Everything is asynchronous
Lapo
--
gotoAndPlay()
...addicted to flash games
nig3d
Posts: 164
Joined: 02 Jul 2008, 09:42

Postby nig3d » 29 Dec 2008, 08:13

everything is asynchronous?
how can the server be asynch? You don't have any event on the server side!

You often do something like that:

theRoom = _server.createRoom(roomObj, null, true, true, roomVars)

if (theRoom != null)
trace("Room Created Successfully")
else
trace("OUCH! Room was not created!!!")


obviously createRoom is not asynch.
Beside, I have another big problem with the dynamic room creation.
I create and join rooms on the server side, through extensions, with the consequence that the client crashes everytime!
Why? Because when I join the room using the server side code, the room list on the client side is not updated, and the handleJoinOk (or something like that) crashes always.
To avoid this, I used the function sendRoomList(), but if it's not synch, I'm not 100% sure that the client won't crash.
Please advice.
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 29 Dec 2008, 08:21

Ok, then the word is blocking or non blocking.
Synchronous / Asynchronous refers to network communications, and I confirm that every request works asynchronously.

Method calls are all blocking (they return when they have finished)

I create and join rooms on the server side, through extensions, with the consequence that the client crashes everytime!


Make sure to send the room list before you create or join anything.

1- login
2- send room list from server side
3- create new room (make sure that you call createRoom with the broadcast flag set to true)
4- join the room
Lapo

--

gotoAndPlay()

...addicted to flash games
nig3d
Posts: 164
Joined: 02 Jul 2008, 09:42

Postby nig3d » 29 Dec 2008, 08:26

Lapo wrote:Ok, then the word is blocking or non blocking.
Synchronous / Asynchronous refers to network communications, and I confirm that every request works asynchronously.


sorry, I was referring to synchronous and asynchronous languages :)
nig3d
Posts: 164
Joined: 02 Jul 2008, 09:42

Postby nig3d » 29 Dec 2008, 08:27

Lapo wrote:
1- login
2- send room list from server side
3- create new room (make sure that you call createRoom with the broadcast flag set to true)
4- join the room


well if I don't send the room list after the room creation, it crashes during the joining :(.
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 29 Dec 2008, 08:34

You need to send the room list only at the beginning, right after a successful loign.
From that moment on the server will keep the user updated by only sending notifications of new rooms being added or rooms being deleted.

If you have problems joining it is very likely that your createRoom call is not sending an update to the client. As i said earlier, make sure that the broadcast flag is set to true, otherwise no update is sent to the client and the join will fail
Lapo

--

gotoAndPlay()

...addicted to flash games
nig3d
Posts: 164
Joined: 02 Jul 2008, 09:42

Postby nig3d » 29 Dec 2008, 08:36

Thanks for the answer.
The login is made on the client side, so how can I send the room list after the login?
Anyway, after the login on the client side, the roomlist is sent.
The flag is set to true (it's also the default value).
nig3d
Posts: 164
Joined: 02 Jul 2008, 09:42

Postby nig3d » 29 Dec 2008, 10:00

Code: Select all

var response = {}
      response._cmd = "rcount"
      
      var room = params;
      var rName = room.name;
               
      var zone = _server.getCurrentZone()
      
      if (roomInstances[rName] == undefined || (zone.getRoom(roomInstances[rName].getId()) == null))
      {
         trace ("creating dynamic room..." + rName);
         var newroom = _server.createRoom(room, user);
         if (newroom)
         {
            roomInstances[rName] = newroom;
            trace ("joining dynamic room..." + rName);
            response.ok = _server.joinRoom(user, fromRoom, true, newroom.getId())
            //response.ok = true;
         }
         else
            response.ok = false;
      }
      else
      {
         trace ("joining dynamic room..." + rName + "from room:" + fromRoom);
         //force the client to update the room list, otherwise the client will crash because it can't find the new rooms!         
         _server.sendRoomList(user)         
         response.ok = _server.joinRoom(user, fromRoom, true, roomInstances[rName].getId())
         //response.ok = true;
      }

      //return the id of the istance available
      response.instanceName = rName;
      //the name of the join to room must be composed by
      
      _server.sendResponse(response, -1, null, [user])


ok I try to explain better:
Actually I was mistaken, since after the room creation the room can be joined (I just forgot).
The problem is when an user want to join a room created by another user. In that case, I'm forced to send the room list, otherwise smartfox crashes.
nig3d
Posts: 164
Joined: 02 Jul 2008, 09:42

Postby nig3d » 30 Dec 2008, 09:29

no comments? Then I assume it's normal.
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 30 Dec 2008, 10:29

Unfortunately this doesn't add much to what we said before.
Can you please describe what is going on step by step?

I assume the user has at least already been logged in.
Is he already joined in another room when this code runs? If so ... is it a regular room? limbo? game room?

If you can provide the steps that you're doing up to that point it will be easier to help you
Lapo

--

gotoAndPlay()

...addicted to flash games
nig3d
Posts: 164
Joined: 02 Jul 2008, 09:42

Postby nig3d » 30 Dec 2008, 13:54

So:

all the users log in through the client.
the first user who enter in a room, creates it through the server.
all the other users entering the same room, join it through the server.

For the first user, after the room creation, he is able to join the room.
For all the other users, I need to send the room list before to join the room, otherwise !crash!
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 31 Dec 2008, 10:50

the first user who enter in a room, creates it through the server.

This is clear but you are not explaining how you do it in detail.
Here's how it should work:

1- [client] connect
2- [client :: onConnect] log into the application zone
3- [server] send room list
4- [server] join user in a Limbo Room (this is where you park people who need to wait before a specific room is created for them)
5- [server] check if room exist, if NO -> create room
6- [server] join the user

I am quite sure that you are skipping point 4

It is important the BEFORE you start creating rooms, sending messages and whatnot you join you user SOMEWHERE

Users cannot interact with the server if they don't join at least ONE ROOM

LIMBO Rooms are specifically designed for tasks like these ... such as: registration areas, instant messengers, lobbies etc...
Lapo

--

gotoAndPlay()

...addicted to flash games
nig3d
Posts: 164
Joined: 02 Jul 2008, 09:42

Postby nig3d » 31 Dec 2008, 13:09

Ciao Lapo,

happy new year!
The limbo is always joined before to do any operation.
Knowing this, check the code above, you can see how I create the room and how I let the user join the room created.
Again, I need to send the roomList if want a user join a room created dynamically on the server (but only if this user is not the one to have created the room)

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 48 guests