private void doServerWait() { try { rtpTransport.setClientIp(rtspTransport.getClientIp()); rtspTransport.open(); setState(RTSP_STATES.INIT); } catch (IOException e) { RTSPServer.log("I/O exception opening RTSP socket\n"); return; } // Wait for the SETUP message from the client RTSP_METHODS request; boolean done = false; while (!done) { request = rtspTransport.parseRequest(); // blocking if (request == RTSP_METHODS.SETUP) { done = true; setState(RTSP_STATES.READY); rtspTransport.sendResponse(); try { video = new VideoStream(videoName); RTPTransport.open(); } catch (SocketException e) { RTSPServer.log("socket exception creating RTP socket: %s\n", e.getMessage()); return; } catch (FileNotFoundException e) { RTSPServer.log("video file not found: %s\n", e.getMessage()); return; } } } // loop to handle RTSP requests while (true) { request = rtspTransport.parseRequest(); // blocking if ((request == RTSP_METHODS.PLAY) && (getState() == RTSP_STATES.READY)) { rtspTransport.sendResponse(); timer.start(); setState(RTSP_STATES.PLAYING); } else if ((request == RTSP_METHODS.PAUSE) && (getState() == RTSP_STATES.PLAYING)) { rtspTransport.sendResponse(); timer.stop(); setState(RTSP_STATES.READY); } else if (request == RTSP_METHODS.TEARDOWN) { rtspTransport.sendResponse(); timer.stop(); try { rtspTransport.close(); } catch (IOException e) { RTSPServer.log("I/O exception closing RTSP socket: %s\n", e.getMessage()); } RTPTransport.close(); setState(RTSP_STATES.NONE); return; } else if (request == RTSP_METHODS.NONE) { timer.stop(); try { rtspTransport.close(); } catch (IOException e) { RTSPServer.log("I/O exception closing RTSP socket: %s\n", e.getMessage()); } RTPTransport.close(); setState(RTSP_STATES.NONE); RTSPServer.log("client disconnected\n"); return; } } }