ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/socket++-1.10/test/commObj.C
Revision: 1.2
Committed: Mon Jun 10 14:10:44 2002 UTC (22 years, 4 months ago) by tdb
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
State: FILE REMOVED
Error occurred while calculating annotation data.
Log Message:
Tidy up of files. These are all old things that are not only no longer used
but are also probably useless to anyone other than us. This saves checking
them out all the time, and makes the "cms/source" tree contain only current
stuff. They'll still exist in the attic's though :)

File Contents

# Content
1 //----------------------------------------------------------------------------
2 // File: Comm-Dvr.cc
3 // Author: Bala Swaminathan 5/19/94
4 // This is a test file for Communication Objects
5 //
6 // Copyright 1994, Washington University in St. Louis
7 //----------------------------------------------------------------------------
8
9 static const char* sscid =
10 "@(#) Comm-Dvr.cc, testing CommObj and CommController, (C) Wustl 1994";
11
12 #define PRO_A_PORT 9999
13 #define PRO_B_PORT 8888
14 #define HOSTNAME "larc"
15
16 void PRO_A();
17 void PRO_B();
18
19 extern "C" {
20 int fork (...);
21 int exit (...);
22 int sleep (...);
23 }
24
25 #include <string.h>
26 #include <iostream.h>
27 #include "commObj.h"
28
29 char *strings[] = {"Santa", "Claus", "Is", "Coming", "To", "Town"};
30
31 const int cMAXMESGDATA = 2040;
32 struct Mesg_New {
33 Mesg_New (const char* s=NULL, int ty = 0) {
34 if (s) init (s, ty); else init ("<default>", ty);
35 }
36 void init (const char* s, int ty = 0) {
37 len = strlen(s);
38 qitem.type = ty;
39 strcpy (qitem.data, s);
40 }
41 void print () {
42 cout << "len = " << len << endl;
43 cout << "struct Q_item" << endl;
44 cout << " type = " << qitem.type << endl
45 << " data = " << (qitem.data[cMAXMESGDATA-1]='\0', qitem.data) << endl;
46 }
47 int len;
48 struct Q_item {
49 int type;
50 char data[cMAXMESGDATA];
51 } qitem;
52 };
53
54 typedef Mesg_New* Mesg_New_Ptr;
55
56 #define SERVSBUF(cc) (cc.server())
57 CommController cc_a (PRO_A_PORT); // create PRIMARY sockets for both
58 CommController cc_b (PRO_B_PORT); // the protocols we are testing.
59
60 main ()
61 {
62 if (fork() == 0) { // child process
63 PRO_B ();
64 exit (10);
65 } else { // parent
66 PRO_A ();
67 exit (5);
68 }
69 }
70
71 void
72 PRO_A ()
73 {
74 Mesg_New mn;
75 cout << "PRO_A: serv.host = " << SERVSBUF(cc_a)->localhost() << endl;
76 cout << "PRO_A: serv.port = " << SERVSBUF(cc_a)->localport() << endl;
77 // using our controller, now accept the connection
78 CommObj co = cc_a.accept();
79 cout << "PRO_A: co.local.host = " << (co).localhost() << endl;
80 cout << "PRO_A: co.local.port = " << (co).localport() << endl;
81 cout << "PRO_A: co.peer.host = " << (co).peerhost() << endl;
82 cout << "PRO_A: co.peer.port = " << (co).peerport() << endl;
83 for (int i=0; i<6; i++) {
84 co.read (&mn, sizeof (mn));
85 cout << "PRO_A receives:--- " << endl;
86 mn.print ();
87 }
88 mn.init ("PRO_A: THE END", 's');
89 co.write (&mn, sizeof (mn));
90 }
91
92 void
93 PRO_B ()
94 {
95 Mesg_New mn;
96 cout << "PRO_B: serv.host = " << SERVSBUF(cc_b)->localhost() << endl;
97 cout << "PRO_B: serv.port = " << SERVSBUF(cc_b)->localport() << endl;
98 // using our controller, let's connect to PRO_A
99 CommObj co;
100 sleep (1);
101 co.connect (HOSTNAME, PRO_A_PORT);
102 cout << "PRO_B: co.local.host = " << (co).localhost() << endl;
103 cout << "PRO_B: co.local.port = " << (co).localport() << endl;
104 cout << "PRO_B: co.peer.host = " << (co).peerhost() << endl;
105 cout << "PRO_B: co.peer.port = " << (co).peerport() << endl;
106 for (int i=0; i<6; i++) {
107 mn.init (strings[i], i);
108 co.write (&mn, sizeof (mn));
109 }
110 co.read (&mn, sizeof (mn));
111 mn.print ();
112 cout << "PRO_B: THE END" << endl;
113 }
114