English 中文(简体)
我的包裹中是否有一部分落空?
原标题:Is UDP losing part of my packet here?
  • 时间:2012-04-18 18:00:54
  •  标签:
  • java

试图向用户发送一个包裹,告知服务器上的所有人员,如果他们向服务器发出一个“谁”一词的信息。

我的守则是:

else if( response.contains( "who" ) )
{
     System.out.println( "Size of names collection: "+names.size() );

     buf = null;
     buf = names.toString().getBytes();

     int thisPort = packet.getPort();
     packet = new DatagramPacket( buf, buf.length,packet.getAddress(),thisPort );
     socket.send(packet);
}

上文印刷说明的结果表明,有2人,如扔和ja。 现在,在我一揽子计划之后,我会期望它能够这样做:

[Andrew, James]

而客户则得到:

[Andrew,

也是这样。 问题是什么? BTW 我必须为此利用民主力量,并且可以转而转而转而转而去。

<><>>><>>>>>>><>>>>>>

这里是接收包裹的客户类别中的代码:

 while( true )
        {
            try
            {
                // Set the buf to 256 to receive data back from same address and port
                buf = null;
                buf = new byte[256];
                packet = new DatagramPacket(buf, buf.length, address, 4445);
                socket.receive(packet);

                String response = new String( packet.getData() );

                // Receive the packet back
                System.out.println( response );
            }
            catch( IOException e )
            {

            }

        }
最佳回答

你的数据图被压缩到256条带,因为这样会影响你为接收数据表而宣布的缓冲面积。 如果你的数据表能够延长,使缓冲更大。

最佳做法是使其大于预期得到的最大数据表。 那么,如果你收到一刀切的申请书,就会有误。

问题回答

You should check on both client and server the length of the DatagramPacket after the send/receive operation respectively (with the getLength method) to make sure it s the same, that would be the first hint. What Collection are you using for names?

你的问题是不完整的。 然而。

UDP失去包装。 因此,它不可靠地将民主力量用于档案传输目的。obe RTMFP利用UDP传输许多包装材料丢失的视听数据。 但是,与TCP相比,声音/视频内容的流放实际上较快。 我不知道这是否回答了你的问题,我只想说,全国保卫人民大会确实失去了包装。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签