AcqServConnThread.java
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:3k
- /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
- Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
- Software license is located in file "COPYING"
- VideoServer application
- $Id: AcqServConnThread.java,v 1.4 1999/01/14 02:41:52 andrew Exp $
- */
- package edu.sunysb.cs.ecsl.videoserver;
- import java.io.*;
- import java.net.*;
- class AcqServConnThread extends Thread implements AcqServProtocol {
- VideoServer parentApplication = null;
- VSProperties properties = null;
- private Socket socket = null;
- private DataOutputStream outputstream = null;
- private BufferedReader inputreader = null;
- AcqServConnThread( VideoServer app, VSProperties props )
- throws UnknownHostException, IOException
- {
- super( "1" );
- parentApplication = app;
- properties = props;
- }
- public void run()
- {
- InetAddress addr = null;
- try
- {
- addr = java.net.InetAddress.getByName
- ( properties.getProperty( properties.AcquisitionServerIP ));
- }
- catch ( java.net.UnknownHostException e )
- {
- parentApplication.log( 0, e.toString() );
- // parentApplication.AcqServConnThreadDie();
- return;
- }
- try
- {
- socket = new Socket( addr, properties.getPropertyInt
- ( properties.AcquisitionServerPort ));
- // set timeout time for all input calls
- socket.setSoTimeout( 100 );
- outputstream = new DataOutputStream( socket.getOutputStream() );
- inputreader = new BufferedReader( new InputStreamReader
- ( socket.getInputStream() ));
- }
- catch ( IOException e )
- {
- parentApplication.log( 0, e.toString() );
- // parentApplication.AcqServConnThreadDie();
- return;
- }
- // inform acq server where to broadcast data.
- try
- {
- setupAcquisitionStream
- ( properties.getProperty
- ( properties.AcquisitionServerBroacastDestIP ),
- properties.getProperty
- ( properties.AcquisitionServerBroacastDestPort ));
- while( true )
- {
- // this call pick-up and parse the command.
- waitForInput();
- }
- }
- catch( Exception e )
- {
- // ends the thread there
- parentApplication.log( 0, e.toString() );
- }
- // parentApplication.AcqServConnThreadDie();
- }
- /** database server informs acquisition server of the push server which
- is interested to receive video stream. If broadcast or multicast is
- needed, this is performed by the push server, not by acquisition
- server
- */
- protected synchronized void setupAcquisitionStream
- ( String ipaddr, String portnum )
- {
- try
- {
- outputstream.writeBytes( _add_acq_stream_[KEY] + "n" );
- outputstream.writeBytes( ipaddr + "n" + portnum + "n" );
- }
- catch( IOException e )
- {
- // if exception occurs, add log record and zero socket
- parentApplication.log( 0, e.toString() );
- try {
- socket.close(); }
- catch( Exception dummy ) {}
- socket = null;
- }
- }
- /** this method lock the thread
- */
- protected synchronized void waitForInput()
- throws IOException
- {
- String command = null;
- try
- {
- command = inputreader.readLine();
- }
- catch( InterruptedIOException e )
- {
- // this means that timeout occurs. Simple exit
- }
- }
- }