sendResponse and userList

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
beate
Posts: 33
Joined: 15 Jun 2005, 14:34

sendResponse and userList

Post 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
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

I think you should read this --> http://forums.smartfoxserver.com/viewtopic.php?t=792

Let me know if it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
beate
Posts: 33
Joined: 15 Jun 2005, 14:34

Post 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
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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 :)
Lapo
--
gotoAndPlay()
...addicted to flash games
beate
Posts: 33
Joined: 15 Jun 2005, 14:34

Post by beate »

THANKS LAPO !
Post Reply