Quote
If i recall correctly Ethernet KRL allows only one server (on the robot side). But in your case server is external, so robot is acting as client. That means (as long as your server support it) you can create several connection to it, either from same or from different robots.
I'm using src modules to test things first, so sub modules were mentioned to give explanation of planned end system. I have written simple src module which tries to create two simultaneous connections from robot to server. Server is 100% capable to work with multiple connection form single client. Here is src module code:
DEF multi_tcp_connection ( )
INT i
DECL EKI_STATUS RET1
DECL EKI_STATUS RET2
DECL CHAR inquiry1[64]
DECL CHAR inquiry2[64]
INTERRUPT DECL 89 WHEN $FLAG[1] == TRUE DO GET_FIRST_DATA()
INTERRUPT DECL 90 WHEN $FLAG[2] == TRUE DO GET_SECOND_DATA()
INTERRUPT ON 89
INTERRUPT ON 90
FOR i=1 TO 64 STEP 1
inquiry1[i]=0
inquiry2[i]=0
ENDFOR
RET1=EKI_Init("Call_to_server1")
RET2=EKI_Init("Call_to_server2")
RET1=EKI_Open("Call_to_server1")
RET2=EKI_Open("Call_to_server2")
WAIT SEC 0
inquiry1[] = "1 connection test"
inquiry2[] = "2 connection test"
$FLAG[1] = FALSE
$FLAG[2] = FALSE
RET1=EKI_Send("Call_to_server1", inquiry1[])
RET2=EKI_Send("Call_to_server2", inquiry2[])
$FLAG[89] = FALSE
$FLAG[90] = FALSE
WAIT SEC 0
WAIT FOR $FLAG[89] AND $FLAG[90]
RET1=EKI_Close("Call_to_server")
RET1=EKI_Clear("Call_to_server")
RET2=EKI_Close("Call_to_server")
RET2=EKI_Clear("Call_to_server")
END
DEF GET_FIRST_DATA()
DECL EKI_STATUS RET
DECL INT i
FOR i=1 TO 64 STEP 1
echo1[i]=0
ENDFOR
RET = EKI_GetString("Call_to_server1", "BufferIn1", echo1[])
$FLAG[89] = TRUE
$FLAG[1] = FALSE
END
DEF GET_SECOND_DATA()
DECL EKI_STATUS RET
DECL INT i
FOR i=1 TO 64 STEP 1
echo2[i]=0
ENDFOR
RET = EKI_GetString("Call_to_server2", "BufferIn2", echo2[])
$FLAG[90] = TRUE
$FLAG[2] = FALSE
END
Display More
Here is "Call_to_server1.xml" internals:
<ETHERNETKRL>
<CONFIGURATION>
<EXTERNAL>
<IP>172.31.1.140</IP>
<PORT>59152</PORT>
<TYPE>Server</TYPE>
</EXTERNAL>
</CONFIGURATION>
<RECEIVE>
<RAW>
<ELEMENT Tag="BufferIn1" Type="STREAM" Set_Flag="1" EOS="10"/>
</RAW>
</RECEIVE>
<SEND>
<RAW>
<ELEMENT Tag="BufferOut1" Type="STREAM" EOS="10" />
</RAW>
</SEND>
</ETHERNETKRL>
Display More
The difference between "Call_to_server1" and "Call_to_server2" are receive flag number (1 or 2) and different names for input and output buffers (with indices 1 or 2). External configuration contains right server connection parameters and they are the same for both configuration files.
Considering basics of TCP\IP protocol, a connection or "socket" on server side is defined by combination of "Server IP, Server Port, Client IP, Client Port". So any other connection to the same server will have ether different Client IP or Client Port. The Client IP will be the same coz we are connection from the same robot. According to EthernetKRL documentation, we do not have access to port choice if KLI is acting as client, so, I suppose EthernetKRL package manages ports itself. So, in theory, my test program must work. But code gives EKI00023 error at line:
RET2=EKI_Init("Call_to_server2")
what means that - "The Ethernet connection has already been initialized with the function EKI_Init()." And documentation advices me to close active connection before creating new....
Either, I'm doing something wrong, or it is not possible to make several simultaneous connections from single robot to the same server, even if documentation states it is possible.