![](/images/new-backgrounds/1319792/319792307x1.webp)
Sample Programs
Connection Mode
connect_req(send_fd, rcdlsap, rcdlsap_len);
/*
The receiver control stream gets a CONNECT_IND. We need the correlation number to relate the CONNECT_IND to the CONNECT_RES we will send down later.
*/
correlation = connect_ind(recv_c_fd);
/*
We want to handle the actual data transfer over a dedicated receiver stream. Here, we attach and bind a second stream on the receivers sap with max_conind = 0.
*/
recv_d_fd = attach();
bind(recv_d_fd, RECV_SAP, 0, DL_CODLS, rddlsap, &rddlsap_len);
/*
To pass the connection from the control stream to the data stream, we need a token for the data stream. get_token returns this.
*/
token = get_token(recv_d_fd);
/*
Now we do a CONNECT_RES on the control stream. The correlation specifies the CONNECT_IND we are responding to, and the token, since it is
*/
connect_res(recv_c_fd, correlation, token);
/* Get the CONNECT_CON back on the senders stream */ get_msg(send_fd); check_ctrl(DL_CONNECT_CON);
printf(”connection established\n”);
/*
We now have a connection established between the send_fd stream and the recv_d_fd stream. The recv_c_fd stream is in the IDLE state and is ready to process another CONNECT_IND. Since we won't be establishing any new connections, we'll call cleanup on the receiver control stream to unbind, detach, and close the file descriptor.
*/
cleanup(recv_c_fd);
/* Fill in data_area with some data to send. */ for(i = 0; i < 60; i++) {
data_area[i] = i;
}
/* Send 5 packets of data. */ for(i = 0; i < 5; i++) {
put_data(send_fd, (i + 1) * 10);
printf(”sent %d bytes of data\n”, (i + 1) * 10);
}
154 | Appendix A |