Quantcast

java.io.IOException: An existing connection was forcibly closed by the remote host

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

java.io.IOException: An existing connection was forcibly closed by the remote host

dragonken
I got this exception but i hv no idea about the root cause.

Please help:

TestServer.java
MyClient.java

output:

13000
14000
15000
Exception in execute ... java.io.IOException: An existing connection was forcibly closed by the remote host
count = 15361
java.io.IOException: An existing connection was forcibly closed by the remote host
        at sun.nio.ch.SocketDispatcher.write0(Native Method)
        at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
        at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
        at sun.nio.ch.IOUtil.write(IOUtil.java:75)
        at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
        at com.sun.grizzly.TCPConnectorHandler.write(TCPConnectorHandler.java:424)
        at test.MyClient.execute(MyClient.java:75)
        at test.MyClient.main(MyClient.java:36)
program exit!

My JDK:
C:\Program Files\Java\jdk1.6.0_06\bin>java -version
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) 64-Bit Server VM (build 10.0-b22, mixed mode)

on Windows XP x64 SP2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.io.IOException: An existing connection was forcibly closed by the remote host

John ROM

> I got this exception but i hv no idea about the root cause.
>
> Please help:
>
> http://www.nabble.com/file/p18739932/TestServer.java TestServer.java
> http://www.nabble.com/file/p18739932/MyClient.java MyClient.java
>

In TestServer.java you need to add Filters to the ProtocolChain. Otherwise
a Protocol chain does not make any sense!? Propably some grizzly timeout or maybe a full
tcp buffer forces the exception
Many Greetings
John






> output:
>
> 13000
> 14000
> 15000
> Exception in execute ... java.io.IOException: An existing connection was
> forcibly closed by the remote host
> count = 15361
> java.io.IOException: An existing connection was forcibly closed by the
> remote host
>         at sun.nio.ch.SocketDispatcher.write0(Native Method)
>         at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
>         at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
>         at sun.nio.ch.IOUtil.write(IOUtil.java:75)
>         at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
>         at
> com.sun.grizzly.TCPConnectorHandler.write(TCPConnectorHandler.java:424)
>         at test.MyClient.execute(MyClient.java:75)
>         at test.MyClient.main(MyClient.java:36)
> program exit!
>
> --
> View this message in context:
> http://www.nabble.com/java.io.IOException%3A-An-existing-connection-was-forcibly-closed-by-the-remote-host-tp18739932p18739932.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.

--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.io.IOException: An existing connection was forcibly closed by the remote host

dragonken
Thanks for your quick response.

Yes, you are correct.

Actually the original problem is, i did add filters but it somehow stop reading / stop parsing / parsing too slow resulting the exception in client side.


John ROM wrote
> I got this exception but i hv no idea about the root cause.
>
> Please help:
>
> http://www.nabble.com/file/p18739932/TestServer.java TestServer.java
> http://www.nabble.com/file/p18739932/MyClient.java MyClient.java
>

In TestServer.java you need to add Filters to the ProtocolChain. Otherwise
a Protocol chain does not make any sense!? Propably some grizzly timeout or maybe a full
tcp buffer forces the exception
Many Greetings
John






> output:
>
> 13000
> 14000
> 15000
> Exception in execute ... java.io.IOException: An existing connection was
> forcibly closed by the remote host
> count = 15361
> java.io.IOException: An existing connection was forcibly closed by the
> remote host
>         at sun.nio.ch.SocketDispatcher.write0(Native Method)
>         at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
>         at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
>         at sun.nio.ch.IOUtil.write(IOUtil.java:75)
>         at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
>         at
> com.sun.grizzly.TCPConnectorHandler.write(TCPConnectorHandler.java:424)
>         at test.MyClient.execute(MyClient.java:75)
>         at test.MyClient.main(MyClient.java:36)
> program exit!
>
> --
> View this message in context:
> http://www.nabble.com/java.io.IOException%3A-An-existing-connection-was-forcibly-closed-by-the-remote-host-tp18739932p18739932.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.

