8 Replies Latest reply: Sep 14, 2012 6:39 PM by EJP RSS

    Setting the PUSH indicator to the data packets

    Muthu Ramasamy
      Hi,

      Am facing some issue with sending the data packets using java Socket programming. The issue is that our (Java)application is sending the data to a server.But in between connection breaks. The network people says that there are packets sent without the PUSH flag by the application. When they look at these their server sends a FIN and eventually an RST flag which resets the connection. That being said since the Java Application in question to send/receive data.

      I have checked the link http://www.faqs.org/rfcs/rfc1122.html 4.2.2.2 Use of Push: RFC-793 Section 2.8. Which suggests that the PUSH will be sent at the end of the data that to be sent(last packet). But they says all the packets should contain the PUSH indicator. So I tried to set using Java API but no method available to set. Can anyone suggest that , how to set the PUSH indicator to the data packets.

      Thanks,
      Muthu
        • 1. Re: Setting the PUSH indicator to the data packets
          jtahlborn
          show some of your sending code. you don't need to be setting any of these flags in your application. you just need to use sockets correctly and it will all work out on the wire.
          • 2. Re: Setting the PUSH indicator to the data packets
            EJP
            The network people says that there are packets sent without the PUSH flag by the application.
            Very likely. There isn't an API for setting the PUSH flag in Java, so it won't be set unless the TCP stack sets it.
            they say all data should contain the PUSH flag.
            The network people are mistaken. The PUSH flag is an option, and in practice it makes little or no difference to TCP processing. Show them the RFC you quoted from. Tell them that Java has never set the PUSH flag, and yet Java has been sending enormous TCP streams all over the world for over sixteen years
            • 3. Re: Setting the PUSH indicator to the data packets
              Muthu Ramasamy
              Thanks for your input. Supposing, I need to change the TCP stack option, is there any possiblity of changing this either at system level etc.,?. i.e using any system level settings for Windows/Linux?.
              • 4. Re: Setting the PUSH indicator to the data packets
                Muthu Ramasamy
                Thanks for your reply, below is my code consolidated snippet.

                Socket socket = new Socket(host, port);     
                socket.setTcpNoDelay(true);
                OutputStream output = new BufferedOutputStream(socket.getOutputStream());
                ByteArrayInputStream byteArray = new ByteArrayInputStream(bytes); // Note : bytes -- Byte array which is holding the huge volume of data.
                byte[] data = new byte[BYTES_PER_ARRAY];
                int off=0;
                int len = -1;
                while((len = byteArray.read(data, off, BYTES_PER_ARRAY)) != -1)
                {
                     output.write(data,off,len);
                }
                output.flush();

                When write operation is happening, in the middle it is disconnected with the exception java.net.SocketException:, But ther is no network disconnection. I dont know how to attach the documents here, If so, I can send you the wireshark tarce routes and some screenshots about the transmitted packets.

                Thanks,
                Muthu
                • 5. Re: Setting the PUSH indicator to the data packets
                  jtahlborn
                  well, for one thing, that bit of code can be consolidated to:
                  Socket socket = new Socket(host, port);
                  socket.setTcpNoDelay(true);
                  OutputStream output = socket.getOutputStream();
                  output.write(bytes);
                  output.flush();
                  also, what exactly is the socketexception that is thrown?
                  • 6. Re: Setting the PUSH indicator to the data packets
                    EJP
                    Supposing, I need to change the TCP stack option
                    You don't. The RFC alone should have convinced you of that, also the complete absence of any Java API.

                    This line of enquiry is a complete waste of time.

                    Supposing, instead, you tell us what the actual problem is, rather than pursuing some else's incorrect diagnosis & solution.
                    in the middle it is disconnected with the exception java.net.SocketException:, But ther is no network disconnection.
                    Now you're just contradicting yourself. Either there is a network disconnect or there isn't. If you got a SocketException, there was a disconnect (unless it was a SocketTimeoutException, which only happens during reading, so that isn't it). Apparently the peer has closed the connection while you were still writing to it. That could be either because you shouldn't be writing at all, i.e. an application protocol mis-implementation between server and client, or maybe the peer has just given up for some reason, for example an upload is too large.

                    I repeat. This has nothing whatsoever to do with the PUSH flag. Anybody who tells you different doesn't know what he is talking about, and should be studiously ignored, and avoided in future.
                    • 7. Re: Setting the PUSH indicator to the data packets
                      Muthu Ramasamy
                      Thank you for the detailed explanation.
                      • 8. Re: Setting the PUSH indicator to the data packets
                        EJP
                        There's a lesson to be learned here. You had Java code and a Java exception, so you should at least have posted all that in the first place. You got led off on a wild goose chase by your network people, which can happen, but you should have started from the beginning here, with your network people's comments as extra information.