Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Net/testserver.cpp

Go to the documentation of this file.
00001 // Wolf for J2K Library
00002 // LGPL Licensed.
00003 // http://j2k.sourceforge.net/
00004 // Revision #1: Fred P. - Oct 2nd, 2001
00005 
00006 #include <stdio.h>
00007 #include <j2k/Net/include.hpp>
00008 #include <j2k/Net/net.hpp>
00009 
00010 
00011 int main( int argc, char** argv )
00012 {
00013   int i = 0;
00014   int n = 0;
00015   char buffer[101];
00016   TcpSocket *ts = NULL;
00017   Socket *s = NULL;
00018   BOOL halt = FALSE;
00019   TcpServerSocket server(12345);
00020 
00021   memset( buffer, 0, 101 );
00022 
00023   if ( argc > 1 )
00024   {
00025    printf( "Launching server... \n " );
00026 //   ServerSocket sserver = (ServerSocket ) server;
00027    printf( "Server launched! \n"  );
00028   }
00029  
00030   printf( "started...\n" );
00031   fflush( stdout ); 
00032 
00033   while( halt != TRUE ) 
00034   {
00035     printf( "#" ); 
00036     fflush( stdout ); 
00037 
00038     s = server.accept();
00039     ts = new TcpSocket(*s);
00040 
00041     printf( "Sent welcome \n" );
00042     fflush( stdout ); 
00043 
00044     ts->send("Welcome to echo server 0.1.0\n(C)Wolf Bergenheim 2001\n",53);
00045     ts->send("This server will echo everything you type back to you\n",54);
00046     ts->send("Send CLOSE to close this connection and HALT to shut down the server\n",69);
00047 
00048     while ( 1 ) 
00049     {
00050       printf( "Reading 100 bytes... \n" );
00051       fflush( stdout ); 
00052 
00053       n = ts->read(buffer, 100);
00054       if (n == -1)
00055         perror("testserver:main:recieve");
00056       if(ts->send(buffer, n) == -1) 
00057       {
00058         perror("testserver:main:recieve");
00059         fprintf(stderr,"Would have sent this:\n");
00060         for(i=0;i<n;i++) 
00061         {
00062           fputc(buffer[i],stderr);
00063         }
00064       }
00065       if(strncmp(buffer,"CLOSE",5) == 0) 
00066       {
00067         ts->close();
00068         break;
00069       }
00070       else if(strncmp(buffer,"HALT",4) == 0) 
00071       {
00072         ts->close();
00073         halt = true;
00074         break;
00075       }
00076       else
00077         memset(buffer,'\0',101);
00078     }
00079   }
00080    
00081   return 0;  
00082 }

Generated on Sun Oct 14 18:46:33 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001