--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@grizzly.dev.java.net
For additional commands, e-mail: users-help@grizzly.dev.java.net
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.io.IOException: An existing connection was forcibly closed by the remote host

John ROM
In reply to this post by dragonken

>
>
> Thanks for your quick response.
>
> Yes, you are correct.
>
> Actually the original problem is, i did add filters but it somehow stop
> reading / stop parsing / parsing too slow resulting the exception in
> client
> side.
if you just add a grizzly ReadFilter your code should work fine so
maybe its a problem with your custom filters?

>
>
>
> John ROM wrote:
> >
> >
> >> I got this exception but i hv no idea about the root cause.
> >>
> >> Please help:
> >>
> >> http://www.nabble.com/file/p18739932/TestServer.java TestServer.java
> >> http://www.nabble.com/file/p18739932/MyClient.java MyClient.java
> >>
> >
> > In TestServer.java you need to add Filters to the ProtocolChain.
> Otherwise
> > a Protocol chain does not make any sense!? Propably some grizzly timeout
> > or maybe a full
> > tcp buffer forces the exception
> > Many Greetings
> > John
> >
> >
> >
> >
> >
> >
> >> output:
> >>
> >> 13000
> >> 14000
> >> 15000
> >> Exception in execute ... java.io.IOException: An existing connection
> was
> >> forcibly closed by the remote host
> >> count = 15361
> >> java.io.IOException: An existing connection was forcibly closed by the
> >> remote host
> >>         at sun.nio.ch.SocketDispatcher.write0(Native Method)
> >>         at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
> >>         at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
> >>         at sun.nio.ch.IOUtil.write(IOUtil.java:75)
> >>         at
> sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
> >>         at
> >> com.sun.grizzly.TCPConnectorHandler.write(TCPConnectorHandler.java:424)
> >>         at test.MyClient.execute(MyClient.java:75)
> >>         at test.MyClient.main(MyClient.java:36)
> >> program exit!
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/java.io.IOException%3A-An-existing-connection-was-forcibly-closed-by-the-remote-host-tp18739932p18739932.html
> >> Sent from the Grizzly - Users mailing list archive at Nabble.com.
> >
> > --
> > Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
> > Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/java.io.IOException%3A-An-existing-connection-was-forcibly-closed-by-the-remote-host-tp18739932p18745961.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]

--
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.io.IOException: An existing connection was forcibly closed by the remote host

dragonken
Thanks for your quick response.

You are correct. I found my ProtocolFilter has bug and will stop parsing after releaseBuffer() is called.

and I feel it really difficult to debug. Pls help.

I wrote a protoclfilter before and did post here.

Oleksiy Stashok helped me to fine tune the code:

MyProcessorFilter.java
MyProtocolParser.java

John ROM wrote
>
>
> Thanks for your quick response.
>
> Yes, you are correct.
>
> Actually the original problem is, i did add filters but it somehow stop
> reading / stop parsing / parsing too slow resulting the exception in
> client
> side.
if you just add a grizzly ReadFilter your code should work fine so
maybe its a problem with your custom filters?

