Page 1 of 1

sendResponse and userList

Posted: 01 Sep 2006, 08:33
by beate
Hi,

i will send a message to all users (in different rooms), on each internal server event 'userJoin' ... i tried many possibilities with my extension but nothing works. the response does not send.... has someone a solution?

Code: Select all

function handleInternalEvent(evtObj)
{

     if (evtObj.name == "userJoin")
     {

           var response = new Object();
	   response._cmd = "NewUser";
	   response.msg = "xxx";
           
     var ok = _server.sendResponse(response, -1, null, getAllUsersInZone());

           if (ok)
           {
		     trace("Response sent!")
	             } else {
		     trace("Ups! Failed Response sent!")
           }
     }

}


 function getAllUsersInZone()
{
   var zone = _server.getCurrentZone()
   var listOfChannels = zone.getAllUsersInZone()
   var allUsers = []
   var socketChan = null
   
   for (var i = 0; i < listOfChannels.size(); i++)
   {
      socketChan = listOfChannels.get(i)
      allUsers.push( _server.getUserByChannel( socketChan ) )
   }
   
   return allUsers
}

thanks for help
and best regards beate

Posted: 01 Sep 2006, 10:32
by Lapo
I think you should read this --> http://forums.smartfoxserver.com/viewtopic.php?t=792

Let me know if it helps

Posted: 01 Sep 2006, 12:09
by beate
hi lapo,

yes, i read the article. but i dont know where ist the error in my extension.

getAllUsersInZone() and getChannelList() supply the same result, a list with all socketchannels in the zone.

the code in my extensions, with getAllUsersInZone(), for example: it.gotoandplay.smartfoxserver.data.User@1478a43,it.gotoandplay.smartfoxserver.data.User@81b1fb

best regards beate

Posted: 02 Sep 2006, 07:02
by Lapo
This part of the code is wrong:

Code: Select all

 var ok = _server.sendResponse(response, -1, null, getAllUsersInZone());
the sendResponse method does not return anything, because sending a message is something that can happen at any time, depending on the connections status.
It can be immediately in good network condition, but it may also take several seconds if the client is using a slow connections and is receiving packets slowly.

You just have to send the message and don't worry about it, the server and the underlying TCP/IP protocol will do the rest :)

Posted: 02 Sep 2006, 07:06
by beate
THANKS LAPO !