up previous next
OpenSocket    --    open a socket connection


Syntax
OpenSocket(HostName: STRING, PortNum: INT): RECORD

Description
This function opens a client socket (I/O) connection: the result is a RECORD where the field send is an out-stream , and the field recv is an in-stream . The expectation is that a "remote procedure call" is sent on send , and the result is read from recv using the function GetLine .

The first arg HostName is a string containing the name of the computer which is waiting for a connection; the second arg PortNum is the "port number" at which the server is waiting.

To make a connection to the same computer CoCoA is running on specify the host name localhost . The obsolescent CoCoAServer waits for a connection on the port number 49344 (which is c0c0 in hexadecimal).

Example
/**/ -->  assuming an echo server is waiting on port 10000...
/**/ IOPair := OpenSocket("localhost", 10000);
/**/ PrintLn 123+456 On IOPair.send;
/**/ str := GetLine(IOPair.recv);
/**/ str;
579

See Also