home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / filesbbs / os2 / plnk065.arj / PLNK065.ZIP / pilot-link.0.6.5 / test-acceptor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-23  |  2.3 KB  |  80 lines

  1. /* test-acceptor.c: Test a unix-to-unix connection
  2.  *
  3.  * This is free software, licensed under the GNU Public License V2.
  4.  * See the file COPYING for details.
  5.  */
  6.  
  7. /* "Server" and "client" are fuzzy concepts with the Pilot. The Pilot
  8.  * initiates conversation, and the desktop sits passively and listens, so by
  9.  * unix networking standards at least, the desktop is the server and the
  10.  * Pilot is the client. However, once a connection is established the
  11.  * desktop initiates all further actions while the Pilot sits, passively
  12.  * allowing the desktop to rummage through its databases. Thus the desktop
  13.  * could be called a client.
  14.  *
  15.  * All normal Pilot hot-sync programs should be "acceptors" that sit around
  16.  * waiting for a pilot to connect, using the Unix bind/listen/accept
  17.  * sequence. The test-connector companion to this file is effectively a
  18.  * "fake Pilot" that uses connect to simulate a Pilot connecting. Note that
  19.  * either side can transmit and receive data, as long as they agree on which
  20.  * one is going to be talking.
  21.  *
  22.  * This pair of programs use a pty to simulate the first stages of a Pilot
  23.  * communcation -- CMP exchanges, and baud rate matching. Note that a pty is
  24.  * used to let the two programs talk together, and that no attempt has been
  25.  * made to properly allocate a pty.
  26.  *
  27.  * Also note that dlp_AbortSync is used, instead of EndOfSync. That is
  28.  * because the normal EndOfSync proceedings involves sending a padp packet,
  29.  * which would not work as neither side is expecting such a packet.
  30.  *
  31.  */ 
  32.  
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include "pi-source.h"
  36. #include "pi-socket.h"
  37. #include "pi-dlp.h"
  38.  
  39. int main(int argc, char *argv[])
  40. {
  41.   struct pi_sockaddr addr;
  42.   int sd;
  43.   char buffer[64];
  44.   int ret;
  45.  
  46.   if (!(sd = pi_socket(PI_AF_SLP, PI_SOCK_STREAM, PI_PF_PADP))) {
  47.     perror("pi_socket");
  48.     exit(1);
  49.   }
  50.     
  51.   addr.pi_family = PI_AF_SLP;
  52.   addr.pi_port = 3;
  53.   strcpy(addr.pi_device,"/dev/ptyp9"); /* Bogus PTY allocation */
  54.   
  55.   ret = pi_bind(sd, &addr, sizeof(addr));
  56.   if(ret == -1) {
  57.     perror("pi_bind");
  58.     exit(1);
  59.   }
  60.  
  61.   ret = pi_listen(sd, 1);
  62.   if(ret == -1) {
  63.     perror("pi_listen");
  64.     exit(1);
  65.   }
  66.  
  67.   sd = pi_accept(sd, 0, 0);
  68.   if(sd < 0) {
  69.     perror("pi_accept");
  70.     exit(1);
  71.   }
  72.   
  73.   pi_write(sd, "Sent from server", 17 );
  74.   pi_read(sd, buffer, 64);
  75.   puts(buffer);
  76.   
  77.   dlp_AbortSync(sd);
  78.   exit(0);
  79. }
  80.