RTSPServer.java
上传用户:gmxazy
上传日期:2022-06-06
资源大小:70k
文件大小:2k
- import java.io.*;
- import java.util.*;
- import javax.microedition.io.*;
- /**
- * Very simple RTSP server. It starts up on port 8554 and waits for incoming
- * client connections. Each connection is handled in its own thread.
- */
- public class RTSPServer implements Runnable {
- private boolean running;
-
- /**
- * Socket waiting for a client connection.
- */
- private ServerSocketConnection server;
-
- /**
- * Starts the server running.
- */
- public void start() {
- new Thread(this).start();
- try {
- while (server == null) {
- Thread.sleep(500);
- }
- } catch (Exception e) {}
- }
-
- /**
- * Stops the server.
- */
- public void stop() {
- running = false;
- try {
- server.close();
- } catch (Exception e) {}
- }
-
- /**
- * Server loop, waiting for incoming connections.
- */
- public void run() {
- running = true;
- try {
- server = (ServerSocketConnection) Connector.open("socket://:8554");
-
- while (running) {
- SocketConnection client = (SocketConnection) server.acceptAndOpen();
- dprint("**** Open **** n");
- new RTSPConnection(client);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void dprint(Object obj) {
- System.out.print(obj);
- }
-
- /**
- * Command line test of the server.
- */
- public static void main(String[] args) {
- new RTSPServer().start();
- }
- }