0ad3a0526aacf3369d42263afe4187967ca1d479
[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 \n
37  *  Keep it alive as long as image viewers are open.\n
38  *
39  *  To quite the opj_dec_server, send a message "quit" through the telnet.\n
40  *   % telnet localhost 5000\n
41  *     quit\n
42  *  Be sure all image viewers are closed.\n
43  *  Cache file in JPT format is stored in the working directly before it quites.
44  *  
45  */
46
47 #include <stdio.h>
48 #include "openjpip.h"
49
50 #ifdef _WIN32
51 WSADATA initialisation_win32;
52 #endif
53
54 int main(int argc, char *argv[]){
55   
56   dec_server_record_t *server_record;
57   client_t client;
58
59 #ifdef _WIN32
60   int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
61   if( erreur!=0)
62     fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
63   else
64     printf( "Initialisation Winsock\n");
65 #endif //_WIN32
66   
67   server_record = init_dec_server( 50000);
68   
69   while(( client = accept_connection( server_record)) != -1 )
70     if(!handle_clientreq( client, server_record))
71       break;
72   
73   terminate_dec_server( &server_record);
74
75 #ifdef _WIN32
76   if( WSACleanup() != 0){
77     printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
78   }else{
79     printf("\nWSACleanup OK\n");
80   }
81 #endif
82
83   return 0;
84 }