Menu

Sending bytes count == 0

Sergey
2013-02-26
2013-05-17
  • Sergey

    Sergey - 2013-02-26

    I am trying to establish connection between my tablet and pc via Upt sockets using wifi. I have working code written with using simple java Tcp sockets, so I just have changed sockets on udtsockets, but it didn't work!
    I receive 0 bytes on tablet side:
    int read = input.read(bytes); // read  == 0

    Here is my logs:

    26.02.2013 12:20:32 udt.UDTClient <init>
    INFO: Created client endpoint on port 7777
    26.02.2013 12:20:33 udt.UDTSession <init>
    INFO: Using udt.UDTCongestionControl
    26.02.2013 12:20:33 udt.ClientSession <init>
    INFO: Created udt.ClientSession@2efb56b1
    26.02.2013 12:20:33 udt.UDPEndPoint addSession
    INFO: Storing session <199>
    26.02.2013 12:20:33 udt.UDPEndPoint start
    INFO: UDTEndpoint started.
    26.02.2013 12:20:37 udt.ClientSession sendHandShake
    INFO: Sending ConnectionHandshake , mySocketID=199, initialSeqNo=721357864, packetSize=1400, maxFlowWndSize=1024, socketType=1, destSocketID=0]
    26.02.2013 12:20:47 udt.ClientSession sendHandShake
    INFO: Sending ConnectionHandshake , mySocketID=199, initialSeqNo=853667538, packetSize=1400, maxFlowWndSize=1024, socketType=1, destSocketID=0]
    26.02.2013 12:20:47 udt.ClientSession received
    INFO: Received connection handshake from Destination
    ConnectionHandshake
    26.02.2013 12:20:47 udt.UDTSession setState
    INFO: udt.ClientSession@2efb56b1  connection state CHANGED to <2>
    26.02.2013 12:20:47 udt.ClientSession connect
    INFO: Connected, 20 handshake packets sent
    26.02.2013 12:20:47 udt.UDTClient connect
    INFO: The UDTClient is connected
    26.02.2013 12:20:54 udt.UDTSender start
    INFO: Starting sender for udt.ClientSession@2efb56b1

    Android side:

                      UDTServerSocket server = new UDTServerSocket(7777);
                        UDTSocket socket = server.accept();
                        UDTInputStream input = socket.getInputStream();
                        long total = 0;
                        long start = System.currentTimeMillis();
                        byte[] bytes = new byte[1024 * 10]; // 10K
                        // read the data again and again
                        while (true) {
                            int read = input.read(bytes);
                            total += read;
                            long cost = System.currentTimeMillis() - start;
                            if (cost > 1000) {
                                double megaBytes = (total / (1024.0 * 1024));
                                double seconds = (cost / 1000.0);
                                bytesReaded[0] = "Read " + total + " bytes, speed: " + megaBytes / seconds + " MB/s";
                                handler.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        Toast toast = Toast.makeText(getApplicationContext(), bytesReaded[0], Toast.LENGTH_SHORT);
                                        toast.setGravity(Gravity.CENTER, 0, 0);
                                        toast.show();
                                    }
                                });
                                System.out.println(bytesReaded[0]);
                                start = System.currentTimeMillis();
                                total = 0;
                            }
                        }
    

    PC side:

            public static void main(String[] args) throws Exception {
            UDTClient socket = new UDTClient(Inet4Address.getByName("192.168.137.249"), 7777);
            socket.connect("192.168.137.249", 7777);
                UDTOutputStream output = socket.getOutputStream();
                byte[] bytes = new byte[1024 * 10]; // 10K
                for (int i = 0; i < bytes.length; i++) {
                    bytes[i] = 12;
                } // fill the bytes
                // send them again and again
                while (true) {
                    output.write(bytes);
                }
        }
    
     
  • Sergey

    Sergey - 2013-02-26

    Unfortunately I can't test same sample on too pc's because I haven't got second one

     
  • Bernd Schuller

    Bernd Schuller - 2013-02-26

    hi,

    thanks for your interest and sorry that it does not work for you. Your code looks OK of course, maybe you should add
    a "flush() after calling outputStream.write() The UDT sockets do not quite work the same way as normal TCP sockets (especially there is no -1 for End-of-stream!)

    1) are you using the SVN trunk or the latest "release" version? Not sure that trunk is OK, unfortunately I don't have too much time for this project at the moment
    2) does it work for you on the same machine (i.e. two processes on the same PC) ?

     
  • Sergey

    Sergey - 2013-02-26

    I am using udt-java-0.5-SNAPSHOT.jar - last change 2010.09.23
    I also added flush but nothing has changed.

     
  • Sergey

    Sergey - 2013-02-26

    Thank you for quick reply btw=)

     
  • Sergey

    Sergey - 2013-02-26

    I checked out, it is working on same machine in two threads, but test results are horrible. 0.5 MB/s against 159 MB/s by simple tcp. Of course it is not network case at all, but why is such big difference?

     
  • Sergey

    Sergey - 2013-02-26

    Is UDT work's in Wireless Network?

     
  • Bernd Schuller

    Bernd Schuller - 2013-02-26

    hi,

    my experience with wireless networks was also very bad. In a wired network it was better but still nowhere as fast as TCP. The point is that TCP is usually your best choice, because in UDP based protocols (when you need reliable transfer) you have to build the whole reliability layer in (Java) code. The C++ version of UDT is very good and fast, but our Java version is not nearly as good :(

    Summary: if you can use TCP, use it ;)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.