>
>
>
> John ROM wrote:
> >
> >
> >> I got this exception but i hv no idea about the root cause.
> >>
> >> Please help:
> >>
> >> http://www.nabble.com/file/p18739932/TestServer.java TestServer.java
> >> http://www.nabble.com/file/p18739932/MyClient.java MyClient.java
> >>
> >
> > In TestServer.java you need to add Filters to the ProtocolChain.
> Otherwise
> > a Protocol chain does not make any sense!? Propably some grizzly timeout
> > or maybe a full
> > tcp buffer forces the exception
> > Many Greetings
> > John
> >
> >
> >
> >
> >
> >
> >> output:
> >>
> >> 13000
> >> 14000
> >> 15000
> >> Exception in execute ... java.io.IOException: An existing connection
> was
> >> forcibly closed by the remote host
> >> count = 15361
> >> java.io.IOException: An existing connection was forcibly closed by the
> >> remote host
> >>         at sun.nio.ch.SocketDispatcher.write0(Native Method)
> >>         at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
> >>         at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
> >>         at sun.nio.ch.IOUtil.write(IOUtil.java:75)
> >>         at
> sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
> >>         at
> >> com.sun.grizzly.TCPConnectorHandler.write(TCPConnectorHandler.java:424)
> >>         at test.MyClient.execute(MyClient.java:75)
> >>         at test.MyClient.main(MyClient.java:36)
> >> program exit!
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/java.io.IOException%3A-An-existing-connection-was-forcibly-closed-by-the-remote-host-tp18739932p18739932.html
> >> Sent from the Grizzly - Users mailing list archive at Nabble.com.
> >
> > --
> > Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
> > Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@grizzly.dev.java.net
> > For additional commands, e-mail: users-help@grizzly.dev.java.net
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/java.io.IOException%3A-An-existing-connection-was-forcibly-closed-by-the-remote-host-tp18739932p18745961.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@grizzly.dev.java.net
> For additional commands, e-mail: users-help@grizzly.dev.java.net

--
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@grizzly.dev.java.net
For additional commands, e-mail: users-help@grizzly.dev.java.net
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.io.IOException: An existing connection was forcibly closed by the remote host

John ROM
In reply to this post by dragonken

>
> Thanks for your quick response.
>
> You are correct. I found my ProtocolFilter has bug and will stop parsing
> after releaseBuffer() is called.
>
> and I feel it really difficult to debug. Pls help.
>
> I wrote a protoclfilter before and did post here.
>
> Oleksiy Stashok help me to fine tune the code:

