Socket library (pc_sock)

Description:
PocketC native library for low-level TCP/IP communications based on sockets.
Palm devices with OS > 2.0, PocketC compiler (embedded or Desktop Edition).
Shareware.

Files included:
pc_sock.prc: the native library. Install it on your Palm device using PalmDesktop tool.
pc_sock.lib: Lib file for PocketC desktop edition.
test_chat.c: PocketC demo code for a simple chat over TCP with a desktop application (use the supplied windows application).
tcpsrvdemo.exe: Windows TCP server application to use with test_chat.c file above.
pc_sock.html: this file.

Usage:
On the top of your code place the line :
library "pc_sock"

Functions:

int tcp_netopen();
Open network. Returns 0 on succes or an error code if failed.
Errors thrown: 1001, 1002, 1003, 1004
1001 ROM Incompatible
1002 Net.lib not found on device
1003 Cannot open network
1004 Network interface error

tcp_netclose();
Close network.

int tcp_connect(string address, int port, int timeout);
adrress: remote machine address, in the form of: "192.168.0.1" or "www.google.com"
port: port on the remote machine where the server is listening
timeout: timeout, in SysTicks (currently 100SysTicks=1 sec.)
Returns a positive value if connection succed or a negative value if it fails.
Store the positive value to use in further calls to read or write from/in this connection.
Example:
s=tcp_connect("www.google.com",80,500);
s=tcp_connect("192.168.0.200",5001,100);

tcp_disconnect(int socketref);
socketref: the value obtained in tcpconnect
Disconnect from a remote machine and close the socket.

int tcp_write(int socketref, string data);
socketref: the value obtained in tcpconnect
data: data to send
Returns the number of chars (bytes) actually sent.
Example:
tcp_write(s, "Hello there !");

string tcp_read(int socketref, int len, string token, int timeout);
socketref: the value obtained in tcpconnect
len: maximum number of chars (bytes) to receive
token: if string token is received then return
timeout: maximum time to wait, in SysTicks (currently 100SysTicks=1 sec.)
Reads data from a socket until len bytes are received OR string token is
received OR timeout elapse.
Example:
received=tcp_read(s, 100, "\n", 500);
Receive in received variable a maximum of 100 bytes OR until "\n" is
received OR 500 SysTicks elapses (5 seconds)

tcp_purge(int socketref);
socketref: the value obtained in tcpconnect
Flush the input buffer of a socket. Note: this calls may block until
the remote machine stops sending. Use this only with a well known
protocol.

int tcp_ver();
Returns library version, as a 4 chars string. Ex: 102d.
First 3 chars is version number and the forth can be d - developer version
or u - user version.

tcp_reg(string devkey);
devkey: key for registering, obtained on purchasing the developer version.
Register the library (remove the nag alert), must be the first function called.
Works only on developer version (library installs on unlimited number of devices),
does nothing in the user version (library installs on only one device).

Other network libraries for PocketC

FTP library (pc_ftp)
SendMail library (pc_smail)

Copyright Cosmin Buhu, 2002-2003

http://www.easyvitools.com/palm
cosminb@warpnet.ro