Now I'm using RL-TCPnet on an embedded controller which acts as the TCP server. The server returns back different messages according to different messages sent by different clients. To return back the messages to different clients, I guess that tcp_send function should be used. If my guess is right, I want to know if the server's tcp socket is defined as socket_tcp = tcp_get_socket(TCP_TYPE_SERVER,0,10,tcp_callback), shall the tcp_send function be called in the tcp_callback function on the TCP server?
The tcp_send() function is used to send data to an opened TCP socket. However it shall not be used from the tcp_callback function. This function is only used to inform the application about several events and to deliver data to the application.
The callback function shall return to allow the library to acknowledge the TCP packet and update sequence numbers. If tcp_send is called from the callback function, this destroys the sequence numbering and proper acknowledge. For this reason it will not work.
Please take a look at the LEDSwitch example.
Thanks Mr Franc Urbanc for your help. Can you answer me another question about RL-TCPnet? I want to make such an embedded system as following. The embedded system acts as a TCP server, it receives different messages which are sent by different clients and it sends back different messages to different clients. There're three TCP socket types in RL-TCPnet, TCP_TYPE_SERVER, TCP_TYPE_CLIENT, TCP_TYPE_CLIENT_SERVER. I tried to use TCP_TYPE_SERVER, but I found that TCP_TYPE_SERVER can only listen and can't send messages out. Can you tell me which socket types I can used in the above embedded system? Thanks.
You should use TCP_TYPE_SERVER sockets. The difference is in a way, how the connection is established. Server type only accepts connections, but can not start them. When the TCP socket is connected, you can send and receive data in both directions.
Franc
do you have an example of receiving and sending data form a TCP_TYPE_SERVER? , I have tried but all my attemps have falied, I'm doing also what you said; using the send command from outside the call back function but it doesn't work
Kind regards