About Store Forum Documentation Contact



Post Reply 
[Solved] - Avanced Networking Connection
Author Message
Avatar Offline
Member

Post: #1
[Solved] - Avanced Networking Connection
Hi,

I search to create a dynamique ARRAY of Connection function and start in multi Threard all connection at the same time, send to server requested information. I read a XML file that contain X socket information, i read this XML to put in a Socket Array

Code Example :

Code:
Connection connection[X];
SockAddr server[X];
Thread TestServ[X];
GlobalStruct Globalarray[X];

Reading XML ... to pupolate SockAddr Array

Code:
FREPA(XML_Server_List.nodes)
{
str IP     = XMLFav.nodes[i].params(0).value;
Str PORT= XMLFav.nodes[i].params(0).value;
server[i].setIP( IP, CalcR(PORT) );
}

Creation Multi Theard of connection...

Code:
FREPA(server)
{
TestServ[i].create(ServerTest, 0,0,0, ptr(i) );
}

Code:
bool ServerTest(Thread &thread_caller)
{
   uint iref = (UIntPtr)thread_caller.user;
   if ( connection[iref].clientConnectToServer(server[iref]) )
   {
      File ServTestSend;
      ServTestSend.writeMem();
      ServTestSend.putInt(SERVER_INFO);
      ServTestSend.pos(0);
      connection[iref].dataFull(ServTestSend, ServTestSend.size(), true);      
        
      if(connection[iref].receive(3000))
         {
          connection[[iref].data.pos(0);
          byte typeP=connection[[iref].data.getByte();
            
          switch (typeP) {
               case SERVER_INFO :
                  Globalarray[iref].NAME  = connection[iref].data.getStr();
                  Globalarray[iref].STATE = "ON";
                  Globalarray[iref].VERSION = connection[iref].data.getStr();
                  Globalarray[iref].NBP = connection[iref].data.getStr();  
               break;
          }
        }
   }

1 : When i start the Multi Theard of connection, eatch server receive request X time for each Theard ...

2 : Array as always CONSTANT, but i need to change the number of occurence of each array dynamicaly, it is possible to add occurence or delete occurence and rezise Array dynamicaly ? if yes how to ?

3 : Server receive connection but never the packet <SERVER_INFO> request. i have test with one connection, and i need to wait the GREETED State before Send my request... it is possible to bypass that ?

4 : I dont use Update section, because i want each Theard to wait the anwser of each server. i use a receive delay to 3 seconds. But i never reveive anwser in the theard...

Can anyone help me please ?
Avatar
(This post was last modified: 07-15-2011 02:06 PM by Avatar.)
07-10-2011 02:23 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Avanced Networking Connection
Hi,

2. class ThreadConn
{
Connection conn;
Thread thread;
};
Memx<ThreadConn> connections;

3. currently Connection can't send data until it has greeted status first, use
connection.clientConnectToServer(..);
connection.receive(5000); // call this 1 time after 'clientConnectToServer' to wait for greet receiving
..now send data..

I'll update this for the next SDK so you don't need to call 'receive' 1 extra time at start

4. in your code SERVER_INFO will not be sent because connection was not greeted yet, so server won't receive it and won't send reply. If you will do as I mentioned in 3) it should work ok.
07-10-2011 03:15 PM
Find all posts by this user Quote this message in a reply
Avatar Offline
Member

Post: #3
RE: Avanced Networking Connection
Thanks

I test that

Avatar
07-10-2011 03:23 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Avanced Networking Connection
if you'll download latest SDK update then please remove this line:

connection.receive(5000); // call this 1 time after 'clientConnectToServer' to wait for greet receiving
07-10-2011 04:20 PM
Find all posts by this user Quote this message in a reply
Avatar Offline
Member

Post: #5
RE: Avanced Networking Connection
OK

Works perfectly with improve performance...
Thx a lot
Thx for Update SDK very appreciated !
Avatar
07-10-2011 06:28 PM
Find all posts by this user Quote this message in a reply
Avatar Offline
Member

Post: #6
RE: Avanced Networking Connection
Another question :

i have the class :

Code:
class ThreadConn
{
Connection conn;
Thread thread;
};
Memx<ThreadConn> connections;

i start many connections with that :

Code:
ThreadConn &TempsTheard=connections.New();
         TempsTheard.thread.create( Serverup, 0,0,0, ptr(i)  );

i finish my Serverup function by :

Code:
thread_caller.del();                                                
   return false;

But when i show the numbers of element in connections , this number never decreise to 0... why ?

Code:
D.text(0,0.9f,S+connections.elms());

It is possible to del connections when the process of ServerUP is finish ?
07-11-2011 11:28 PM
Find all posts by this user Quote this message in a reply
Avatar Offline
Member

Post: #7
RE: Avanced Networking Connection
Ok is good, i found a way to know all terminated thread.

Thx
07-14-2011 03:07 AM
Find all posts by this user Quote this message in a reply
Avatar Offline
Member

Post: #8
RE: Avanced Networking Connection
I have a new probleme, now, when i have lots of Theard, EE engine output : cant allocate x bytes of memory. I have search why but y dont understand the probleme.

How many memory reservation take a theard by defaut ?

I continue to search.

Avatar
(This post was last modified: 07-14-2011 05:46 PM by Avatar.)
07-14-2011 05:42 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: Avanced Networking Connection
1MB for each thread
possibly you have a bug and dont release memory somewhere
07-14-2011 11:09 PM
Find all posts by this user Quote this message in a reply
Avatar Offline
Member

Post: #10
RE: Avanced Networking Connection
OK thank for answer.

I found the probleme, i allocate a wrong space memory. Sorry.
I have make test with 100 theards connection and all works perfecly now.

Thanks
07-15-2011 02:14 AM
Find all posts by this user Quote this message in a reply
Post Reply