zoukankan      html  css  js  c++  java
  • RTPConnector实现类RTPJxtaMulticastSocketAdapter的问题

    我底层传输使用JxtaMulticastSocket,以便能在JXTA平台使用JMF的RTP支持。

     在RTPConnector的实现类中有

        /**
         * An inner class to implement an PushSourceStream based on UDP sockets.
         
    */
        class SockInputStream extends Thread implements PushSourceStream {

            JxtaMulticastSocket sock;
            // ... other declariation

            public SockInputStream(JxtaMulticastSocket sock) {
                this.sock = sock;
            }

            @Override
            public int read(byte buffer[], int offset, int length) {
                byte[] buf = new byte[length];
                DatagramPacket p = new DatagramPacket(buf, offset, length);
                try {
                    sock.receive(p);
                    byte[] data = p.getData();
                    System.arraycopy(data, 0, buffer, offset, p.getLength());
                } catch (IOException e) {
                    return -1;
                }
                synchronized (this) {
                    dataRead = true;
                    notify();
                }
                return p.getLength();
            }

            // ... other function ...
        }

     上面是正常的代码,下面贴的是不正常的代码,是我参考其他资料写出的

        /**
         * An inner class to implement an PushSourceStream based on UDP sockets.
         
    */
        class SockInputStream extends Thread implements PushSourceStream {

            DatagramSocket sock;
            // ... other declaration ...

            public SockInputStream(DatagramSocket sock, InetAddress addr, int port) {
                this.sock = sock;
                // ...
            }

            public int read(byte buffer[], int offset, int length) {
                DatagramPacket p = new DatagramPacket(buffer, offset, length, addr, port);
                try {
                    sock.receive(p);
                } catch (IOException e) {
                    return -1;
                }
                synchronized (this) {
                    dataRead = true;
                    notify();
                }
                return p.getLength();
            }

            // ... other function ...
        }

    比较一下可以发现不同之处。

     这个问题让我头疼了2天

  • 相关阅读:
    python线程与进程手记
    3.08课·········switch case及if else嵌套(日期格式)
    3.07课·········if分支语句
    3.06课·········C#语言基础
    3.05课·········进制转换
    Oracle profile 使用技巧
    sys用户密码丢失找回密码的步骤和命令
    oracle帐号scott被锁定如何解锁
    SQL中哪些情况会引起全表扫描
    Oracle创建用户、角色、授权、建表
  • 原文地址:https://www.cnblogs.com/cuizhf/p/2220531.html
Copyright © 2011-2022 走看看