openserver(), closeserver(), serveruser(), serverpass()

There are several support functions for using the networked functions generated by NCG. They connect and disconnect from servers.

The functions are:

SERVER   *openserver(char *host,char *port);
SERVER   *closeserver(SERVER *se);
int       serveruser(char *username);
int       serverpass(char *password);

The openserver() and closeserver() functions connect and disconnect a client to and from a server respectively. openserver() takes the name of the host and port to connect to. The host may be a symbolic name like "thunder.thunderstone.com" or a number like "198.49.220.81". If an empty string or NULL pointer is passed, "localhost" will be used. Localhost means the same machine that the client is running on.

The port may be a symbolic name, that has been added to the list of known TCP/IP services on your system, or a number.

openserver() will immediately attempt to connect to the named host and port. It will return a SERVER pointer to be passed to all of the network functions. It will return SERVERPN on failure to connect.

closeserver() will shutdown the connection made by a successful openserver() call.

The serveruser() and serverpass() calls set the name and password, respectively, that openserver() will use when logging into the server. Either function will return zero on error. Non-zero is returned on success.

The default user name and password are both the empty string ("").

Example:

{
 SERVER *se;
 SRCH *sr;

 if(!serveruser("me")         ||
    !serverpass("mypassword") ||
    (se=openserver("thunder.thunderstone.com","10000"))==SERVERPN)
    {
     puts("can't open server, exiting.");
     exit(1);
    }
 ...
    n_search(se,sr);
 ...
 closeserver(se);
}


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.