Cold Help System: Programming: ColdC Reference Manual: Implementation: Networking: Server Connection


To establish a server connection first call the function bind_port(). The argument to this function is the network port to listen on. Note: most operating systems will restrict low numbered ports (usually anything below 1024 is restricted, and can only be opened with special privelages). If there are no errors, the current object is listening as a server on the specified port.

When an external client opens a connection the driver will call the method .connect() with two arguments. The first argument is a STRING, specifying the remote IP address of the client. The second argument is an INTEGER, specifying the socket where the connection was established. In general this number can be ignored.

Data received on the connection will be sent as a buffer to the method .parse(), after the method .connect() is called. Data is sent to the connection using the functions cwrite() and cwritef().

If the client terminates the connection, the method .disconnect() is called. Note: this method will not be called if the object terminates the connection through close_connection().

If multiple connections will be received on the network port, it is suggested that when a connection is started the connection object either reassigns the connection to another connection object (using the function reassign_connection()), or it notifies a new connection object to re-bind the port to itself. If this is not done, new connections will preempt and close the older connection (as only one connection can be on an object at a time).


Server Connection | Client Connection | Driver Network Methods


the Cold Dark