Socket: 4 Making a Connection

Up: GEOS SDK TechDocs| Up | Prev: 3 Addresses | Next: 5 Accepting a Connection
SocketCreate(), SocketConnect(), SocketInterrupt()

To make a connection, a program creates a socket and specifies an address to which to connect that socket.

To create a new socket, call SocketCreate() . You must specify the socket's delivery type: datagram, sequential packet, or stream.

Before sending or receiving data over a sequential packet or stream socket, you must "connect" it to the place it will be sending the data to or receiving it from.

Depending on the medium and device, you may need to make sure that the device is connected to a network. For example, for a Nokia 9000i Communicator to make a TCP/IP connection, it must first have made a PPP connection. Use the SocketOpenDomainMedium() routine to make the "raw" network connection.

To make a connection, call SocketConnect() . Pass the socket created via SocketCreate() , the address to connect to, and a time-out value. If it returns SE_NORMAL, then the connection was established successfully. If it returns SE_CONNECTION_REFUSED, the remote site wasn't prepared to accept the connection. If it returns SE_CONNECTION_ERROR, the connection didn't go through for some miscellaneous reason. If it returns SE_NON_UNIQUE_CONNECTION, then the attempted connection would have been identical to another connection: same source address, source port, destination address, destination port, and delivery type. There would be no way to tell these connections apart. If you try to open the same connection from both sides simultaneously, they may both fail with SE_NON_UNIQUE_CONNECTION.

To cancel the connection operation, call SocketInterrupt() .

Datagram sockets cannot form a true connection -- they are unreliable. Sockets must be able to send and receive datagram packets without relying on a permanent connection. However, using SocketConnect() with a datagram socket specifies a default destination address to use when sending packets.


Up: GEOS SDK TechDocs| Up | Prev: 3 Addresses | Next: 5 Accepting a Connection