Well then it will work (((-:
>
> http://www.nabble.com/file/p18758541/MyProcessorFilter.java
> MyProcessorFilter.java
>

Just to make sure that you have a good setup
and we are discussing the same thing :

On server side you must not add an additional  ReadFilter since
MyParserProtocolFilter already extends ReadFilter so on Server side you have:

ProtocolChain protocolChain = pciHandler.poll();
protocolChain.addFilter(new MyParserProtocolFilter());
protocolChain.addFilter(new MyProcessorFilter());

Since you are plugging a Parser in, which expects a message which starts with byte 0x02
and ends with 0x03 you want to do on client side something like:

ByteBuffer buffer = ByteBuffer.allocate(18);
buffer.put(MyProtocolParser.STX);
buffer.put(  "Test".getBytes());
buffer.put(MyProtocolParser.ETX);
buffer.flip();

well with the above config the codes runs ok on my machine?










>
>
> John ROM wrote:
> >
> >
> >>
> >>
> >> Thanks for your quick response.
> >>
> >> Yes, you are correct.
> >>
> >> Actually the original problem is, i did add filters but it somehow stop
> >> reading / stop parsing / parsing too slow resulting the exception in
> >> client
> >> side.
> > if you just add a grizzly ReadFilter your code should work fine so
> > maybe its a problem with your custom filters?
> >
> >>
> >>
> >>
> >> John ROM wrote:
> >> >
> >> >
> >> >> I got this exception but i hv no idea about the root cause.
> >> >>
> >> >> Please help:
> >> >>
> >> >> http://www.nabble.com/file/p18739932/TestServer.java TestServer.java
> >> >> http://www.nabble.com/file/p18739932/MyClient.java MyClient.java
> >> >>
> >> >
> >> > In TestServer.java you need to add Filters to the ProtocolChain.
> >> Otherwise
> >> > a Protocol chain does not make any sense!? Propably some grizzly
> >> timeout
> >> > or maybe a full
> >> > tcp buffer forces the exception
> >> > Many Greetings
> >> > John
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >> output:
> >> >>
> >> >> 13000
> >> >> 14000
> >> >> 15000
> >> >> Exception in execute ... java.io.IOException: An existing connection
> >> was
> >> >> forcibly closed by the remote host
> >> >> count = 15361
> >> >> java.io.IOException: An existing connection was forcibly closed by
> the
> >> >> remote host
> >> >>         at sun.nio.ch.SocketDispatcher.write0(Native Method)
> >> >>         at
> sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
> >> >>         at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
> >> >>         at sun.nio.ch.IOUtil.write(IOUtil.java:75)
> >> >>         at
> >> sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
> >> >>         at
> >> >>
> >> com.sun.grizzly.TCPConnectorHandler.write(TCPConnectorHandler.java:424)
> >> >>         at test.MyClient.execute(MyClient.java:75)
> >> >>         at test.MyClient.main(MyClient.java:36)
> >> >> program exit!
> >> >>
> >> >> --
> >> >> View this message in context:
> >> >>
> >>
> http://www.nabble.com/java.io.IOException%3A-An-existing-connection-was-forcibly-closed-by-the-remote-host-tp18739932p18739932.html
> >> >> Sent from the Grizzly - Users mailing list archive at Nabble.com.
> >> >
> >> > --
> >> > Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
> >> > Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: [hidden email]
> >> > For additional commands, e-mail: [hidden email]
> >> >
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/java.io.IOException%3A-An-existing-connection-was-forcibly-closed-by-the-remote-host-tp18739932p18745961.html
> >> Sent from the Grizzly - Users mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >
> > --
> > GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry
> > Passion!
> >
> http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
> >

--
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.io.IOException: An existing connection was forcibly closed by the remote host

dragonken
Thanks for you quick response.

It will pause the paser if I the following code as client:

        for (int i = 0; i < 50000; i++) {
            try {
                ByteBuffer buffer = ByteBuffer.allocate(16);
                buffer.put(new byte[]{0x02});
                buffer.putLong(System.currentTimeMillis());
                buffer.put(new byte[]{0x03});
                buffer.flip();
               
                connectorHandler.write(buffer, false);
                Thread.currentThread().sleep(50L);
                if (i%10 == 0) System.out.println("i = " + i);
            } catch (Exception e) {
                System.out.println("Exception in execute ... " + e);
                e.printStackTrace(System.out);
                break;
            }
        }

It seems that some byte value will pause the parser.

Attached my client code:

MyClient.java
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.io.IOException: An existing connection was forcibly closed by the remote host

John ROM
In reply to this post by dragonken
Well yes your absolutely on the right track.

Your parser expects a message that starts with byte 0x2 and ends with 0x3 .
In your testcase with
buffer.putLong(System.currentTimeMillis());
you are sometimes sending two consecutive 0x3 which
break your Protocol.

Then following scenario might happen in  hasNextMessage():

start = -1
pos = 10
savedBuffer.limit()==10

So now  hasNextMessage() == false
and isExpectingMoreData()==false
and hasMoreBytesToParse()== false

This causes Grizzly to not read any bytes of the wire on the selected connection
and your connection seems to pause and eventually because client keeps sending
bytes you see an exception.

if you make sure 0x2 and 0x3 won't be part of your message content you should
be fine...


> Thanks for you quick response.
>
> It will pause the paser if I the following code as client:
>
>         for (int i = 0; i < 50000; i++) {
>             try {
>                 ByteBuffer buffer = ByteBuffer.allocate(16);
>                 buffer.put(new byte[]{0x02});
>                 buffer.putLong(System.currentTimeMillis());
>                 buffer.put(new byte[]{0x03});
>                 buffer.flip();
>                
>                 connectorHandler.write(buffer, false);
>                 Thread.currentThread().sleep(50L);
>                 if (i%10 == 0) System.out.println("i = " + i);
>             } catch (Exception e) {
>                 System.out.println("Exception in execute ... " + e);
>                 e.printStackTrace(System.out);
>                 break;
>             }
>         }
>
> It seems that some byte value will pause the parser.
>
> Attached my client code:
>
> http://www.nabble.com/file/p18776606/MyClient.java MyClient.java
>
> --
> View this message in context:
> http://www.nabble.com/java.io.IOException%3A-An-existing-connection-was-forcibly-closed-by-the-remote-host-tp18739932p18776606.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]

--
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...