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天

  • 相关阅读:
    git在eclipse中的配置 转载
    Java annotation 自定义注释@interface的用法 转载记录
    Java内存溢出的详细解决方案 转载
    sql server 分页、存储过程、视图
    重新认识Asp.Net管道模型
    vim修改替换
    Excel hong
    开始第一次Delphi
    常用正则表达式的网站
    := 赋值语句
  • 原文地址:https://www.cnblogs.com/cuizhf/p/2220531.html
Copyright © 2011-2022 走看看