home *** CD-ROM | disk | FTP | other *** search
/ Merciful 5 / Merciful - Disc 5.iso / software / r / rtg_master / rtgmasterv21.0dev.lha / demos / network / P2PClient.c next >
Encoding:
C/C++ Source or Header  |  1996-06-28  |  1.6 KB  |  69 lines

  1. #include <clib/exec_protos.h>
  2. #include <pragmas/exec_pragmas.h>
  3. #include <stdio.h>
  4. #include <strings.h>
  5. #include <rtgmaster/rtgmaster.h>
  6. #include <rtgmaster/rtgsublibs.h>
  7. #include <clib/rtgmaster_protos.h>
  8. #include <pragmas/rtgmaster_pragmas.h>
  9. #include <rtgmaster/rtgtcpip.h>
  10. #define UDPDemo 1
  11.  
  12. // set UDPDemo to 0 if you want to
  13. // compile this demo to use TCP instead
  14. // of UDP
  15.  
  16. struct Library *SocketBase=0;
  17. struct Library *RTGMasterBase=0;
  18.  
  19. void makeservaddr(struct sockaddr_in *address, char *host, int port);
  20. struct RTG_Socket *LIBOpenClient(char *host, struct Library *SBase, int port, int mode, int protocol);
  21. struct RTG_Socket rs;
  22.  
  23. void main()
  24. {
  25.  struct RTG_Socket *s;
  26.  if (RTGMasterBase=OpenLibrary("rtgmaster.library",0))
  27.  {
  28.   if (SocketBase=OpenLibrary("bsdsocket.library",4))
  29.   {
  30.    int i;
  31.    long mode=1;
  32.    char buf[1024];
  33.    char *strings[]={"Nur","ein","Test",NULL};
  34.  
  35. #ifndef UDPDemo
  36.    s=OpenClient(SocketBase,"194.55.101.26",3056,SOCK_STREAM,0);
  37. #else
  38.    s=OpenClient(SocketBase,"194.55.101.26",3056,SOCK_DGRAM,0);
  39. #endif
  40.  
  41.    RtgIoctl(SocketBase,s,&mode);
  42.    for (i=0;strings[i]!=NULL;i++)
  43.    {
  44.     struct sockaddr_in *si;
  45.  
  46.     // Note about the following 2 lines : GetUDPName returns
  47.     // 0 for TCP connections, so this code will work for
  48.     // TCP *and* UDP !!!
  49.  
  50.     si=GetUDPName(SocketBase,s);
  51.  
  52.     do {} while (RtgSend(SocketBase,s,(strings[i]),si,strlen(strings[i])+1)<=0);
  53.     do {} while (RtgRecv(SocketBase,s,buf,si,1024)<=0);
  54.  
  55. #ifndef UDPDemo
  56. #else
  57.        printf("Message from : %s",RtgInAdr(SocketBase,si));
  58. #endif
  59.  
  60.     printf("%s\n",buf);
  61.    }
  62.    CloseClient(SocketBase,s);
  63.    CloseLibrary(SocketBase);
  64.    CloseLibrary(RTGMasterBase);
  65.   }
  66.  }
  67. }
  68.  
  69.