Home AMX User Forum NetLinx Studio

IP server and load balance

HI all,

I am writing a code with 14 tcp servers started. the port connections are 6001 to 6014. As we know each server accept only one connection, and each client need to have specified the AMX ip address and the specific port to connect to the server.

So, I would like to know if is there a way to create a load balance , a pool of these servers , these way all client need specify AMX ip address and the port 6001 for example, ( as occurs in web servers hosted in cloud ) this way if the first server of pool is occupied the system send the request to the second server of pool, or to third, or fourth ,etc.

thanks in advance


DEFINE_START
wait 50
{
ip_server_open(dvSvr01.PORT,6001,IP_TCP)
ip_server_open(dvSvr02.PORT,6002,IP_TCP)
ip_server_open(dvSvr03.PORT,6003,IP_TCP)
ip_server_open(dvSvr04.PORT,6004,IP_TCP)
ip_server_open(dvSvr05.PORT,6005,IP_TCP)
ip_server_open(dvSvr06.PORT,6006,IP_TCP)
ip_server_open(dvSvr07.PORT,6007,IP_TCP)
ip_server_open(dvSvr08.PORT,6008,IP_TCP)
ip_server_open(dvSvr09.PORT,6009,IP_TCP)
ip_server_open(dvSvr10.PORT,6010,IP_TCP)
ip_server_open(dvSvr11.PORT,6011,IP_TCP)
ip_server_open(dvSvr12.PORT,6012,IP_TCP)
ip_server_open(dvSvr13.PORT,6013,IP_TCP)
ip_server_open(dvSvr14.PORT,6014,IP_TCP)
}



Comments

  • GregGGregG Posts: 251
    It is possible to open more than one ip_server on the same port:
    DEFINE_DEVICE
    dvIP1 = 0:3:0
    dvIP2 = 0:4:0
    dvIP4 = 0:5:0
    
    DEFINE_CONSTANT
    Dev dvIPPorts[] =
    {
      dvIP1,
      dvIP2,
      dvIP3
    }
    
    DEFINE_VARIABLE
    Volatile Integer nTmp
    Volatile Char cBuffers[3][5000]
    
    DEFINE_START
    For(nTmp=Length_Array(dvIPPorts);nTmp;nTmp--)
    {
        Create_Buffer dvIPPorts[nTmp],cBuffers[nTmp]
        IP_SERVER_OPEN(dvIPPorts[nTmp].Port,6001,IP_TCP)
    }
    
    DEFINE_EVENT
    Data_Event[dvIPPorts]
    {
      String:
      {
        Stack_Var Char cMsg[200]
        Stack_Var Integer nConn
            nConn = Get_Last(dvIPPorts)
            While(Find_String(cBuffers[nConn],"$FF",1))  // Chose your own delimiters
            {
                cMsg = Remove_String(cBuffers[nConn],"$FF",1)
                // Deal with the incoming data as needed, per-connection...
            }
      }
    }
    
  • viningvining Posts: 4,368
    I have a program that uses 6 servers all on the same port but I only have one listening at a time. As soon as a client connects to my current "listener" it becomes an active connection so I start the next server in line to be my listener, when the first connection ends I close it. A round robin routine so one is always listening and the others are either closed or have active clients.
  • Thanks guys, I will test it.
Sign In or Register to comment.