Establishing a connection

QNX SDP8.0Getting Started with the QNX OSDeveloperUser

So, let's look at these functions in turn. The first thing we need to do is to establish a connection. We do this with the function ConnectAttach(), which looks like the sample shown here.

#include <sys/neutrino.h>

int ConnectAttach (int reserved,
                   pid_t pid,
                   int chid,
                   unsigned index,
                   int flags);

ConnectAttach() is given two identifiers: the pid, which is the process ID, and the chid, which is the channel ID. These two IDs, commonly referred to as PID/CHID, uniquely identify the server that the client wants to connect to. We'll ignore the index and flags (just set them to 0).

So, let's assume that we want to connect to process ID 77, channel ID 1. Here's the code sample to do that:
int coid;

coid = ConnectAttach (0, 77, 1, 0, 0);

How did I figure out I wanted to talk to process ID 77 and channel ID 1? We'll see that shortly (see Finding the server's PID/CHID, below).

At this point, I have a connection ID, a small integer that uniquely identifies a connection from my client to a specific channel on a particular server.

I can use this connection ID when sending to the server as many times as I like. When I'm done with it, I can destroy it via:
ConnectDetach (coid);

So let's see how I actually use it.

Page updated: