remove a warning about unused variable
[openjpeg.git] / applications / jpip / util / opj_dec_server.c
1 /*
2  * $Id: opj_dec_server.c 54 2011-05-10 13:22:47Z kaori $
3  *
4  * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5  * Copyright (c) 2002-2011, Professor Benoit Macq
6  * Copyright (c) 2010-2011, Kaori Hagihara
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 /*! \file
32  *  \brief opj_dec_server is a server to decode JPT-stream and communicate locally with JPIP client, which is coded in java.
33  *
34  *  \section impinst Implementing instructions
35  *  Launch opj_dec_server from a terminal in the same machine as JPIP client image viewers. \n
36  *   % ./opj_dec_server [portnumber]\n
37  *  ( portnumber=50000 by default)\n
38  *  Keep it alive as long as image viewers are open.\n
39  *
40  *  To quite the opj_dec_server, send a message "quit" through the telnet.\n
41  *   % telnet localhost 50000\n
42  *     quit\n
43  *  Be sure all image viewers are closed.\n
44  *  Cache file in JPT format is stored in the working directly before it quites.
45  *  
46  */
47
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include "openjpip.h"
51
52 #ifdef _WIN32
53 WSADATA initialisation_win32;
54 #endif
55
56 int main(int argc, char *argv[]){
57   
58   dec_server_record_t *server_record;
59   client_t client;
60   int port = 50000;
61   int erreur;
62   (void)erreur;
63
64   if( argc > 1)
65     port = atoi( argv[1]);
66
67 #ifdef _WIN32
68   erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
69   if( erreur!=0)
70     fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
71   else
72     printf( "Initialisation Winsock\n");
73 #endif /*_WIN32*/
74   
75   server_record = init_dec_server( port);
76   
77   while(( client = accept_connection( server_record)) != -1 )
78     if(!handle_clientreq( client, server_record))
79       break;
80   
81   terminate_dec_server( &server_record);
82
83 #ifdef _WIN32
84   if( WSACleanup() != 0){
85     printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
86   }else{
87     printf("\nWSACleanup OK\n");
88   }
89 #endif
90
91   return 0;
92 }