A Code Snippet
|Top Previous Next|
Here is a small code snippet illustrating the process of getting and releasing sockets. We sacrificed robustness for simplicity, so don't take the code below for a shining example of sock. object's usage. Just see the parts related to the SOCK library — that's the point right now.
And here is what appeared in the output pane of TIDE as the code executed:
The first message corresponds to sock_get(), the second one — to sock_release(). "TCPS" is the signature left by us, it stands for "TCP socket". The socket number obtained is 2 because we ran this code within a large program that uses a lot of other sockets for a lot of other things.
The example above establishes an outgoing connection to 192.168.1.67:10000. In our test, this was a PC running I/O Ninja, our sniffer/terminal software (you can get it at ninja.tibbo.com). We opened a "listener socket" on I/O Ninja, and here is what we saw:
This "TCPS" is the signature our code provided when calling sock_get(). The reason it appeared in Ninja is because of the sock.setdata(sock_who_uses(tcp_sock)) line in the code.