xsocket-develop Mailing List for xsocket (Page 16)
Status: Inactive
Brought to you by:
grro
You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(12) |
Oct
(9) |
Nov
(11) |
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(8) |
Feb
(9) |
Mar
(9) |
Apr
(22) |
May
(28) |
Jun
(17) |
Jul
(10) |
Aug
(19) |
Sep
(4) |
Oct
(14) |
Nov
(26) |
Dec
(25) |
| 2009 |
Jan
(13) |
Feb
(17) |
Mar
(12) |
Apr
(4) |
May
(16) |
Jun
(6) |
Jul
(10) |
Aug
(24) |
Sep
(6) |
Oct
(5) |
Nov
(13) |
Dec
(10) |
| 2010 |
Jan
(17) |
Feb
(21) |
Mar
(10) |
Apr
(8) |
May
(2) |
Jun
(14) |
Jul
(7) |
Aug
(10) |
Sep
(7) |
Oct
(3) |
Nov
|
Dec
(2) |
| 2011 |
Jan
(1) |
Feb
(5) |
Mar
(1) |
Apr
|
May
(5) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
(3) |
Nov
|
Dec
|
| 2015 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
(3) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(6) |
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
|
From: Gregor R. <gre...@go...> - 2008-05-30 06:13:24
|
Hi Jeff,
by implementing the onConnect and onDisconnect method you are able to manage
the open connections. See enclosed example. Does this answer your question?
Gregor
private static final class Test implements IDataHandler, IConnectHandler,
IDisconnectHandler {
private final HashMap<String, INonBlockingConnection> openConnections =
new HashMap<String,INonBlockingConnection>();
public boolean onConnect(INonBlockingConnection connection) throws
IOException, BufferUnderflowException, MaxReadSizeExceededException {
connection.setIdleTimeoutMillis(30 * 60 * 1000); // if not data is
be received within 30 min, the connection will be closed
synchronized (openConnections) {
openConnections.put(connection.getId(), connection);
}
return true;
}
public boolean onDisconnect(INonBlockingConnection connection) throws
IOException {
synchronized (openConnections) {
openConnections.remove(connection.getId());
}
return true;
}
public boolean onData(INonBlockingConnection connection) throws
IOException, BufferUnderflowException, MaxReadSizeExceededException {
…
data = connection.read...
...
send(…);
return true;
}
// will be called concurrently
private void send(Object message) {
HashMap<String, INonBlockingConnection> openConnectionsCopy = null;
synchronized (openConnections) {
openConnectionsCopy = (HashMap<String, INonBlockingConnection>)
openConnections.clone();
}
for (INonBlockingConnection connection :
openConnectionsCopy.values()) {
try {
synchronized (connection) { // connection methods are not
threadsafe
connection.write...
...
}
} catch (IOException ioe) {
synchronized (openConnections) {
openConnections.remove(connection.getId());
}
}
}
}
}
Hi Jeff,
by implementing the onConnect and onDisconnect method you are able to manage
the open connections. See enclosed example. Does this answers your question?
Gregor
private static final class Test implements IDataHandler,
IConnectHandler, IDisconnectHandler {
private final HashMap<String, INonBlockingConnection>
openConnections = new HashMap<String, INonBlockingConnection>();
public boolean onConnect(INonBlockingConnection connection) throws
IOException, BufferUnderflowException, MaxReadSizeExceededException {
connection.setIdleTimeoutMillis(30 * 60 * 1000); // if not data
is be received within 30 min, the connection will be closed
synchronized (openConnections) {
openConnections.put(connection.getId(), connection);
}
return true;
}
public boolean onDisconnect(INonBlockingConnection connection)
throws IOException {
synchronized (openConnections) {
openConnections.remove(connection.getId());
}
return true;
}
public boolean onData(INonBlockingConnection connection) throws
IOException, BufferUnderflowException, MaxReadSizeExceededException {
…
data = connection.read...
...
send(…);
return true;
}
// will be called concurrently
private void send(Object message) {
HashMap<String, INonBlockingConnection> openConnectionsCopy =
null;
synchronized (openConnections) {
openConnectionsCopy = (HashMap<String,
INonBlockingConnection>) openConnections.clone();
}
for (INonBlockingConnection connection :
openConnectionsCopy.values()) {
try {
synchronized (connection) { // connection methods are
not threadsafe
connection.write...
...
}
} catch (IOException ioe) {
synchronized (openConnections) {
openConnections.remove(connection.getId());
}
}
}
}
}
2008/5/29 Jeff Crane <JC...@sp...>:
> I read and implemented the answer to my first question. ConnectionUtil
> held the function and usage.
>
>
>
> Clientside:
>
>
>
> client = new NonBlockingConnection(…);
>
> ByteArrayOutputStream bos = new ByteArrayOutputStream();
>
> ObjectOutputStream out = new ObjectOutputStream(bos);
>
> out.writeObject(genericObj);
>
> out.writeObject(DELIMITER);
>
> client.write(bos.size());
>
> client.write(bos.toByteArray());
>
>
>
>
>
> Server Protocol Handler in onData(…)
>
> int length =
> ConnectionUtils.validateSufficientDatasizeByIntLengthField(connection);
>
> byte[] test = connection.readBytesByDelimiter(DELIMITER,length);
>
>
>
> ByteArrayInputStream bis = new ByteArrayInputStream(test);
>
> ObjectInputStream incomingObjstream = new ObjectInputStream(bis);
>
>
>
> Object incomingObj = null;
>
> try{
>
> incomingObj = incomingObjstream.readObject();
>
> }
>
> catch(ClassNotFoundException e){e.printStackTrace();
>
> }
>
> incomingObjstream.close();
>
>
>
> 2. What is the standard practice to index open connections for sending? I
> use my protocol handler to read the object, handle the object, throw an
> event. If the server wants to disconnect or send a message, how do I do a
> lookup? I could do a singleton HashMap or pass a reference in the event
> thrown (which doesn't help if it's interacting with another connection) or
> am I missing something in the xSocket interfaces?
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|
|
From: Jeff C. <JC...@sp...> - 2008-05-29 20:06:38
|
I read and implemented the answer to my first question. ConnectionUtil held the function and usage.
Clientside:
client = new NonBlockingConnection(...);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(genericObj);
out.writeObject(DELIMITER);
client.write(bos.size());
client.write(bos.toByteArray());
Server Protocol Handler in onData(...)
int length = ConnectionUtils.validateSufficientDatasizeByIntLengthField(connection);
byte[] test = connection.readBytesByDelimiter(DELIMITER,length);
ByteArrayInputStream bis = new ByteArrayInputStream(test);
ObjectInputStream incomingObjstream = new ObjectInputStream(bis);
Object incomingObj = null;
try{
incomingObj = incomingObjstream.readObject();
}
catch(ClassNotFoundException e){e.printStackTrace();
}
incomingObjstream.close();
2. What is the standard practice to index open connections for sending? I use my protocol handler to read the object, handle the object, throw an event. If the server wants to disconnect or send a message, how do I do a lookup? I could do a singleton HashMap or pass a reference in the event thrown (which doesn't help if it's interacting with another connection) or am I missing something in the xSocket interfaces?
|
|
From: Jeff C. <JC...@sp...> - 2008-05-29 18:54:51
|
Hi there. I have had some trouble using xSocket. 2 questions (with associated followups)
I'm using xSocket to transfer serialized objects and the javadocs hint that there's a leaky buffer in the way that I am using it.
Clientside:
client = new NonBlockingConnection(...);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(genericObj);
out.writeObject(DELIMITER);
client.write(bos.toByteArray());
Server Protocol Handler in onData(...)
//TODO: This is the only way I can get it to read. Leaky?
byte[] test = connection.readBytesByDelimiter(DELIMITER);
ByteArrayInputStream bis = new ByteArrayInputStream(test);
ObjectInputStream incomingObjstream = new ObjectInputStream(bis);
Object incomingObj = null;
try{
incomingObj = incomingObjstream.readObject();
}
catch(ClassNotFoundException e){e.printStackTrace();
}
incomingObjstream.close();
1. How do I safely specify the message length before I read it when I don't know the length until I've written it to stream already?
Some type of byte padding which specifies length at the beginning of the message? I'm not sure how to even read that out correctly.
2. What is the standard practice to index open connections for sending? I use my protocol handler to read the object, handle the object, throw an event. If the server wants to disconnect or send a message, how do I do a lookup? I could do a singleton HashMap or pass a reference in the event thrown (which doesn't help if it's interacting with another connection) or am I missing something in the xSocket interfaces?
Apologies in advance if these questions are inappropriate.
|
|
From: Gregor R. <gre...@go...> - 2008-05-28 08:00:14
|
Hi victorxue, unfortunately the UPD tutorial task is still pending :-( The best way to see how to set up a UDP server is to take a look into the unit test code. See http://xsocket.svn.sourceforge.net/viewvc/xsocket/xsocket/core/tags/V2_0/src/test/java/org/xsocket/datagram/ Gregor 2008/5/28 victorxue <vic...@de...>: > hi: > > can anybody tell me how do i establish a udp server using xsocket > framework? > many thanks > 2008-05-28 > ------------------------------ > victorxue > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > > |
|
From: victorxue <vic...@de...> - 2008-05-28 07:40:41
|
hi: can anybody tell me how do i establish a udp server using xsocket framework? many thanks 2008-05-28 victorxue |
|
From: victorxue <vic...@de...> - 2008-05-28 07:22:12
|
hi: can anybody tell me how do i establish a udp server using xsocket framework? many thanks 2008-05-28 victorxue |
|
From: Christian K. <ck...@vx...> - 2008-05-26 12:51:06
|
Hi Gregor,
OK, some testing results:
- last test on production server with 2 incoming DSL connections:
- 400MByte logfile in non-threaded mode and no hang this time :-/
- local test:
- in non-threaded mode: hang after a few seconds
- in multi-threaded mode (default settings, no special worker pool, etc.):
no hang
My assumption would be: fast connection (high data rate, low latency) and
non-threaded
mode in combination with SSL causes some dead lock.
JConsole told me "BLOCKED" for two of three dispatcher Threads at the same
position:
Name: xDispatcherSrv443#1
State: BLOCKED on org.xsocket.connection.IoSSLProcessor@16ac92e owned by:
xDispatcherSrv443#2
Total blocked: 1.822 Total waited: 0
Stack trace:
org.xsocket.connection.IoActivateableSSLHandler.flushOutgoing(IoActivateable
SSLHandler.java:170)
org.xsocket.connection.IoActivateableSSLHandler.write(IoActivateableSSLHandl
er.java:161)
org.xsocket.connection.NonBlockingConnection.internalFlush(NonBlockingConnec
tion.java:1290)
org.xsocket.connection.NonBlockingConnection.onWriteDataInserted(NonBlocking
Connection.java:1166)
org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingSt
ream.java:1109)
That is:
public void flushOutgoing() throws IOException {
if (mode == Mode.SSL) {
synchronized (sslProcessor) {
if (sslProcessor.isHandshaking()) { //<< HERE
...
just calling:
org.xsocket.connection.IoSSLProcessor
<mailto:org.xsocket.connection.IoSSLProcessor@16ac92e> : synchronized
boolean isHandshaking()
using the "always-SSL" mode tracks the problem down here - ending up in the
same function call:
Name: xDispatcherSrv443#1
State: BLOCKED on org.xsocket.connection.IoSSLProcessor@9b04ac owned by:
xDispatcherSrv443#2
Total blocked: 1.859 Total waited: 0
Stack trace:
org.xsocket.connection.IoSSLHandler.flush(IoSSLHandler.java:192)
org.xsocket.connection.IoSSLHandler.write(IoSSLHandler.java:187)
org.xsocket.connection.NonBlockingConnection.internalFlush(NonBlockingConnec
tion.java:1290)
org.xsocket.connection.NonBlockingConnection.onWriteDataInserted(NonBlocking
Connection.java:1166)
org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingSt
ream.java:1109)
Seems to be a race condition.
I'm filing a bug.
The long-term test in multi-threaded mode is still running.
Thanks for your support so far. :-)
Best regards,
Christian
PS: the last log-entries are:
26.05.2008 14:09:35 org.xsocket.connection.IoSSLProcessor decrypt
FEIN: 1890 decrypted data: 02 e0 02 52 00 21 00 20 00 00 00 05 1a f9 7c 03
19 7d 80 4e 19 85 d0 2e 99 d6 0f f0 1a 19 85 02 39 85 f0 0e 99 d6 0f f0 0e
39 85 99 [...snipped...]
e9 00 b6 ff f9 00 [...output has been cut]
26.05.2008 14:09:35 org.xsocket.connection.AbstractMemoryManager newBuffer
FEIN: allocating 16 kb direct memory
26.05.2008 14:09:35 org.xsocket.connection.ReadQueue append
FEIN: buffer added. new read queue size = 1890
26.05.2008 14:09:35 org.xsocket.connection.IoSynchronizedMemoryManager
recycleMemory
FEIN: recycling 16 kb
26.05.2008 14:09:35 org.xsocket.connection.IoSSLProcessor decrypt
FEIN: 18 decrypted data: 05 00 02 dc 00 0b 05 00 02 da 00 10 05 00 02 da 00
11
26.05.2008 14:09:35 org.xsocket.connection.ReadQueue append
FEIN: buffer added. new read queue size = 18
_____
Von: Gregor Roth [mailto:gre...@go...]
Gesendet: Montag, 26. Mai 2008 13:19
An: xSo...@li...
Cc: Christian Kahlo
Betreff: Re: [xSocket-develop] Question: SSL with non-threaded onData()
hangs sometimes
Hi Christian,
have you already tested your code in the multithreaded mode?
If you call the connection methods only within a call back method (thread)
such as onData() or onConnect(), you will not have to synchronize method
calls on the Connection class. xSocket performs the call back methods always
in a serialized for a given connection.
Independent of this, SSL should work in a non threaded mode as well as in a
multi threaded mode. It is recommended to set the FlushMode to ASYCN to
avoid deadlocks. Did you done this?
If this doesn't help, you should file a bug. Please add also a JUnit test
based on your code.
Gregor
2008/5/26 Christian Kahlo <ck...@vx...>:
Hi there,
at first thanks for the good work. I stumbled over xSocket and
instantly loved it. ;)
So, I was starting to write a repeater service using SSL.
That means a client and a server both connect the repeater and
identify themselves either as being client or server and to whom
they belong. The result is a pair of two connections - similar to
the proxy example. (it's all about remote desktop stuff)
Everything is working fine - until some sporadic hang occurs in the
onData handler. Because it is non-threaded the whole server hangs.
The code:
public boolean onData(INonBlockingConnection c)
throws IOException, BufferUnderflowException,
MaxReadSizeExceededException {
Node n = (Node)c.getAttachment();
if(n != null && n.sessionID != null) {
Node n2 = n.server ? viewers.get(n.sessionID) :
servers.get(n.sessionID);
if(n2 != null) {
System.out.print((n2.server ? "S" : "C") +
c.available() + ">");
// before hang #1
ByteBuffer[] data =
c.readByteBufferByLength(c.available());
System.out.print("<" + (n2.server ? "S" :
"C"));
// before hang #2
n2.c.write(data);
System.out.println("#");
}
}
return true;
}
I identified two positions where the code may hang. The write hangs far more
often than the
read. But as I said - sometimes it's running for hours, even days. In
another case it died
within 3 minutes. :(
Could anyone please give me a hint what to watch out for? What to tune?
I supposed some synchronisation cludge with the SSL stack and modified
xSocket, so that I
can deliver my own customized SSLEngine. I forced the connection to use RC4
stream-cipher,
because I thought there may be some length difference issue due to
padding/unpadding when
using a block-cipher - but nothing changed. :-/
Or do I simply _have to_ use multi-threading as soon as I want to have SSL?
Did I understand the other threads correctly, that I would have to
synchronize on the
connection objects for each read and write operation when using
multi-threading?
Thanks in advance.
Best regards,
Christian
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
xSocket-develop mailing list
xSo...@li...
https://lists.sourceforge.net/lists/listinfo/xsocket-develop
|
|
From: Christian K. <ck...@vx...> - 2008-05-26 11:33:34
|
Hi Gregor,
thanks for your fast reply.
I already tried to send an amendment to my last mail (was rejected by list
server):
Sorry, forgot to mention a few important things:
- Connections are in ASYNC mode as tutorial explains
- both nodes can and probably will send data asynchronously at the same time
(no "synchronous" protocol behaviour as seen i.e. in HTTP)
- SSL Layer is the standard JSSE implementation, either 1.5.x or 1.6.x made
no
difference so far
The multi-threaded test-case is on its way. At the moment we're waiting for
the
next hang in non-threaded mode (hope to see something different in the
logs).
Hmm, you say SSL should work in non threaded mode - could it be an issue
(may be
with JVMs SSLEngine) if both nodes are sending a stream of data at the same
time?
I understand that you need a Junit test-case, therefore I would examine the
be-
haviour with two pseudo-clients sending random data to each other
continously.
Best regards,
Christian
________________________________
Von: Gregor Roth [mailto:gre...@go...]
Gesendet: Montag, 26. Mai 2008 13:19
An: xSo...@li...
Cc: Christian Kahlo
Betreff: Re: [xSocket-develop] Question: SSL with non-threaded
onData() hangs sometimes
Hi Christian,
have you already tested your code in the multithreaded mode?
If you call the connection methods only within a call back method
(thread) such as onData() or onConnect(), you will not have to synchronize
method calls on the Connection class. xSocket performs the call back methods
always in a serialized for a given connection.
Independent of this, SSL should work in a non threaded mode as well
as in a multi threaded mode. It is recommended to set the FlushMode to ASYCN
to avoid deadlocks. Did you done this?
If this doesn't help, you should file a bug. Please add also a JUnit
test based on your code.
Gregor
2008/5/26 Christian Kahlo <ck...@vx...>:
Hi there,
at first thanks for the good work. I stumbled over xSocket
and
instantly loved it. ;)
So, I was starting to write a repeater service using SSL.
That means a client and a server both connect the repeater
and
identify themselves either as being client or server and to
whom
they belong. The result is a pair of two connections -
similar to
the proxy example. (it's all about remote desktop stuff)
Everything is working fine - until some sporadic hang occurs
in the
onData handler. Because it is non-threaded the whole server
hangs.
The code:
public boolean onData(INonBlockingConnection c)
throws IOException, BufferUnderflowException,
MaxReadSizeExceededException {
Node n = (Node)c.getAttachment();
if(n != null && n.sessionID != null) {
Node n2 = n.server ?
viewers.get(n.sessionID) :
servers.get(n.sessionID);
if(n2 != null) {
System.out.print((n2.server ?
"S" : "C") +
c.available() + ">");
// before hang #1
ByteBuffer[] data =
c.readByteBufferByLength(c.available());
System.out.print("<" +
(n2.server ? "S" :
"C"));
// before hang #2
n2.c.write(data);
System.out.println("#");
}
}
return true;
}
I identified two positions where the code may hang. The
write hangs far more
often than the
read. But as I said - sometimes it's running for hours, even
days. In
another case it died
within 3 minutes. :(
Could anyone please give me a hint what to watch out for?
What to tune?
I supposed some synchronisation cludge with the SSL stack
and modified
xSocket, so that I
can deliver my own customized SSLEngine. I forced the
connection to use RC4
stream-cipher,
because I thought there may be some length difference issue
due to
padding/unpadding when
using a block-cipher - but nothing changed. :-/
Or do I simply _have to_ use multi-threading as soon as I
want to have SSL?
Did I understand the other threads correctly, that I would
have to
synchronize on the
connection objects for each read and write operation when
using
multi-threading?
Thanks in advance.
Best regards,
Christian
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
xSocket-develop mailing list
xSo...@li...
https://lists.sourceforge.net/lists/listinfo/xsocket-develop
|
|
From: Gregor R. <gre...@go...> - 2008-05-26 11:18:53
|
Hi Christian,
have you already tested your code in the multithreaded mode?
If you call the connection methods only within a call back method (thread)
such as onData() or onConnect(), you will not have to synchronize method
calls on the Connection class. xSocket performs the call back methods always
in a serialized for a given connection.
Independent of this, SSL should work in a non threaded mode as well as in a
multi threaded mode. It is recommended to set the FlushMode to ASYCN to
avoid deadlocks. Did you done this?
If this doesn't help, you should file a bug. Please add also a JUnit test
based on your code.
Gregor
2008/5/26 Christian Kahlo <ck...@vx...>:
>
> Hi there,
>
> at first thanks for the good work. I stumbled over xSocket and
> instantly loved it. ;)
>
> So, I was starting to write a repeater service using SSL.
> That means a client and a server both connect the repeater and
> identify themselves either as being client or server and to whom
> they belong. The result is a pair of two connections - similar to
> the proxy example. (it's all about remote desktop stuff)
>
> Everything is working fine - until some sporadic hang occurs in the
> onData handler. Because it is non-threaded the whole server hangs.
>
> The code:
>
> public boolean onData(INonBlockingConnection c)
> throws IOException, BufferUnderflowException,
> MaxReadSizeExceededException {
> Node n = (Node)c.getAttachment();
>
> if(n != null && n.sessionID != null) {
> Node n2 = n.server ? viewers.get(n.sessionID) :
> servers.get(n.sessionID);
>
> if(n2 != null) {
> System.out.print((n2.server ? "S" : "C") +
> c.available() + ">");
> // before hang #1
> ByteBuffer[] data =
> c.readByteBufferByLength(c.available());
>
> System.out.print("<" + (n2.server ? "S" :
> "C"));
> // before hang #2
> n2.c.write(data);
>
> System.out.println("#");
> }
> }
>
> return true;
> }
>
> I identified two positions where the code may hang. The write hangs far
> more
> often than the
> read. But as I said - sometimes it's running for hours, even days. In
> another case it died
> within 3 minutes. :(
>
> Could anyone please give me a hint what to watch out for? What to tune?
> I supposed some synchronisation cludge with the SSL stack and modified
> xSocket, so that I
> can deliver my own customized SSLEngine. I forced the connection to use RC4
> stream-cipher,
> because I thought there may be some length difference issue due to
> padding/unpadding when
> using a block-cipher - but nothing changed. :-/
>
> Or do I simply _have to_ use multi-threading as soon as I want to have SSL?
> Did I understand the other threads correctly, that I would have to
> synchronize on the
> connection objects for each read and write operation when using
> multi-threading?
>
> Thanks in advance.
>
> Best regards,
> Christian
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
|
|
From: Christian K. <ck...@vx...> - 2008-05-26 10:37:49
|
Hi there,
at first thanks for the good work. I stumbled over xSocket and
instantly loved it. ;)
So, I was starting to write a repeater service using SSL.
That means a client and a server both connect the repeater and
identify themselves either as being client or server and to whom
they belong. The result is a pair of two connections - similar to
the proxy example. (it's all about remote desktop stuff)
Everything is working fine - until some sporadic hang occurs in the
onData handler. Because it is non-threaded the whole server hangs.
The code:
public boolean onData(INonBlockingConnection c)
throws IOException, BufferUnderflowException,
MaxReadSizeExceededException {
Node n = (Node)c.getAttachment();
if(n != null && n.sessionID != null) {
Node n2 = n.server ? viewers.get(n.sessionID) :
servers.get(n.sessionID);
if(n2 != null) {
System.out.print((n2.server ? "S" : "C") +
c.available() + ">");
// before hang #1
ByteBuffer[] data =
c.readByteBufferByLength(c.available());
System.out.print("<" + (n2.server ? "S" :
"C"));
// before hang #2
n2.c.write(data);
System.out.println("#");
}
}
return true;
}
I identified two positions where the code may hang. The write hangs far more
often than the
read. But as I said - sometimes it's running for hours, even days. In
another case it died
within 3 minutes. :(
Could anyone please give me a hint what to watch out for? What to tune?
I supposed some synchronisation cludge with the SSL stack and modified
xSocket, so that I
can deliver my own customized SSLEngine. I forced the connection to use RC4
stream-cipher,
because I thought there may be some length difference issue due to
padding/unpadding when
using a block-cipher - but nothing changed. :-/
Or do I simply _have to_ use multi-threading as soon as I want to have SSL?
Did I understand the other threads correctly, that I would have to
synchronize on the
connection objects for each read and write operation when using
multi-threading?
Thanks in advance.
Best regards,
Christian
|
|
From: Rod M. <rod...@gm...> - 2008-05-14 05:26:10
|
It appears this was indeed the problem as I have been unable to reproduce it
for close to a week now. Sorry for the trouble; really appreciate the quick
response time and support.
Rod
On Tue, May 6, 2008 at 11:59 PM, Rod Magnuson <rod...@gm...> wrote:
> I've swapped in a new router and can't seem to replicate the problem. Let
> me investigate more.
>
> Thanks,
> Rod
>
>
> On Tue, May 6, 2008 at 3:28 PM, Rod Magnuson <rod...@gm...>
> wrote:
>
>> I've discovered that if I make my client go through a domain & port
>> forwarding on my router, as opposed to localHost, I can reproduce the
>> problem in a Java test server to Java test client. Is there any conceivable
>> explanation about how tcp/ip data can get corrupted?
>>
>> Thanks,
>> Rod
>>
>>
>> On Sun, May 4, 2008 at 11:49 PM, Rod Magnuson <rod...@gm...>
>> wrote:
>>
>>> While the synchronizing on the connections eliminated the NPE I saw when
>>> trying to construct a test case, I'm still getting the data corruption
>>> issue. I can't get my Java to Java test case to repro it, so looks like it's
>>> on the Flash side, though it's hard to believe there are issues like this in
>>> XMLSocket. Will continue to investigate.
>>>
>>> Thanks again,
>>> Rod
>>>
>>>
>>> On Sun, May 4, 2008 at 11:38 AM, Rod Magnuson <rod...@gm...>
>>> wrote:
>>>
>>>> Thank you!
>>>>
>>>> The tutorial update was great. Appreciate your help.
>>>>
>>>> Rod
>>>>
>>>>
>>>> On Sun, May 4, 2008 at 1:04 AM, Gregor Roth <gre...@go...>
>>>> wrote:
>>>>
>>>>> Hi Rod,
>>>>>
>>>>> yes, the NonBlockingConnection and BlockingConnection are not thread
>>>>> safe. This means, you have to synchronize concurrent method calls. xSocket
>>>>> only guarantees that the call back methods will be executed in a
>>>>> synchronized, serialized manner.
>>>>>
>>>>> The NullPointerException is caused by unsynchronized, concurrent write
>>>>> calls on the same connection (-> sendMessageToAllClients will be called
>>>>> concurrently) .
>>>>>
>>>>>
>>>>> May be it would make sense to enhance the ConnectionUtils by a
>>>>> synchronizedConnection(INonBlockingConnection nbc) and a
>>>>> synchronizedConnection(IBlockingConnection con) method. But his doesn't help
>>>>> if concurrent threads will execute code like:
>>>>>
>>>>> con.markWritePosition();
>>>>>
>>>>> con.write(..);
>>>>>
>>>>> con.resetToWriteMark();
>>>>>
>>>>>
>>>>> For this reason I'm not sure if it is a good idea to provide
>>>>> synchronized connections. This will give the feeling of thread safety which
>>>>> fails if you using statements like above.
>>>>>
>>>>> I updated the tutorial by this subject
>>>>>
>>>>>
>>>>> Gregor
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> 2008/5/3 Rod Magnuson <rod...@gm...>:
>>>>>
>>>>>> While trying to get a simple test that fails I ran into:
>>>>>>
>>>>>> java.lang.NullPointerException:
>>>>>> Exception in thread "xServerPool-1-thread-8"
>>>>>> java.lang.NullPointerException
>>>>>> at org.xsocket.connection.WriteQueue.append(WriteQueue.java:133)
>>>>>> at
>>>>>> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1060)
>>>>>> at
>>>>>> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1040)
>>>>>> at
>>>>>> testproject.TestServer.sendMessageToAllClients(TestServer.java:73)
>>>>>> at testproject.TestServer.onData(TestServer.java:63)
>>>>>> at
>>>>>> org.xsocket.connection.HandlerAdapter.onData(HandlerAdapter.java:132)
>>>>>> at
>>>>>> org.xsocket.connection.MultithreadedHandlerAdapter.access$201(MultithreadedHandlerAdapter.java:38)
>>>>>> at
>>>>>> org.xsocket.connection.MultithreadedHandlerAdapter$2.run(MultithreadedHandlerAdapter.java:80)
>>>>>> at
>>>>>> org.xsocket.SerializedTaskQueue.performPendingTasks(SerializedTaskQueue.java:113)
>>>>>> at
>>>>>> org.xsocket.SerializedTaskQueue.access$100(SerializedTaskQueue.java:38)
>>>>>> at
>>>>>> org.xsocket.SerializedTaskQueue$MultithreadedTaskProcessor.run(SerializedTaskQueue.java:139)
>>>>>> at
>>>>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
>>>>>> at
>>>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>>>>>> at java.lang.Thread.run(Thread.java:619)
>>>>>>
>>>>>> Which made me think perhaps I'm lacking some basic understanding,
>>>>>> since I see zero synchronization in the call chain down from
>>>>>> connection.write. Am I supposed to provide this synchronization?
>>>>>>
>>>>>> Thanks,
>>>>>> Rod
>>>>>>
>>>>>> Here's what my test server looks like:
>>>>>>
>>>>>> package testproject;
>>>>>>
>>>>>> import java.io.IOException;
>>>>>> import java.io.UnsupportedEncodingException;
>>>>>>
>>>>>> import java.net.SocketTimeoutException;
>>>>>>
>>>>>> import java.nio.channels.ClosedChannelException;
>>>>>>
>>>>>> import java.util.concurrent.ConcurrentHashMap;
>>>>>>
>>>>>> import org.xsocket.connection.ConnectionUtils;
>>>>>> import org.xsocket.connection.IConnectHandler;
>>>>>> import org.xsocket.connection.IConnection;
>>>>>> import org.xsocket.connection.IDataHandler;
>>>>>> import org.xsocket.connection.IDisconnectHandler;
>>>>>> import org.xsocket.connection.INonBlockingConnection;
>>>>>> import org.xsocket.connection.Server;
>>>>>>
>>>>>>
>>>>>> public class TestServer
>>>>>> implements IConnectHandler, IDisconnectHandler, IDataHandler
>>>>>> {
>>>>>> public static final String END_OF_MESSAGE_DELIM = new String(new
>>>>>> char[] { 0 });
>>>>>> // public static final String END_OF_MESSAGE_DELIM = "\r";
>>>>>>
>>>>>> public static void main(String[] args)
>>>>>> {
>>>>>> try
>>>>>> {
>>>>>> final Server server = new Server(6000, new TestServer());
>>>>>> server.setFlushMode(IConnection.FlushMode.ASYNC);
>>>>>>
>>>>>> ConnectionUtils.start(server);
>>>>>> }
>>>>>> catch (Exception e)
>>>>>> {
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> public boolean onConnect(INonBlockingConnection connection)
>>>>>> {
>>>>>> connection.setAutoflush(false);
>>>>>> m_Connections.put(connection, Boolean.TRUE);
>>>>>> return true;
>>>>>> }
>>>>>>
>>>>>> public boolean onDisconnect(INonBlockingConnection connection)
>>>>>> {
>>>>>> m_Connections.remove(connection);
>>>>>> return true;
>>>>>> }
>>>>>>
>>>>>> public boolean onData(INonBlockingConnection connection)
>>>>>> throws IOException, UnsupportedEncodingException
>>>>>> {
>>>>>> // reset to read position (if former reads failed) and mark it
>>>>>> connection.resetToReadMark();
>>>>>> connection.markReadPosition();
>>>>>>
>>>>>> final String message =
>>>>>> connection.readStringByDelimiter(END_OF_MESSAGE_DELIM);
>>>>>>
>>>>>> connection.removeReadMark();
>>>>>>
>>>>>> sendMessageToAllClients("<received>" + message + "</received>");
>>>>>>
>>>>>> return true;
>>>>>> }
>>>>>>
>>>>>> private void sendMessageToAllClients(String message)
>>>>>> throws ClosedChannelException, IOException, SocketTimeoutException
>>>>>> {
>>>>>> for (INonBlockingConnection connection : m_Connections.keySet())
>>>>>> {
>>>>>> connection.write(message + END_OF_MESSAGE_DELIM);
>>>>>> connection.flush();
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> private final ConcurrentHashMap<INonBlockingConnection, Boolean>
>>>>>> m_Connections = new ConcurrentHashMap<INonBlockingConnection, Boolean>();
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>> On Sat, May 3, 2008 at 12:43 AM, Gregor Roth <
>>>>>> gre...@go...> wrote:
>>>>>>
>>>>>>> Hi Rod,
>>>>>>>
>>>>>>> would you please submit this as a bug (
>>>>>>> http://sourceforge.net/tracker/?atid=850942&group_id=169583). Please
>>>>>>> also add a junit test, which contains the essential xSocket-related part of
>>>>>>> your client and server-side code.
>>>>>>>
>>>>>>> Thanks
>>>>>>> Gregor
>>>>>>>
>>>>>>> 2008/5/3 Rod Magnuson <rod...@gm...>:
>>>>>>>
>>>>>>>> I've got a simple server that sends/receives null terminated Strings
>>>>>>>> to/from a flash based client.
>>>>>>>>
>>>>>>>>
>>>>>>>> Flush mode is async.
>>>>>>>>
>>>>>>>> I'm using the 2.0 final jar.
>>>>>>>>
>>>>>>>> I'm seeing times when the client is receiving mangled data. The
>>>>>>>> length of the data is correct, just some of the contents are wrong. This
>>>>>>>> does not happen often and is hard to reproduce. When it does happen other
>>>>>>>> clients receive the correct data.
>>>>>>>>
>>>>>>>> I write out the messages with:
>>>>>>>>
>>>>>>>> String END_OF_MESSAGE_DELIM = new String(new char[] { 0 });
>>>>>>>> connection.write(message + END_OF_MESSAGE_DELIM);
>>>>>>>> connection.flush();
>>>>>>>>
>>>>>>>> It could be either client or server. Ideas on how to disqualify the
>>>>>>>> server?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Rod
>>>>>>>>
>>>>>>>>
>>>>>>>> -------------------------------------------------------------------------
>>>>>>>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>>>>>>>> Don't miss this year's exciting event. There's still time to save
>>>>>>>> $100.
>>>>>>>> Use priority code J8TL2D2.
>>>>>>>>
>>>>>>>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>>>>>>>> _______________________________________________
>>>>>>>> xSocket-develop mailing list
>>>>>>>> xSo...@li...
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> -------------------------------------------------------------------------
>>>>>>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>>>>>>> Don't miss this year's exciting event. There's still time to save
>>>>>>> $100.
>>>>>>> Use priority code J8TL2D2.
>>>>>>>
>>>>>>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>>>>>>> _______________________________________________
>>>>>>> xSocket-develop mailing list
>>>>>>> xSo...@li...
>>>>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
|
|
From: Gregor R. <gre...@go...> - 2008-05-08 10:44:25
|
Hi Ahmad, this is common problem. If plenty of connections will be established and destroyed within a short period of time, the server will run into the Too Many Open Files error. This is caused by the OS. The Too Many Open Files support pattern ( http://support.bea.com/application_content/product_portlets/support_patterns/wls/TooManyOpenFilesPattern.html) describes this problem and how to handle it. For windows take also a look into Tuning Windows ( http://publib.boulder.ibm.com/wasce/V1.0.1/en/Tasks/Tuning/Windows.html) If you can controlthe clients, they should use persistent connections by performing repeated request. On the client-side xSocket supports persistent connections by the ConnectionPool class. Gregor 2008/5/8 Ahmad Zurkarnain <to...@gm...>: > Hello, > > I'm using xSocket 1.x server and currently we have been bombarded with many > request. When I do netstat -na, there are a lot of connections in TIME_WAIT > state. My concern is that our application may run out of connection/socket > soon or later. Is there a way using xsocket to solved this? > > Thank you. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save $100. > Use priority code J8TL2D2. > > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > > |
|
From: Ahmad Z. <to...@gm...> - 2008-05-08 08:46:11
|
Hello, I'm using xSocket 1.x server and currently we have been bombarded with many request. When I do netstat -na, there are a lot of connections in TIME_WAIT state. My concern is that our application may run out of connection/socket soon or later. Is there a way using xsocket to solved this? Thank you. |
|
From: Rod M. <rod...@gm...> - 2008-05-07 14:33:48
|
That makes sense and is how I understood it; I had reread the tutorial and
wanted to make certain nothing ad changed. Thanks.
Rod
On Wed, May 7, 2008 at 12:49 AM, Gregor Roth <gre...@go...>
wrote:
> Hi Rod,
>
> read mark is not necessary if you perform only a single read operation
> within your onData method.
>
> Each read operation on a non blocking connection can cause a
> BufferUnderflowException. If you perform more than one read operation within
> your handling code it is not predicable, if a BufferUnderflowException will
> be thrown and when it will be thrown (by the 1. read operation, 2.te,...).
> This BufferUnderflowException will be swallowed by xSocket
>
> May be it becomes more clear by an example. The first read operation of the
> example code reads a byte. Implicit the byte will be removed from the
> internal xSocket read buffer. By calling the second read operation
> readString a BufferUnderflowException could be thrown.
> The onData method will be called again, if more data is received. By
> calling the onData method the readByte method will be called again. Because
> the byte has already be removed form the read buffer, the first byte of the
> string will be returned.
>
> This behaviour will not appear by using the read mark support.
>
> BadHandler implements IDataHandler {
>
> on Data(NonBlockingConnection nbc) {
>
> byte recordType = nbc.readByte();
>
> String version = nbc.readStringByDelimiter("\r\n");
> String signature = nbc.readStringByDelimiter("\r\n");
> int dataLength = nbc.readInt();
> ...
>
> }
> }
>
>
>
>
>
>
>
> 2008/5/7 Rod Magnuson <rod...@gm...>:
>
>> It looks like the docs have changed since I started using xSocket. My
>> onData implementation does
>>
>> // reset to read position (if former reads failed) and mark it
>> connection.resetToReadMark();
>> connection.markReadPosition();
>>
>> attempt to read datat that may or may not be thee
>>
>> connection.removeReadMark();
>>
>> process the data, only reached if a BufferUnderflowException
>> wasn't throw
>>
>> Is the mark manipulation still necessary?
>>
>> Thanks,
>> Rod
>>
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>> Don't miss this year's exciting event. There's still time to save $100.
>> Use priority code J8TL2D2.
>>
>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>> _______________________________________________
>> xSocket-develop mailing list
>> xSo...@li...
>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>
>>
>
|
|
From: Gregor R. <gre...@go...> - 2008-05-07 07:49:27
|
Hi Rod,
read mark is not necessary if you perform only a single read operation
within your onData method.
Each read operation on a non blocking connection can cause a
BufferUnderflowException. If you perform more than one read operation within
your handling code it is not predicable, if a BufferUnderflowException will
be thrown and when it will be thrown (by the 1. read operation, 2.te,...).
This BufferUnderflowException will be swallowed by xSocket
May be it becomes more clear by an example. The first read operation of the
example code reads a byte. Implicit the byte will be removed from the
internal xSocket read buffer. By calling the second read operation
readString a BufferUnderflowException could be thrown.
The onData method will be called again, if more data is received. By calling
the onData method the readByte method will be called again. Because the byte
has already be removed form the read buffer, the first byte of the string
will be returned.
This behaviour will not appear by using the read mark support.
BadHandler implements IDataHandler {
on Data(NonBlockingConnection nbc) {
byte recordType = nbc.readByte();
String version = nbc.readStringByDelimiter("\r\n");
String signature = nbc.readStringByDelimiter("\r\n");
int dataLength = nbc.readInt();
...
}
}
2008/5/7 Rod Magnuson <rod...@gm...>:
> It looks like the docs have changed since I started using xSocket. My
> onData implementation does
>
> // reset to read position (if former reads failed) and mark it
> connection.resetToReadMark();
> connection.markReadPosition();
>
> attempt to read datat that may or may not be thee
>
> connection.removeReadMark();
>
> process the data, only reached if a BufferUnderflowException
> wasn't throw
>
> Is the mark manipulation still necessary?
>
> Thanks,
> Rod
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
>
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|
|
From: Rod M. <rod...@gm...> - 2008-05-07 07:04:03
|
It looks like the docs have changed since I started using xSocket. My onData
implementation does
// reset to read position (if former reads failed) and mark it
connection.resetToReadMark();
connection.markReadPosition();
attempt to read datat that may or may not be thee
connection.removeReadMark();
process the data, only reached if a BufferUnderflowException wasn't
throw
Is the mark manipulation still necessary?
Thanks,
Rod
|
|
From: Rod M. <rod...@gm...> - 2008-05-07 06:59:40
|
I've swapped in a new router and can't seem to replicate the problem. Let me
investigate more.
Thanks,
Rod
On Tue, May 6, 2008 at 3:28 PM, Rod Magnuson <rod...@gm...> wrote:
> I've discovered that if I make my client go through a domain & port
> forwarding on my router, as opposed to localHost, I can reproduce the
> problem in a Java test server to Java test client. Is there any conceivable
> explanation about how tcp/ip data can get corrupted?
>
> Thanks,
> Rod
>
>
> On Sun, May 4, 2008 at 11:49 PM, Rod Magnuson <rod...@gm...>
> wrote:
>
>> While the synchronizing on the connections eliminated the NPE I saw when
>> trying to construct a test case, I'm still getting the data corruption
>> issue. I can't get my Java to Java test case to repro it, so looks like it's
>> on the Flash side, though it's hard to believe there are issues like this in
>> XMLSocket. Will continue to investigate.
>>
>> Thanks again,
>> Rod
>>
>>
>> On Sun, May 4, 2008 at 11:38 AM, Rod Magnuson <rod...@gm...>
>> wrote:
>>
>>> Thank you!
>>>
>>> The tutorial update was great. Appreciate your help.
>>>
>>> Rod
>>>
>>>
>>> On Sun, May 4, 2008 at 1:04 AM, Gregor Roth <gre...@go...>
>>> wrote:
>>>
>>>> Hi Rod,
>>>>
>>>> yes, the NonBlockingConnection and BlockingConnection are not thread
>>>> safe. This means, you have to synchronize concurrent method calls. xSocket
>>>> only guarantees that the call back methods will be executed in a
>>>> synchronized, serialized manner.
>>>>
>>>> The NullPointerException is caused by unsynchronized, concurrent write
>>>> calls on the same connection (-> sendMessageToAllClients will be called
>>>> concurrently) .
>>>>
>>>>
>>>> May be it would make sense to enhance the ConnectionUtils by a
>>>> synchronizedConnection(INonBlockingConnection nbc) and a
>>>> synchronizedConnection(IBlockingConnection con) method. But his doesn't help
>>>> if concurrent threads will execute code like:
>>>>
>>>> con.markWritePosition();
>>>>
>>>> con.write(..);
>>>>
>>>> con.resetToWriteMark();
>>>>
>>>>
>>>> For this reason I'm not sure if it is a good idea to provide
>>>> synchronized connections. This will give the feeling of thread safety which
>>>> fails if you using statements like above.
>>>>
>>>> I updated the tutorial by this subject
>>>>
>>>>
>>>> Gregor
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> 2008/5/3 Rod Magnuson <rod...@gm...>:
>>>>
>>>>> While trying to get a simple test that fails I ran into:
>>>>>
>>>>> java.lang.NullPointerException:
>>>>> Exception in thread "xServerPool-1-thread-8"
>>>>> java.lang.NullPointerException
>>>>> at org.xsocket.connection.WriteQueue.append(WriteQueue.java:133)
>>>>> at
>>>>> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1060)
>>>>> at
>>>>> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1040)
>>>>> at
>>>>> testproject.TestServer.sendMessageToAllClients(TestServer.java:73)
>>>>> at testproject.TestServer.onData(TestServer.java:63)
>>>>> at
>>>>> org.xsocket.connection.HandlerAdapter.onData(HandlerAdapter.java:132)
>>>>> at
>>>>> org.xsocket.connection.MultithreadedHandlerAdapter.access$201(MultithreadedHandlerAdapter.java:38)
>>>>> at
>>>>> org.xsocket.connection.MultithreadedHandlerAdapter$2.run(MultithreadedHandlerAdapter.java:80)
>>>>> at
>>>>> org.xsocket.SerializedTaskQueue.performPendingTasks(SerializedTaskQueue.java:113)
>>>>> at
>>>>> org.xsocket.SerializedTaskQueue.access$100(SerializedTaskQueue.java:38)
>>>>> at
>>>>> org.xsocket.SerializedTaskQueue$MultithreadedTaskProcessor.run(SerializedTaskQueue.java:139)
>>>>> at
>>>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
>>>>> at
>>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>>>>> at java.lang.Thread.run(Thread.java:619)
>>>>>
>>>>> Which made me think perhaps I'm lacking some basic understanding, since
>>>>> I see zero synchronization in the call chain down from connection.write. Am
>>>>> I supposed to provide this synchronization?
>>>>>
>>>>> Thanks,
>>>>> Rod
>>>>>
>>>>> Here's what my test server looks like:
>>>>>
>>>>> package testproject;
>>>>>
>>>>> import java.io.IOException;
>>>>> import java.io.UnsupportedEncodingException;
>>>>>
>>>>> import java.net.SocketTimeoutException;
>>>>>
>>>>> import java.nio.channels.ClosedChannelException;
>>>>>
>>>>> import java.util.concurrent.ConcurrentHashMap;
>>>>>
>>>>> import org.xsocket.connection.ConnectionUtils;
>>>>> import org.xsocket.connection.IConnectHandler;
>>>>> import org.xsocket.connection.IConnection;
>>>>> import org.xsocket.connection.IDataHandler;
>>>>> import org.xsocket.connection.IDisconnectHandler;
>>>>> import org.xsocket.connection.INonBlockingConnection;
>>>>> import org.xsocket.connection.Server;
>>>>>
>>>>>
>>>>> public class TestServer
>>>>> implements IConnectHandler, IDisconnectHandler, IDataHandler
>>>>> {
>>>>> public static final String END_OF_MESSAGE_DELIM = new String(new
>>>>> char[] { 0 });
>>>>> // public static final String END_OF_MESSAGE_DELIM = "\r";
>>>>>
>>>>> public static void main(String[] args)
>>>>> {
>>>>> try
>>>>> {
>>>>> final Server server = new Server(6000, new TestServer());
>>>>> server.setFlushMode(IConnection.FlushMode.ASYNC);
>>>>>
>>>>> ConnectionUtils.start(server);
>>>>> }
>>>>> catch (Exception e)
>>>>> {
>>>>> e.printStackTrace();
>>>>> }
>>>>> }
>>>>>
>>>>> public boolean onConnect(INonBlockingConnection connection)
>>>>> {
>>>>> connection.setAutoflush(false);
>>>>> m_Connections.put(connection, Boolean.TRUE);
>>>>> return true;
>>>>> }
>>>>>
>>>>> public boolean onDisconnect(INonBlockingConnection connection)
>>>>> {
>>>>> m_Connections.remove(connection);
>>>>> return true;
>>>>> }
>>>>>
>>>>> public boolean onData(INonBlockingConnection connection)
>>>>> throws IOException, UnsupportedEncodingException
>>>>> {
>>>>> // reset to read position (if former reads failed) and mark it
>>>>> connection.resetToReadMark();
>>>>> connection.markReadPosition();
>>>>>
>>>>> final String message =
>>>>> connection.readStringByDelimiter(END_OF_MESSAGE_DELIM);
>>>>>
>>>>> connection.removeReadMark();
>>>>>
>>>>> sendMessageToAllClients("<received>" + message + "</received>");
>>>>>
>>>>> return true;
>>>>> }
>>>>>
>>>>> private void sendMessageToAllClients(String message)
>>>>> throws ClosedChannelException, IOException, SocketTimeoutException
>>>>> {
>>>>> for (INonBlockingConnection connection : m_Connections.keySet())
>>>>> {
>>>>> connection.write(message + END_OF_MESSAGE_DELIM);
>>>>> connection.flush();
>>>>> }
>>>>> }
>>>>>
>>>>> private final ConcurrentHashMap<INonBlockingConnection, Boolean>
>>>>> m_Connections = new ConcurrentHashMap<INonBlockingConnection, Boolean>();
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> On Sat, May 3, 2008 at 12:43 AM, Gregor Roth <
>>>>> gre...@go...> wrote:
>>>>>
>>>>>> Hi Rod,
>>>>>>
>>>>>> would you please submit this as a bug (
>>>>>> http://sourceforge.net/tracker/?atid=850942&group_id=169583). Please
>>>>>> also add a junit test, which contains the essential xSocket-related part of
>>>>>> your client and server-side code.
>>>>>>
>>>>>> Thanks
>>>>>> Gregor
>>>>>>
>>>>>> 2008/5/3 Rod Magnuson <rod...@gm...>:
>>>>>>
>>>>>>> I've got a simple server that sends/receives null terminated Strings
>>>>>>> to/from a flash based client.
>>>>>>>
>>>>>>>
>>>>>>> Flush mode is async.
>>>>>>>
>>>>>>> I'm using the 2.0 final jar.
>>>>>>>
>>>>>>> I'm seeing times when the client is receiving mangled data. The
>>>>>>> length of the data is correct, just some of the contents are wrong. This
>>>>>>> does not happen often and is hard to reproduce. When it does happen other
>>>>>>> clients receive the correct data.
>>>>>>>
>>>>>>> I write out the messages with:
>>>>>>>
>>>>>>> String END_OF_MESSAGE_DELIM = new String(new char[] { 0 });
>>>>>>> connection.write(message + END_OF_MESSAGE_DELIM);
>>>>>>> connection.flush();
>>>>>>>
>>>>>>> It could be either client or server. Ideas on how to disqualify the
>>>>>>> server?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Rod
>>>>>>>
>>>>>>>
>>>>>>> -------------------------------------------------------------------------
>>>>>>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>>>>>>> Don't miss this year's exciting event. There's still time to save
>>>>>>> $100.
>>>>>>> Use priority code J8TL2D2.
>>>>>>>
>>>>>>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>>>>>>> _______________________________________________
>>>>>>> xSocket-develop mailing list
>>>>>>> xSo...@li...
>>>>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> -------------------------------------------------------------------------
>>>>>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>>>>>> Don't miss this year's exciting event. There's still time to save
>>>>>> $100.
>>>>>> Use priority code J8TL2D2.
>>>>>>
>>>>>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>>>>>> _______________________________________________
>>>>>> xSocket-develop mailing list
>>>>>> xSo...@li...
>>>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
|
|
From: Rod M. <rod...@gm...> - 2008-05-06 22:28:11
|
I've discovered that if I make my client go through a domain & port
forwarding on my router, as opposed to localHost, I can reproduce the
problem in a Java test server to Java test client. Is there any conceivable
explanation about how tcp/ip data can get corrupted?
Thanks,
Rod
On Sun, May 4, 2008 at 11:49 PM, Rod Magnuson <rod...@gm...> wrote:
> While the synchronizing on the connections eliminated the NPE I saw when
> trying to construct a test case, I'm still getting the data corruption
> issue. I can't get my Java to Java test case to repro it, so looks like it's
> on the Flash side, though it's hard to believe there are issues like this in
> XMLSocket. Will continue to investigate.
>
> Thanks again,
> Rod
>
>
> On Sun, May 4, 2008 at 11:38 AM, Rod Magnuson <rod...@gm...>
> wrote:
>
>> Thank you!
>>
>> The tutorial update was great. Appreciate your help.
>>
>> Rod
>>
>>
>> On Sun, May 4, 2008 at 1:04 AM, Gregor Roth <gre...@go...>
>> wrote:
>>
>>> Hi Rod,
>>>
>>> yes, the NonBlockingConnection and BlockingConnection are not thread
>>> safe. This means, you have to synchronize concurrent method calls. xSocket
>>> only guarantees that the call back methods will be executed in a
>>> synchronized, serialized manner.
>>>
>>> The NullPointerException is caused by unsynchronized, concurrent write
>>> calls on the same connection (-> sendMessageToAllClients will be called
>>> concurrently) .
>>>
>>>
>>> May be it would make sense to enhance the ConnectionUtils by a
>>> synchronizedConnection(INonBlockingConnection nbc) and a
>>> synchronizedConnection(IBlockingConnection con) method. But his doesn't help
>>> if concurrent threads will execute code like:
>>>
>>> con.markWritePosition();
>>>
>>> con.write(..);
>>>
>>> con.resetToWriteMark();
>>>
>>>
>>> For this reason I'm not sure if it is a good idea to provide synchronized
>>> connections. This will give the feeling of thread safety which fails if you
>>> using statements like above.
>>>
>>> I updated the tutorial by this subject
>>>
>>>
>>> Gregor
>>>
>>>
>>>
>>>
>>>
>>>
>>> 2008/5/3 Rod Magnuson <rod...@gm...>:
>>>
>>>> While trying to get a simple test that fails I ran into:
>>>>
>>>> java.lang.NullPointerException:
>>>> Exception in thread "xServerPool-1-thread-8"
>>>> java.lang.NullPointerException
>>>> at org.xsocket.connection.WriteQueue.append(WriteQueue.java:133)
>>>> at
>>>> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1060)
>>>> at
>>>> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1040)
>>>> at
>>>> testproject.TestServer.sendMessageToAllClients(TestServer.java:73)
>>>> at testproject.TestServer.onData(TestServer.java:63)
>>>> at
>>>> org.xsocket.connection.HandlerAdapter.onData(HandlerAdapter.java:132)
>>>> at
>>>> org.xsocket.connection.MultithreadedHandlerAdapter.access$201(MultithreadedHandlerAdapter.java:38)
>>>> at
>>>> org.xsocket.connection.MultithreadedHandlerAdapter$2.run(MultithreadedHandlerAdapter.java:80)
>>>> at
>>>> org.xsocket.SerializedTaskQueue.performPendingTasks(SerializedTaskQueue.java:113)
>>>> at
>>>> org.xsocket.SerializedTaskQueue.access$100(SerializedTaskQueue.java:38)
>>>> at
>>>> org.xsocket.SerializedTaskQueue$MultithreadedTaskProcessor.run(SerializedTaskQueue.java:139)
>>>> at
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
>>>> at
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>>>> at java.lang.Thread.run(Thread.java:619)
>>>>
>>>> Which made me think perhaps I'm lacking some basic understanding, since
>>>> I see zero synchronization in the call chain down from connection.write. Am
>>>> I supposed to provide this synchronization?
>>>>
>>>> Thanks,
>>>> Rod
>>>>
>>>> Here's what my test server looks like:
>>>>
>>>> package testproject;
>>>>
>>>> import java.io.IOException;
>>>> import java.io.UnsupportedEncodingException;
>>>>
>>>> import java.net.SocketTimeoutException;
>>>>
>>>> import java.nio.channels.ClosedChannelException;
>>>>
>>>> import java.util.concurrent.ConcurrentHashMap;
>>>>
>>>> import org.xsocket.connection.ConnectionUtils;
>>>> import org.xsocket.connection.IConnectHandler;
>>>> import org.xsocket.connection.IConnection;
>>>> import org.xsocket.connection.IDataHandler;
>>>> import org.xsocket.connection.IDisconnectHandler;
>>>> import org.xsocket.connection.INonBlockingConnection;
>>>> import org.xsocket.connection.Server;
>>>>
>>>>
>>>> public class TestServer
>>>> implements IConnectHandler, IDisconnectHandler, IDataHandler
>>>> {
>>>> public static final String END_OF_MESSAGE_DELIM = new String(new
>>>> char[] { 0 });
>>>> // public static final String END_OF_MESSAGE_DELIM = "\r";
>>>>
>>>> public static void main(String[] args)
>>>> {
>>>> try
>>>> {
>>>> final Server server = new Server(6000, new TestServer());
>>>> server.setFlushMode(IConnection.FlushMode.ASYNC);
>>>>
>>>> ConnectionUtils.start(server);
>>>> }
>>>> catch (Exception e)
>>>> {
>>>> e.printStackTrace();
>>>> }
>>>> }
>>>>
>>>> public boolean onConnect(INonBlockingConnection connection)
>>>> {
>>>> connection.setAutoflush(false);
>>>> m_Connections.put(connection, Boolean.TRUE);
>>>> return true;
>>>> }
>>>>
>>>> public boolean onDisconnect(INonBlockingConnection connection)
>>>> {
>>>> m_Connections.remove(connection);
>>>> return true;
>>>> }
>>>>
>>>> public boolean onData(INonBlockingConnection connection)
>>>> throws IOException, UnsupportedEncodingException
>>>> {
>>>> // reset to read position (if former reads failed) and mark it
>>>> connection.resetToReadMark();
>>>> connection.markReadPosition();
>>>>
>>>> final String message =
>>>> connection.readStringByDelimiter(END_OF_MESSAGE_DELIM);
>>>>
>>>> connection.removeReadMark();
>>>>
>>>> sendMessageToAllClients("<received>" + message + "</received>");
>>>>
>>>> return true;
>>>> }
>>>>
>>>> private void sendMessageToAllClients(String message)
>>>> throws ClosedChannelException, IOException, SocketTimeoutException
>>>> {
>>>> for (INonBlockingConnection connection : m_Connections.keySet())
>>>> {
>>>> connection.write(message + END_OF_MESSAGE_DELIM);
>>>> connection.flush();
>>>> }
>>>> }
>>>>
>>>> private final ConcurrentHashMap<INonBlockingConnection, Boolean>
>>>> m_Connections = new ConcurrentHashMap<INonBlockingConnection, Boolean>();
>>>>
>>>> }
>>>>
>>>>
>>>> On Sat, May 3, 2008 at 12:43 AM, Gregor Roth <
>>>> gre...@go...> wrote:
>>>>
>>>>> Hi Rod,
>>>>>
>>>>> would you please submit this as a bug (
>>>>> http://sourceforge.net/tracker/?atid=850942&group_id=169583). Please
>>>>> also add a junit test, which contains the essential xSocket-related part of
>>>>> your client and server-side code.
>>>>>
>>>>> Thanks
>>>>> Gregor
>>>>>
>>>>> 2008/5/3 Rod Magnuson <rod...@gm...>:
>>>>>
>>>>>> I've got a simple server that sends/receives null terminated Strings
>>>>>> to/from a flash based client.
>>>>>>
>>>>>>
>>>>>> Flush mode is async.
>>>>>>
>>>>>> I'm using the 2.0 final jar.
>>>>>>
>>>>>> I'm seeing times when the client is receiving mangled data. The length
>>>>>> of the data is correct, just some of the contents are wrong. This does not
>>>>>> happen often and is hard to reproduce. When it does happen other clients
>>>>>> receive the correct data.
>>>>>>
>>>>>> I write out the messages with:
>>>>>>
>>>>>> String END_OF_MESSAGE_DELIM = new String(new char[] { 0 });
>>>>>> connection.write(message + END_OF_MESSAGE_DELIM);
>>>>>> connection.flush();
>>>>>>
>>>>>> It could be either client or server. Ideas on how to disqualify the
>>>>>> server?
>>>>>>
>>>>>> Thanks,
>>>>>> Rod
>>>>>>
>>>>>>
>>>>>> -------------------------------------------------------------------------
>>>>>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>>>>>> Don't miss this year's exciting event. There's still time to save
>>>>>> $100.
>>>>>> Use priority code J8TL2D2.
>>>>>>
>>>>>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>>>>>> _______________________________________________
>>>>>> xSocket-develop mailing list
>>>>>> xSo...@li...
>>>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> -------------------------------------------------------------------------
>>>>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>>>>> Don't miss this year's exciting event. There's still time to save $100.
>>>>> Use priority code J8TL2D2.
>>>>>
>>>>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>>>>> _______________________________________________
>>>>> xSocket-develop mailing list
>>>>> xSo...@li...
>>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>>>>
>>>>>
>>>>
>>>
>>
>
|
|
From: Rod M. <rod...@gm...> - 2008-05-05 06:49:14
|
While the synchronizing on the connections eliminated the NPE I saw when
trying to construct a test case, I'm still getting the data corruption
issue. I can't get my Java to Java test case to repro it, so looks like it's
on the Flash side, though it's hard to believe there are issues like this in
XMLSocket. Will continue to investigate.
Thanks again,
Rod
On Sun, May 4, 2008 at 11:38 AM, Rod Magnuson <rod...@gm...> wrote:
> Thank you!
>
> The tutorial update was great. Appreciate your help.
>
> Rod
>
>
> On Sun, May 4, 2008 at 1:04 AM, Gregor Roth <gre...@go...>
> wrote:
>
>> Hi Rod,
>>
>> yes, the NonBlockingConnection and BlockingConnection are not thread safe.
>> This means, you have to synchronize concurrent method calls. xSocket only
>> guarantees that the call back methods will be executed in a synchronized,
>> serialized manner.
>>
>> The NullPointerException is caused by unsynchronized, concurrent write
>> calls on the same connection (-> sendMessageToAllClients will be called
>> concurrently) .
>>
>>
>> May be it would make sense to enhance the ConnectionUtils by a
>> synchronizedConnection(INonBlockingConnection nbc) and a
>> synchronizedConnection(IBlockingConnection con) method. But his doesn't help
>> if concurrent threads will execute code like:
>>
>> con.markWritePosition();
>>
>> con.write(..);
>>
>> con.resetToWriteMark();
>>
>>
>> For this reason I'm not sure if it is a good idea to provide synchronized
>> connections. This will give the feeling of thread safety which fails if you
>> using statements like above.
>>
>> I updated the tutorial by this subject
>>
>>
>> Gregor
>>
>>
>>
>>
>>
>>
>> 2008/5/3 Rod Magnuson <rod...@gm...>:
>>
>>> While trying to get a simple test that fails I ran into:
>>>
>>> java.lang.NullPointerException:
>>> Exception in thread "xServerPool-1-thread-8"
>>> java.lang.NullPointerException
>>> at org.xsocket.connection.WriteQueue.append(WriteQueue.java:133)
>>> at
>>> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1060)
>>> at
>>> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1040)
>>> at testproject.TestServer.sendMessageToAllClients(TestServer.java:73)
>>> at testproject.TestServer.onData(TestServer.java:63)
>>> at
>>> org.xsocket.connection.HandlerAdapter.onData(HandlerAdapter.java:132)
>>> at
>>> org.xsocket.connection.MultithreadedHandlerAdapter.access$201(MultithreadedHandlerAdapter.java:38)
>>> at
>>> org.xsocket.connection.MultithreadedHandlerAdapter$2.run(MultithreadedHandlerAdapter.java:80)
>>> at
>>> org.xsocket.SerializedTaskQueue.performPendingTasks(SerializedTaskQueue.java:113)
>>> at
>>> org.xsocket.SerializedTaskQueue.access$100(SerializedTaskQueue.java:38)
>>> at
>>> org.xsocket.SerializedTaskQueue$MultithreadedTaskProcessor.run(SerializedTaskQueue.java:139)
>>> at
>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
>>> at
>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>>> at java.lang.Thread.run(Thread.java:619)
>>>
>>> Which made me think perhaps I'm lacking some basic understanding, since I
>>> see zero synchronization in the call chain down from connection.write. Am I
>>> supposed to provide this synchronization?
>>>
>>> Thanks,
>>> Rod
>>>
>>> Here's what my test server looks like:
>>>
>>> package testproject;
>>>
>>> import java.io.IOException;
>>> import java.io.UnsupportedEncodingException;
>>>
>>> import java.net.SocketTimeoutException;
>>>
>>> import java.nio.channels.ClosedChannelException;
>>>
>>> import java.util.concurrent.ConcurrentHashMap;
>>>
>>> import org.xsocket.connection.ConnectionUtils;
>>> import org.xsocket.connection.IConnectHandler;
>>> import org.xsocket.connection.IConnection;
>>> import org.xsocket.connection.IDataHandler;
>>> import org.xsocket.connection.IDisconnectHandler;
>>> import org.xsocket.connection.INonBlockingConnection;
>>> import org.xsocket.connection.Server;
>>>
>>>
>>> public class TestServer
>>> implements IConnectHandler, IDisconnectHandler, IDataHandler
>>> {
>>> public static final String END_OF_MESSAGE_DELIM = new String(new char[]
>>> { 0 });
>>> // public static final String END_OF_MESSAGE_DELIM = "\r";
>>>
>>> public static void main(String[] args)
>>> {
>>> try
>>> {
>>> final Server server = new Server(6000, new TestServer());
>>> server.setFlushMode(IConnection.FlushMode.ASYNC);
>>>
>>> ConnectionUtils.start(server);
>>> }
>>> catch (Exception e)
>>> {
>>> e.printStackTrace();
>>> }
>>> }
>>>
>>> public boolean onConnect(INonBlockingConnection connection)
>>> {
>>> connection.setAutoflush(false);
>>> m_Connections.put(connection, Boolean.TRUE);
>>> return true;
>>> }
>>>
>>> public boolean onDisconnect(INonBlockingConnection connection)
>>> {
>>> m_Connections.remove(connection);
>>> return true;
>>> }
>>>
>>> public boolean onData(INonBlockingConnection connection)
>>> throws IOException, UnsupportedEncodingException
>>> {
>>> // reset to read position (if former reads failed) and mark it
>>> connection.resetToReadMark();
>>> connection.markReadPosition();
>>>
>>> final String message =
>>> connection.readStringByDelimiter(END_OF_MESSAGE_DELIM);
>>>
>>> connection.removeReadMark();
>>>
>>> sendMessageToAllClients("<received>" + message + "</received>");
>>>
>>> return true;
>>> }
>>>
>>> private void sendMessageToAllClients(String message)
>>> throws ClosedChannelException, IOException, SocketTimeoutException
>>> {
>>> for (INonBlockingConnection connection : m_Connections.keySet())
>>> {
>>> connection.write(message + END_OF_MESSAGE_DELIM);
>>> connection.flush();
>>> }
>>> }
>>>
>>> private final ConcurrentHashMap<INonBlockingConnection, Boolean>
>>> m_Connections = new ConcurrentHashMap<INonBlockingConnection, Boolean>();
>>>
>>> }
>>>
>>>
>>> On Sat, May 3, 2008 at 12:43 AM, Gregor Roth <gre...@go...>
>>> wrote:
>>>
>>>> Hi Rod,
>>>>
>>>> would you please submit this as a bug (
>>>> http://sourceforge.net/tracker/?atid=850942&group_id=169583). Please
>>>> also add a junit test, which contains the essential xSocket-related part of
>>>> your client and server-side code.
>>>>
>>>> Thanks
>>>> Gregor
>>>>
>>>> 2008/5/3 Rod Magnuson <rod...@gm...>:
>>>>
>>>>> I've got a simple server that sends/receives null terminated Strings
>>>>> to/from a flash based client.
>>>>>
>>>>>
>>>>> Flush mode is async.
>>>>>
>>>>> I'm using the 2.0 final jar.
>>>>>
>>>>> I'm seeing times when the client is receiving mangled data. The length
>>>>> of the data is correct, just some of the contents are wrong. This does not
>>>>> happen often and is hard to reproduce. When it does happen other clients
>>>>> receive the correct data.
>>>>>
>>>>> I write out the messages with:
>>>>>
>>>>> String END_OF_MESSAGE_DELIM = new String(new char[] { 0 });
>>>>> connection.write(message + END_OF_MESSAGE_DELIM);
>>>>> connection.flush();
>>>>>
>>>>> It could be either client or server. Ideas on how to disqualify the
>>>>> server?
>>>>>
>>>>> Thanks,
>>>>> Rod
>>>>>
>>>>>
>>>>> -------------------------------------------------------------------------
>>>>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>>>>> Don't miss this year's exciting event. There's still time to save $100.
>>>>> Use priority code J8TL2D2.
>>>>>
>>>>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>>>>> _______________________________________________
>>>>> xSocket-develop mailing list
>>>>> xSo...@li...
>>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>>>>
>>>>>
>>>>
>>>>
>>>> -------------------------------------------------------------------------
>>>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>>>> Don't miss this year's exciting event. There's still time to save $100.
>>>> Use priority code J8TL2D2.
>>>>
>>>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>>>> _______________________________________________
>>>> xSocket-develop mailing list
>>>> xSo...@li...
>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>>>
>>>>
>>>
>>
>
|
|
From: Rod M. <rod...@gm...> - 2008-05-04 18:38:01
|
Thank you!
The tutorial update was great. Appreciate your help.
Rod
On Sun, May 4, 2008 at 1:04 AM, Gregor Roth <gre...@go...>
wrote:
> Hi Rod,
>
> yes, the NonBlockingConnection and BlockingConnection are not thread safe.
> This means, you have to synchronize concurrent method calls. xSocket only
> guarantees that the call back methods will be executed in a synchronized,
> serialized manner.
>
> The NullPointerException is caused by unsynchronized, concurrent write
> calls on the same connection (-> sendMessageToAllClients will be called
> concurrently) .
>
>
> May be it would make sense to enhance the ConnectionUtils by a
> synchronizedConnection(INonBlockingConnection nbc) and a
> synchronizedConnection(IBlockingConnection con) method. But his doesn't help
> if concurrent threads will execute code like:
>
> con.markWritePosition();
>
> con.write(..);
>
> con.resetToWriteMark();
>
>
> For this reason I'm not sure if it is a good idea to provide synchronized
> connections. This will give the feeling of thread safety which fails if you
> using statements like above.
>
> I updated the tutorial by this subject
>
>
> Gregor
>
>
>
>
>
>
> 2008/5/3 Rod Magnuson <rod...@gm...>:
>
>> While trying to get a simple test that fails I ran into:
>>
>> java.lang.NullPointerException:
>> Exception in thread "xServerPool-1-thread-8"
>> java.lang.NullPointerException
>> at org.xsocket.connection.WriteQueue.append(WriteQueue.java:133)
>> at
>> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1060)
>> at
>> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1040)
>> at testproject.TestServer.sendMessageToAllClients(TestServer.java:73)
>> at testproject.TestServer.onData(TestServer.java:63)
>> at
>> org.xsocket.connection.HandlerAdapter.onData(HandlerAdapter.java:132)
>> at
>> org.xsocket.connection.MultithreadedHandlerAdapter.access$201(MultithreadedHandlerAdapter.java:38)
>> at
>> org.xsocket.connection.MultithreadedHandlerAdapter$2.run(MultithreadedHandlerAdapter.java:80)
>> at
>> org.xsocket.SerializedTaskQueue.performPendingTasks(SerializedTaskQueue.java:113)
>> at
>> org.xsocket.SerializedTaskQueue.access$100(SerializedTaskQueue.java:38)
>> at
>> org.xsocket.SerializedTaskQueue$MultithreadedTaskProcessor.run(SerializedTaskQueue.java:139)
>> at
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
>> at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>> at java.lang.Thread.run(Thread.java:619)
>>
>> Which made me think perhaps I'm lacking some basic understanding, since I
>> see zero synchronization in the call chain down from connection.write. Am I
>> supposed to provide this synchronization?
>>
>> Thanks,
>> Rod
>>
>> Here's what my test server looks like:
>>
>> package testproject;
>>
>> import java.io.IOException;
>> import java.io.UnsupportedEncodingException;
>>
>> import java.net.SocketTimeoutException;
>>
>> import java.nio.channels.ClosedChannelException;
>>
>> import java.util.concurrent.ConcurrentHashMap;
>>
>> import org.xsocket.connection.ConnectionUtils;
>> import org.xsocket.connection.IConnectHandler;
>> import org.xsocket.connection.IConnection;
>> import org.xsocket.connection.IDataHandler;
>> import org.xsocket.connection.IDisconnectHandler;
>> import org.xsocket.connection.INonBlockingConnection;
>> import org.xsocket.connection.Server;
>>
>>
>> public class TestServer
>> implements IConnectHandler, IDisconnectHandler, IDataHandler
>> {
>> public static final String END_OF_MESSAGE_DELIM = new String(new char[]
>> { 0 });
>> // public static final String END_OF_MESSAGE_DELIM = "\r";
>>
>> public static void main(String[] args)
>> {
>> try
>> {
>> final Server server = new Server(6000, new TestServer());
>> server.setFlushMode(IConnection.FlushMode.ASYNC);
>>
>> ConnectionUtils.start(server);
>> }
>> catch (Exception e)
>> {
>> e.printStackTrace();
>> }
>> }
>>
>> public boolean onConnect(INonBlockingConnection connection)
>> {
>> connection.setAutoflush(false);
>> m_Connections.put(connection, Boolean.TRUE);
>> return true;
>> }
>>
>> public boolean onDisconnect(INonBlockingConnection connection)
>> {
>> m_Connections.remove(connection);
>> return true;
>> }
>>
>> public boolean onData(INonBlockingConnection connection)
>> throws IOException, UnsupportedEncodingException
>> {
>> // reset to read position (if former reads failed) and mark it
>> connection.resetToReadMark();
>> connection.markReadPosition();
>>
>> final String message =
>> connection.readStringByDelimiter(END_OF_MESSAGE_DELIM);
>>
>> connection.removeReadMark();
>>
>> sendMessageToAllClients("<received>" + message + "</received>");
>>
>> return true;
>> }
>>
>> private void sendMessageToAllClients(String message)
>> throws ClosedChannelException, IOException, SocketTimeoutException
>> {
>> for (INonBlockingConnection connection : m_Connections.keySet())
>> {
>> connection.write(message + END_OF_MESSAGE_DELIM);
>> connection.flush();
>> }
>> }
>>
>> private final ConcurrentHashMap<INonBlockingConnection, Boolean>
>> m_Connections = new ConcurrentHashMap<INonBlockingConnection, Boolean>();
>>
>> }
>>
>>
>> On Sat, May 3, 2008 at 12:43 AM, Gregor Roth <gre...@go...>
>> wrote:
>>
>>> Hi Rod,
>>>
>>> would you please submit this as a bug (
>>> http://sourceforge.net/tracker/?atid=850942&group_id=169583). Please
>>> also add a junit test, which contains the essential xSocket-related part of
>>> your client and server-side code.
>>>
>>> Thanks
>>> Gregor
>>>
>>> 2008/5/3 Rod Magnuson <rod...@gm...>:
>>>
>>>> I've got a simple server that sends/receives null terminated Strings
>>>> to/from a flash based client.
>>>>
>>>>
>>>> Flush mode is async.
>>>>
>>>> I'm using the 2.0 final jar.
>>>>
>>>> I'm seeing times when the client is receiving mangled data. The length
>>>> of the data is correct, just some of the contents are wrong. This does not
>>>> happen often and is hard to reproduce. When it does happen other clients
>>>> receive the correct data.
>>>>
>>>> I write out the messages with:
>>>>
>>>> String END_OF_MESSAGE_DELIM = new String(new char[] { 0 });
>>>> connection.write(message + END_OF_MESSAGE_DELIM);
>>>> connection.flush();
>>>>
>>>> It could be either client or server. Ideas on how to disqualify the
>>>> server?
>>>>
>>>> Thanks,
>>>> Rod
>>>>
>>>>
>>>> -------------------------------------------------------------------------
>>>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>>>> Don't miss this year's exciting event. There's still time to save $100.
>>>> Use priority code J8TL2D2.
>>>>
>>>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>>>> _______________________________________________
>>>> xSocket-develop mailing list
>>>> xSo...@li...
>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>>>
>>>>
>>>
>>> -------------------------------------------------------------------------
>>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>>> Don't miss this year's exciting event. There's still time to save $100.
>>> Use priority code J8TL2D2.
>>>
>>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>>> _______________________________________________
>>> xSocket-develop mailing list
>>> xSo...@li...
>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>>
>>>
>>
>
|
|
From: Gregor R. <gre...@go...> - 2008-05-04 08:13:31
|
Hi Rod,
yes, the NonBlockingConnection and BlockingConnection are not thread safe.
This means, you have to synchronize concurrent method calls. xSocket only
guarantees that the call back methods will be executed in a synchronized,
serialized manner.
The NullPointerException is caused by unsynchronized, concurrent write calls
on the same connection (-> sendMessageToAllClients will be called
concurrently) .
May be it would make sense to enhance the ConnectionUtils by a
synchronizedConnection(INonBlockingConnection nbc) and a
synchronizedConnection(IBlockingConnection con) method. But his doesn't help
if concurrent threads will execute code like:
con.markWritePosition();
con.write(..);
con.resetToWriteMark();
For this reason I'm not sure if it is a good idea to provide synchronized
connections. This will give the feeling of thread safety which fails if you
using statements like above.
I updated the tutorial by this subject
Gregor
2008/5/3 Rod Magnuson <rod...@gm...>:
> While trying to get a simple test that fails I ran into:
>
> java.lang.NullPointerException:
> Exception in thread "xServerPool-1-thread-8"
> java.lang.NullPointerException
> at org.xsocket.connection.WriteQueue.append(WriteQueue.java:133)
> at
> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1060)
> at
> org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1040)
> at testproject.TestServer.sendMessageToAllClients(TestServer.java:73)
> at testproject.TestServer.onData(TestServer.java:63)
> at
> org.xsocket.connection.HandlerAdapter.onData(HandlerAdapter.java:132)
> at
> org.xsocket.connection.MultithreadedHandlerAdapter.access$201(MultithreadedHandlerAdapter.java:38)
> at
> org.xsocket.connection.MultithreadedHandlerAdapter$2.run(MultithreadedHandlerAdapter.java:80)
> at
> org.xsocket.SerializedTaskQueue.performPendingTasks(SerializedTaskQueue.java:113)
> at
> org.xsocket.SerializedTaskQueue.access$100(SerializedTaskQueue.java:38)
> at
> org.xsocket.SerializedTaskQueue$MultithreadedTaskProcessor.run(SerializedTaskQueue.java:139)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
> at java.lang.Thread.run(Thread.java:619)
>
> Which made me think perhaps I'm lacking some basic understanding, since I
> see zero synchronization in the call chain down from connection.write. Am I
> supposed to provide this synchronization?
>
> Thanks,
> Rod
>
> Here's what my test server looks like:
>
> package testproject;
>
> import java.io.IOException;
> import java.io.UnsupportedEncodingException;
>
> import java.net.SocketTimeoutException;
>
> import java.nio.channels.ClosedChannelException;
>
> import java.util.concurrent.ConcurrentHashMap;
>
> import org.xsocket.connection.ConnectionUtils;
> import org.xsocket.connection.IConnectHandler;
> import org.xsocket.connection.IConnection;
> import org.xsocket.connection.IDataHandler;
> import org.xsocket.connection.IDisconnectHandler;
> import org.xsocket.connection.INonBlockingConnection;
> import org.xsocket.connection.Server;
>
>
> public class TestServer
> implements IConnectHandler, IDisconnectHandler, IDataHandler
> {
> public static final String END_OF_MESSAGE_DELIM = new String(new char[]
> { 0 });
> // public static final String END_OF_MESSAGE_DELIM = "\r";
>
> public static void main(String[] args)
> {
> try
> {
> final Server server = new Server(6000, new TestServer());
> server.setFlushMode(IConnection.FlushMode.ASYNC);
>
> ConnectionUtils.start(server);
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> }
>
> public boolean onConnect(INonBlockingConnection connection)
> {
> connection.setAutoflush(false);
> m_Connections.put(connection, Boolean.TRUE);
> return true;
> }
>
> public boolean onDisconnect(INonBlockingConnection connection)
> {
> m_Connections.remove(connection);
> return true;
> }
>
> public boolean onData(INonBlockingConnection connection)
> throws IOException, UnsupportedEncodingException
> {
> // reset to read position (if former reads failed) and mark it
> connection.resetToReadMark();
> connection.markReadPosition();
>
> final String message =
> connection.readStringByDelimiter(END_OF_MESSAGE_DELIM);
>
> connection.removeReadMark();
>
> sendMessageToAllClients("<received>" + message + "</received>");
>
> return true;
> }
>
> private void sendMessageToAllClients(String message)
> throws ClosedChannelException, IOException, SocketTimeoutException
> {
> for (INonBlockingConnection connection : m_Connections.keySet())
> {
> connection.write(message + END_OF_MESSAGE_DELIM);
> connection.flush();
> }
> }
>
> private final ConcurrentHashMap<INonBlockingConnection, Boolean>
> m_Connections = new ConcurrentHashMap<INonBlockingConnection, Boolean>();
>
> }
>
>
> On Sat, May 3, 2008 at 12:43 AM, Gregor Roth <gre...@go...>
> wrote:
>
> > Hi Rod,
> >
> > would you please submit this as a bug (
> > http://sourceforge.net/tracker/?atid=850942&group_id=169583). Please
> > also add a junit test, which contains the essential xSocket-related part of
> > your client and server-side code.
> >
> > Thanks
> > Gregor
> >
> > 2008/5/3 Rod Magnuson <rod...@gm...>:
> >
> > > I've got a simple server that sends/receives null terminated Strings
> > > to/from a flash based client.
> > >
> > >
> > > Flush mode is async.
> > >
> > > I'm using the 2.0 final jar.
> > >
> > > I'm seeing times when the client is receiving mangled data. The length
> > > of the data is correct, just some of the contents are wrong. This does not
> > > happen often and is hard to reproduce. When it does happen other clients
> > > receive the correct data.
> > >
> > > I write out the messages with:
> > >
> > > String END_OF_MESSAGE_DELIM = new String(new char[] { 0 });
> > > connection.write(message + END_OF_MESSAGE_DELIM);
> > > connection.flush();
> > >
> > > It could be either client or server. Ideas on how to disqualify the
> > > server?
> > >
> > > Thanks,
> > > Rod
> > >
> > >
> > > -------------------------------------------------------------------------
> > > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> > > Don't miss this year's exciting event. There's still time to save
> > > $100.
> > > Use priority code J8TL2D2.
> > >
> > > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> > > _______________________________________________
> > > xSocket-develop mailing list
> > > xSo...@li...
> > > https://lists.sourceforge.net/lists/listinfo/xsocket-develop
> > >
> > >
> >
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> > Don't miss this year's exciting event. There's still time to save $100.
> > Use priority code J8TL2D2.
> >
> > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> > _______________________________________________
> > xSocket-develop mailing list
> > xSo...@li...
> > https://lists.sourceforge.net/lists/listinfo/xsocket-develop
> >
> >
>
|
|
From: Mohamad A. B. A. <az...@gm...> - 2008-05-04 07:34:30
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Gregor,<br>
<br>
Thank you for the explanation. :)<br>
<br>
-Mohamad.<br>
<br>
Gregor Roth wrote:
<blockquote
cite="mid:4c3...@ma..."
type="cite">Hi Mohamad,<br>
<br>
by default the connection and idle timeout of xSocket connections is ~
70 years. To verify that xSocket doesn't close the connection caused by
a timeout, you can implement the ITimout handler interface. The methods
of the timeout handler will be called if a timout occurs. <br>
<br>
Additional you can activate xSocket's log to see what happens under the
hood. <br>
<br>
Please see the example enclosed<br>
<br>
Gregor <br>
<br>
<br>
<br>
public static void main(String[] args) throws IOException {<br>
<br>
Logger logger = Logger.getLogger("org.xsocket.stream");<br>
logger.setLevel(Level.FINE);<br>
<br>
ConsoleHandler ch = new ConsoleHandler();<br>
ch.setLevel(Level.FINE);<br>
logger.addHandler(ch);<br>
<br>
IMultithreadedServer srv = new MultithreadedServer(new
Handler());<br>
// srv.setIdleTimeoutSec(3);<br>
srv.run();<br>
<br>
<br>
}<br>
<br>
<br>
<br>
private static final class Handler implements IDataHandler,
ITimeoutHandler {<br>
<br>
@Override<br>
public boolean onData(INonBlockingConnection connection) throws
IOException, BufferUnderflowException, MaxReadSizeExceededException {<br>
<br>
connection.write(connection.readAvailable());<br>
return true;<br>
}<br>
<br>
@Override<br>
public boolean onConnectionTimeout(INonBlockingConnection
connection) throws IOException {<br>
System.out.println("connection timeout occured (connection
timeout=" + connection.getConnectionTimeoutSec() + ")");<br>
return false; // returning false causes that the
connection will be closed <br>
}<br>
<br>
<br>
@Override<br>
public boolean onIdleTimeout(INonBlockingConnection connection)
throws IOException {<br>
System.out.println("idle timeout occured (idle timeout=" +
connection.getIdleTimeoutSec() + ")");<br>
return false; // returning false causes that the
connection will be closed<br>
}<br>
}<br>
<br>
<br>
<div class="gmail_quote">2008/5/3 Mohamad Azri Bin Azhar <<a
moz-do-not-send="true" href="mailto:az...@gm...">az...@gm...</a>>:<br>
<blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi
there,<br>
<br>
I'm using xSocket 1.2.1 MultithreadedServer to listen for HTTP POST<br>
request. Upon receiving the request, I'd do something with the data<br>
which takes like 1 to 3 seconds and response back to the client.<br>
<br>
Basically, inside my onData() handler, I'd have something like:<br>
<br>
connection.readByteBufferByDelimiter(delimeter);<br>
//do something, and then:<br>
connection.write(someData);<br>
<br>
However, every an hour or so it won't be able to write the response back<br>
and get the following exception:<br>
<br>
org.xsocket.ClosedConnectionException: connection<br>
7c292b5b.119a45810b8.4d6a25b2.s.12074 is already closed<br>
at org.xsocket.stream.Connection.write(Connection.java:667)<br>
at org.xsocket.stream.Connection.write(Connection.java:582)<br>
at<br>
org.xsocket.stream.NonBlockingConnection.onDataEvent(NonBlockingConnection.java:757)<br>
.......<br>
<br>
My question is, does the connection here is closed by xSocket? If so,<br>
any idea to solve this?<br>
<br>
(btw, the client is an Axis client which simply post the request to my<br>
xSocket server)<br>
<br>
Thank you.<br>
<br>
Regards,<br>
Azri.<br>
<br>
<br>
-------------------------------------------------------------------------<br>
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference<br>
Don't miss this year's exciting event. There's still time to save $100.<br>
Use priority code J8TL2D2.<br>
<a moz-do-not-send="true"
href="http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone"
target="_blank">http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone</a><br>
_______________________________________________<br>
xSocket-develop mailing list<br>
<a moz-do-not-send="true"
href="mailto:xSo...@li...">xSo...@li...</a><br>
<a moz-do-not-send="true"
href="https://lists.sourceforge.net/lists/listinfo/xsocket-develop"
target="_blank">https://lists.sourceforge.net/lists/listinfo/xsocket-develop</a><br>
</blockquote>
</div>
<br>
</blockquote>
<br>
</body>
</html>
|
|
From: Rod M. <rod...@gm...> - 2008-05-03 18:29:50
|
While trying to get a simple test that fails I ran into:
java.lang.NullPointerException:
Exception in thread "xServerPool-1-thread-8" java.lang.NullPointerException
at org.xsocket.connection.WriteQueue.append(WriteQueue.java:133)
at
org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1060)
at
org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1040)
at testproject.TestServer.sendMessageToAllClients(TestServer.java:73)
at testproject.TestServer.onData(TestServer.java:63)
at org.xsocket.connection.HandlerAdapter.onData(HandlerAdapter.java:132)
at
org.xsocket.connection.MultithreadedHandlerAdapter.access$201(MultithreadedHandlerAdapter.java:38)
at
org.xsocket.connection.MultithreadedHandlerAdapter$2.run(MultithreadedHandlerAdapter.java:80)
at
org.xsocket.SerializedTaskQueue.performPendingTasks(SerializedTaskQueue.java:113)
at
org.xsocket.SerializedTaskQueue.access$100(SerializedTaskQueue.java:38)
at
org.xsocket.SerializedTaskQueue$MultithreadedTaskProcessor.run(SerializedTaskQueue.java:139)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Which made me think perhaps I'm lacking some basic understanding, since I
see zero synchronization in the call chain down from connection.write. Am I
supposed to provide this synchronization?
Thanks,
Rod
Here's what my test server looks like:
package testproject;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.SocketTimeoutException;
import java.nio.channels.ClosedChannelException;
import java.util.concurrent.ConcurrentHashMap;
import org.xsocket.connection.ConnectionUtils;
import org.xsocket.connection.IConnectHandler;
import org.xsocket.connection.IConnection;
import org.xsocket.connection.IDataHandler;
import org.xsocket.connection.IDisconnectHandler;
import org.xsocket.connection.INonBlockingConnection;
import org.xsocket.connection.Server;
public class TestServer
implements IConnectHandler, IDisconnectHandler, IDataHandler
{
public static final String END_OF_MESSAGE_DELIM = new String(new char[] {
0 });
// public static final String END_OF_MESSAGE_DELIM = "\r";
public static void main(String[] args)
{
try
{
final Server server = new Server(6000, new TestServer());
server.setFlushMode(IConnection.FlushMode.ASYNC);
ConnectionUtils.start(server);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public boolean onConnect(INonBlockingConnection connection)
{
connection.setAutoflush(false);
m_Connections.put(connection, Boolean.TRUE);
return true;
}
public boolean onDisconnect(INonBlockingConnection connection)
{
m_Connections.remove(connection);
return true;
}
public boolean onData(INonBlockingConnection connection)
throws IOException, UnsupportedEncodingException
{
// reset to read position (if former reads failed) and mark it
connection.resetToReadMark();
connection.markReadPosition();
final String message =
connection.readStringByDelimiter(END_OF_MESSAGE_DELIM);
connection.removeReadMark();
sendMessageToAllClients("<received>" + message + "</received>");
return true;
}
private void sendMessageToAllClients(String message)
throws ClosedChannelException, IOException, SocketTimeoutException
{
for (INonBlockingConnection connection : m_Connections.keySet())
{
connection.write(message + END_OF_MESSAGE_DELIM);
connection.flush();
}
}
private final ConcurrentHashMap<INonBlockingConnection, Boolean>
m_Connections = new ConcurrentHashMap<INonBlockingConnection, Boolean>();
}
On Sat, May 3, 2008 at 12:43 AM, Gregor Roth <gre...@go...>
wrote:
> Hi Rod,
>
> would you please submit this as a bug (
> http://sourceforge.net/tracker/?atid=850942&group_id=169583). Please also
> add a junit test, which contains the essential xSocket-related part of your
> client and server-side code.
>
> Thanks
> Gregor
>
> 2008/5/3 Rod Magnuson <rod...@gm...>:
>
>> I've got a simple server that sends/receives null terminated Strings
>> to/from a flash based client.
>>
>>
>> Flush mode is async.
>>
>> I'm using the 2.0 final jar.
>>
>> I'm seeing times when the client is receiving mangled data. The length of
>> the data is correct, just some of the contents are wrong. This does not
>> happen often and is hard to reproduce. When it does happen other clients
>> receive the correct data.
>>
>> I write out the messages with:
>>
>> String END_OF_MESSAGE_DELIM = new String(new char[] { 0 });
>> connection.write(message + END_OF_MESSAGE_DELIM);
>> connection.flush();
>>
>> It could be either client or server. Ideas on how to disqualify the
>> server?
>>
>> Thanks,
>> Rod
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>> Don't miss this year's exciting event. There's still time to save $100.
>> Use priority code J8TL2D2.
>>
>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>> _______________________________________________
>> xSocket-develop mailing list
>> xSo...@li...
>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>
>>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
>
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|
|
From: Gregor R. <gre...@go...> - 2008-05-03 11:45:42
|
Hi Mohamad,
by default the connection and idle timeout of xSocket connections is ~ 70
years. To verify that xSocket doesn't close the connection caused by a
timeout, you can implement the ITimout handler interface. The methods of the
timeout handler will be called if a timout occurs.
Additional you can activate xSocket's log to see what happens under the
hood.
Please see the example enclosed
Gregor
public static void main(String[] args) throws IOException {
Logger logger = Logger.getLogger("org.xsocket.stream");
logger.setLevel(Level.FINE);
ConsoleHandler ch = new ConsoleHandler();
ch.setLevel(Level.FINE);
logger.addHandler(ch);
IMultithreadedServer srv = new MultithreadedServer(new Handler());
// srv.setIdleTimeoutSec(3);
srv.run();
}
private static final class Handler implements IDataHandler,
ITimeoutHandler {
@Override
public boolean onData(INonBlockingConnection connection) throws
IOException, BufferUnderflowException, MaxReadSizeExceededException {
connection.write(connection.readAvailable());
return true;
}
@Override
public boolean onConnectionTimeout(INonBlockingConnection
connection) throws IOException {
System.out.println("connection timeout occured (connection
timeout=" + connection.getConnectionTimeoutSec() + ")");
return false; // returning false causes that the connection
will be closed
}
@Override
public boolean onIdleTimeout(INonBlockingConnection connection)
throws IOException {
System.out.println("idle timeout occured (idle timeout=" +
connection.getIdleTimeoutSec() + ")");
return false; // returning false causes that the connection
will be closed
}
}
2008/5/3 Mohamad Azri Bin Azhar <az...@gm...>:
> Hi there,
>
> I'm using xSocket 1.2.1 MultithreadedServer to listen for HTTP POST
> request. Upon receiving the request, I'd do something with the data
> which takes like 1 to 3 seconds and response back to the client.
>
> Basically, inside my onData() handler, I'd have something like:
>
> connection.readByteBufferByDelimiter(delimeter);
> //do something, and then:
> connection.write(someData);
>
> However, every an hour or so it won't be able to write the response back
> and get the following exception:
>
> org.xsocket.ClosedConnectionException: connection
> 7c292b5b.119a45810b8.4d6a25b2.s.12074 is already closed
> at org.xsocket.stream.Connection.write(Connection.java:667)
> at org.xsocket.stream.Connection.write(Connection.java:582)
> at
>
> org.xsocket.stream.NonBlockingConnection.onDataEvent(NonBlockingConnection.java:757)
> .......
>
> My question is, does the connection here is closed by xSocket? If so,
> any idea to solve this?
>
> (btw, the client is an Axis client which simply post the request to my
> xSocket server)
>
> Thank you.
>
> Regards,
> Azri.
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
>
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
|
|
From: Mohamad A. B. A. <az...@gm...> - 2008-05-03 10:25:37
|
Hi there,
I'm using xSocket 1.2.1 MultithreadedServer to listen for HTTP POST
request. Upon receiving the request, I'd do something with the data
which takes like 1 to 3 seconds and response back to the client.
Basically, inside my onData() handler, I'd have something like:
connection.readByteBufferByDelimiter(delimeter);
//do something, and then:
connection.write(someData);
However, every an hour or so it won't be able to write the response back
and get the following exception:
org.xsocket.ClosedConnectionException: connection
7c292b5b.119a45810b8.4d6a25b2.s.12074 is already closed
at org.xsocket.stream.Connection.write(Connection.java:667)
at org.xsocket.stream.Connection.write(Connection.java:582)
at
org.xsocket.stream.NonBlockingConnection.onDataEvent(NonBlockingConnection.java:757)
.......
My question is, does the connection here is closed by xSocket? If so,
any idea to solve this?
(btw, the client is an Axis client which simply post the request to my
xSocket server)
Thank you.
Regards,
Azri.
|