home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / NWTP04 / XCONN / TSTCONN.PAS < prev    next >
Pascal/Delphi Source File  |  1993-12-29  |  5KB  |  154 lines

  1. {$X+,V-,B-}
  2. Program testconn;
  3.  
  4. { Testprogram for the nwConn unit / NwTP 0.4 API. (c) 1994, R.Spronk }
  5.  
  6. Uses nwMisc,nwConn;
  7.  
  8. Procedure Warning(s:string);
  9. begin
  10. writeln(s);
  11. writeln(' ERROR #: $',HexStr(nwConn.Result,2),' (',nwConn.result,')');
  12. writeln;
  13. writeln('...Press <Enter> to Continue..');
  14. readln;
  15. end;
  16.  
  17. Var myConnNumber:byte;
  18.     myConnId    :byte; { connID of server I'm attached to }
  19.     myNetwNumber:LongInt;
  20.     myPhysNode,myPhysNode2:TnodeAddress;
  21.     mySocket    :word;
  22.     myObjName   :string;
  23.     myObjType   :word;
  24.     myObjId     :longInt;
  25.     myLoginTime :NovTimeRec;
  26.  
  27.     nbrOfConn:byte;
  28.     connList :TconnectionList;
  29.  
  30.     objName  :string;
  31.     objType  :word;
  32.     objId    :LongInt;
  33.     LoginTime:NovTimeRec;
  34.  
  35.     connId    :byte;
  36.     serverName:string;
  37.     routeInfo :string;
  38.  
  39.     t      :byte;
  40.     tempStr:string;
  41.  
  42. begin
  43. IF GetConnectionNumber(myConnNumber)
  44.  then writeln('Your connection number is:',myConnNumber)
  45.  else warning('!!! The GetConnectionNumber call failed');
  46.  
  47. IF GetInterNetAddress(myConnNumber,
  48.                       myNetwNumber,myPhysNode,mySocket)
  49.  then begin
  50.       write('Your Netw.:Node:Socket Nbr is: [$',hexStr(myNetwNumber,8),':');
  51.        for t:=1 to 6 do write(HexStr(myPhysNode[t],2));
  52.       writeln(':',hexstr(mysocket,4),']');
  53.       end
  54.  else warning('!!! GetInterNetAdress failed.');
  55.  
  56.  
  57. IF GetStationAddress(myPhysNode2)
  58.   and (myPhysNode[6]=myPhysNode2[6])
  59.   and (myPhysNode[5]=myPhysNode2[5])
  60.   and (myPhysNode[4]=myPhysNode2[4])
  61.  then { ok }
  62.  else begin
  63.       warning('!!! GetStationadress failed');
  64.       write('returned: $');
  65.         for t:=1 to 6 do write(HexStr(myPhysNode2[t],2));
  66.       end;
  67.  
  68. IF GetConnectionInformation(myConnNumber,
  69.                             myObjName,myObjType,myObjId,myLoginTime)
  70.  then begin
  71.       writeln('You are :',myObjName);
  72.       if myObjType=$1 { OT_USER}
  73.        then writeln(' of object type : USER')
  74.        else writeln(' of object type : $',HexStr(myObjType,4));
  75.       writeln(' with object ID: $',HexStr(myObjId,8));
  76.       NovTimeRec2String(myLoginTime,tempStr);
  77.       writeln(' logged in at ',tempStr);
  78.       end
  79.  else warning('!!! GetConnectionInformation failed.');
  80.  
  81. if NOT (GetUserAtConnection(myConnNumber,tempStr) and (tempStr=myObjName))
  82.  then warning('!!! GetUserAtConnection (2) failed.');
  83.  
  84. IF GetObjectConnectionNumbers(myObjName,1 {OT_USER},
  85.                               nbrOfConn,connList)
  86.  then begin
  87.       writeln('User ',myObjName,' has ',nbrOfConn,' active connection(s).');
  88.       t:=nbrOfConn;
  89.       if t>0
  90.        then begin
  91.             t:=1;
  92.             while t<=nbrOfConn
  93.              do begin
  94.                 writeln('  at connectionNumber:',connList[t]);
  95.                 inc(t);
  96.                 end;
  97.             end;
  98.       end
  99.  else warning('!!! GetObjectConnectionNumbers failed.');
  100.  
  101.  
  102. writeln;
  103. t:=1;
  104. writeln('ConnNbr Name             LoginTime');
  105. WHILE t<250 { nw 3.x / 2.x  100 }
  106. do begin
  107.    IF GetConnectionInformation(t, objName,objType,objId,LoginTime)
  108.     then begin
  109.          PstrCopy(TempStr,objName,15);
  110.          objName:=TempStr;
  111.          NovTimeRec2String(LoginTime,TempStr);
  112.          writeln(t:4,'    ',objName,'  ',TempStr);
  113.          end
  114.     else if nwConn.result<>$FD { bad_station_number / nbr not in use }
  115.          then warning('!!! GetConnectionInformation failed.');
  116.    inc(t);
  117.    end;
  118.  
  119. {*********** connection ID's ( server numbers in server table )************ }
  120.  
  121. { to which server have we been sending all the above requests? }
  122.  
  123. routeInfo:='preferred';
  124. GetPreferredConnectionID(ConnId);
  125.  { if set previously, this server has the highest priority. }
  126.  
  127. if connId=0 { preferred server was not set }
  128.  then begin
  129.       RouteInfo:='default';
  130.       GetDefaultConnectionID(ConnId);
  131.       end;
  132.  { your current default drive is attached to this server }
  133.  
  134. if connId=0
  135.  then begin
  136.       RouteInfo:='primary';
  137.       GetPrimaryConnectionID(ConnId);
  138.       end;
  139.  { the server your shell initially attached to, used if the default drive
  140.    is a local drive. Lowest priority. }
  141.  
  142. { These three calls are also incorporated in the secondary function:
  143.   GetEffectiveConnectionID. }
  144. writeln;
  145. writeln('All requests are routed to the ',RouteInfo,'-server with conn.ID=',connId);
  146.  
  147. GetFileServerName(connId,{out:} serverName);
  148. GetConnectionID(serverName,{out} t);
  149. if t<>connId
  150.  then warning('!!! GetFileServerName and GetConnectionId report different values.')
  151.  else writeln('Name of the server: ',serverName);
  152.  
  153. end.
  154.