#include <clib/exec_protos.h>
#include <pragmas/exec_pragmas.h>
#include <stdio.h>
#include <strings.h>
#include <clib/rtgextra_protos.h>
#include <pragmas/rtgextra_pragmas.h>
#include <rtgmaster/rtgtcpip.h>
#define UDPDemo 1

// set UDPDemo to 0 if you want to
// compile this demo to use TCP instead
// of UDP

struct Library *SocketBase=0;
struct Library *RTGExtraBase=0;

void makeservaddr(struct sockaddr_in *address, char *host, int port);
struct RTG_Socket *LIBOpenClient(char *host, struct Library *SBase, int port, int mode, int protocol);
struct RTG_Socket rs;

void main()
{
 struct RTG_Socket *s;
 if (RTGExtraBase=OpenLibrary("rtgextra.library",0))
 {
  if (SocketBase=OpenLibrary("bsdsocket.library",4))
  {
   int i;
   long mode=1;
   char buf[1024];
   char *strings[]={"Nur","ein","Test",NULL};

#ifndef UDPDemo
   s=OpenClient(SocketBase,"194.55.101.26",3056,SOCK_STREAM,0);
#else
   s=OpenClient(SocketBase,"194.55.101.26",3056,SOCK_DGRAM,0);
#endif

   RtgIoctl(SocketBase,s,&mode);
   for (i=0;strings[i]!=NULL;i++)
   {
    struct sockaddr_in *si;

    // Note about the following 2 lines : GetUDPName returns
    // 0 for TCP connections, so this code will work for
    // TCP *and* UDP !!!

    si=GetUDPName(SocketBase,s);

    do {} while (RtgSend(SocketBase,s,(strings[i]),si,strlen(strings[i])+1)<=0);
    do {} while (RtgRecv(SocketBase,s,buf,si,1024)<=0);

#ifndef UDPDemo
#else
       printf("Message from : %s",RtgInAdr(SocketBase,si));
#endif

    printf("%s\n",buf);
   }
   CloseClient(SocketBase,s);
   CloseLibrary(SocketBase);
   CloseLibrary(RTGExtraBase);
  }
 }
}

