|Top Previous Next|
Below is the entire project. You can just copy/paste it into the main.tbs file -- it will be opened and "in front of you" when you create your tcp_echo project.
The only line that will probably need changing is the net_ip="" line. Choose a suitable IP address for your device and set it here. Obviously, the address you choose should be unoccupied -- you can verify this by pinging this IP and making sure nobody responds.
We don't want to go into a lengthy explanation here... just a few comments on how this works:
•The sys_on_sys_init event handler prepares a single listening TCP socket.
•The sock_on_sock_data_arrival event handler takes whatever is received by the TCP socket and sends it back.
•The sock_on_sock_event event handler is not actually necessary for the echo application. We added this because we wanted to have this proverbial "HELLO WORLD" somewhere. The string is sent whenever a TCP connection is established.
Notice how small your first Tibbo BASIC program is! This is the power of Tibbo BASIC -- you accomplish complex things in just several lines of code.
dim s as string
sub on_sock_event(newstate as enum pl_sock_state,newstatesimple as enum pl_sock_state_simple)
if newstatesimple=PL_SSTS_EST then