xsocket-develop Mailing List for xsocket (Page 13)
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: yanping g. <yan...@gm...> - 2008-11-18 11:01:34
|
hi Gregor:
When I try to implement my NIO Server, I found some little feature is
lack:
1. in xsocket, now support get by lenght and get by delimiter, is most
case, it is OK; but some times, I cannot
get the packet's length or delimiter before decoding; so I need try
decode and valide checksum; in this case, need
pushback stream, maybe unread(...) is preferable.
2. INonBlockingConnection is both client and server connection, if I
could know the connection is which side, it will help
for processing, maybe need isServerSide() in connection.
--
Jimmy Gao
Software Senior Product Manager
yan...@gm...
|
|
From: Gregor R. <gre...@go...> - 2008-11-17 19:06:21
|
Hi, in most cases it is better to use the multithreaded mode (multithreaded is the default mode). Running the service in a non-threaded mode is a performance optimization. However, the non-threaded mode will work only work, if the handler doesn't perform I/O operations such as file or network operations. To avoid outstanding threads while receiving file data, you could read the network data and write it to a file in a non-blocking mode. For instance see the Data Handler of the SimpleSmtpServer -> http://xsocket.svn.sourceforge.net/viewvc/xsocket/xsocket/core/trunk/src/test/java/org/xsocket/connection/SimpleSmtpServer.java To send a file a sync mode has to be used. For instance see the UploadHandler2 of the SimpleFileChannelPerformanceTest –> http://xsocket.svn.sourceforge.net/viewvc/xsocket/xsocket/core/trunk/src/test/java/org/xsocket/connection/SimpleFileChannelPerformanceTest.java With Java 1.7 you will have the option to access the file in an async mode. In this case you can use a non-blocking, async approach similar to the file upload scenario. If the server reaches the limit by serving many clients, a transport level load balancing solution will be used to spread the request over a farm of servers. For a more detailed explanation see link http://www.javaworld.com/javaworld/jw-10-2008/jw-10-load-balancing-1.html Gregor 2008/11/17 beijing welcome <wel...@gm...> > hi, > a discussion for applying xSocket to implement an effective and robust file > server. > > a TCP server stores lots of small pictures (from 1k to 5k for each size). > a client downloads pictures from server frequently, but seldom do uploading > job. > > as far as i know for xSocket, the server can use > SERVER: transferFrom a FileChannel to BlockingConnection in on > IDataHandler.onData() > CLIENT: can use transferTo a FileChannel from BlockingConnection > > the communication between client and server has two steps: > 1. client sends a query to server, server send back the pictures list which > need to download. > 2. client begins to download the pictures from server. > > if the client need to download more than 10 pictures in a seconds, then it > seems reasonable to use multi thread. > > the question is how to design in server side. > 1) if use multi thread, how to write the IDataHandler.onData()? if it's > BlockingConnection, will it block other threads for this connection? if > NonBlockingConnection, need to write to bytebuffer.duplicate()? > > 2) if many clients connect to the same server (e.g. more than 10k), the > multi thread will rise the connection number? how to minimize the load of > server? if use proxy to do load balance, any other problem? > > > > what's your opinion? > > any comments are appreciated. > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > > |
|
From: beijing w. <wel...@gm...> - 2008-11-17 16:43:48
|
hi, a discussion for applying xSocket to implement an effective and robust file server. a TCP server stores lots of small pictures (from 1k to 5k for each size). a client downloads pictures from server frequently, but seldom do uploading job. as far as i know for xSocket, the server can use SERVER: transferFrom a FileChannel to BlockingConnection in on IDataHandler.onData() CLIENT: can use transferTo a FileChannel from BlockingConnection the communication between client and server has two steps: 1. client sends a query to server, server send back the pictures list which need to download. 2. client begins to download the pictures from server. if the client need to download more than 10 pictures in a seconds, then it seems reasonable to use multi thread. the question is how to design in server side. 1) if use multi thread, how to write the IDataHandler.onData()? if it's BlockingConnection, will it block other threads for this connection? if NonBlockingConnection, need to write to bytebuffer.duplicate()? 2) if many clients connect to the same server (e.g. more than 10k), the multi thread will rise the connection number? how to minimize the load of server? if use proxy to do load balance, any other problem? what's your opinion? any comments are appreciated. |
|
From: Gregor R. <gre...@go...> - 2008-11-14 05:07:20
|
Hi Jimmy, thanks for your feedback. Feature 1 (onWritten callback) is already on the ToDo list and will be addressed by the next feature release of xSocket. Could you specifiy what excatly should be improved regading to Feature 2 (FilterChain API)? This would help to imrpove xSocket. Thanks Gregor 2008/11/14 yanping gao <yan...@gm...> > > I have compare some nio framework, and i found xsocket is best for easy > use; > but I found some features is need: > > 1. IHandler is no onWritten() interface, it is need for check request > time-out, for example, i written some packets to connection, and i need wait > reply on some time; that event is triggerred in onWritten is best fit. > > 2. the filterChain is too simple and not so flexible, so i cannot import my > filter so easy and flexible; maybe mina is better in here. > > -- > Jimmy Gao > Software Senior Product Manager > yan...@gm... > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > > |
|
From: yanping g. <yan...@gm...> - 2008-11-14 03:30:29
|
I have compare some nio framework, and i found xsocket is best for easy use; but I found some features is need: 1. IHandler is no onWritten() interface, it is need for check request time-out, for example, i written some packets to connection, and i need wait reply on some time; that event is triggerred in onWritten is best fit. 2. the filterChain is too simple and not so flexible, so i cannot import my filter so easy and flexible; maybe mina is better in here. -- Jimmy Gao Software Senior Product Manager yan...@gm... |
|
From: Gregor R. <gre...@go...> - 2008-11-06 04:44:28
|
David,
thanks for your remark. This is a bug. I've fixed this (see trunk).
Gregor
2008/11/5 David Haubenstricker (IS - Emg Tech) <
dav...@do...>
> In the NonBlockingConnection, why is a separate connection pool used
> (EXECUTOR on line 671) rather than the workerpool that is passed in as a
> parameter? It seems that if I'm trying to control the number of running
> threads, via the workerpool, this will launch more threads than I want.
>
>
>
> 647 /**
>
> 648 * client constructor, which uses a specific dispatcher
>
> 649 */
>
> 650 private NonBlockingConnection(final InetSocketAddress
> remoteAddress, boolean waitForConnect, final int connectTimeoutMillis, final
> Map<String, Object> options, final SSLContext sslContext, final boolean
> isSecured, final IHandler appHdl, final Executor workerpool, boolean
> autoflush, FlushMode flushmode) throws IOException {
>
> 651 setFlushmode(flushmode);
>
> 652 setAutoflush(autoflush);
>
> 653 setWorkerpool(workerpool);
>
> 654
>
> 655 appHandler.set(HandlerAdapter.newInstance(appHdl));
>
> 656
>
> 657 if (waitForConnect) {
>
> 658 connect(remoteAddress, connectTimeoutMillis,
> options, sslContext, isSecured);
>
> 659
>
> 660 } else {
>
> 661 Runnable connectTask = new Runnable() {
>
> 662
>
> 663 public void run() {
>
> 664 try {
>
> 665 connect(remoteAddress,
> connectTimeoutMillis, options, sslContext, isSecured);
>
> 666 } catch (IOException ioe) {
>
> 667 onDisconnect();
>
> 668 }
>
> 669 }
>
> 670 };
>
> 671 EXECUTOR.execute(connectTask);
>
> 672 }
>
> 673 }
>
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|
|
From: David H. (IS - E. Tech) <dav...@do...> - 2008-11-05 19:56:19
|
In the NonBlockingConnection, why is a separate connection pool used (EXECUTOR on line 671) rather than the workerpool that is passed in as a parameter? It seems that if I'm trying to control the number of running threads, via the workerpool, this will launch more threads than I want.
647 /**
648 * client constructor, which uses a specific dispatcher
649 */
650 private NonBlockingConnection(final InetSocketAddress remoteAddress, boolean waitForConnect, final int connectTimeoutMillis, final Map<String, Object> options, final SSLContext sslContext, final boolean isSecured, final IHandler appHdl, final Executor workerpool, boolean autoflush, FlushMode flushmode) throws IOException {
651 setFlushmode(flushmode);
652 setAutoflush(autoflush);
653 setWorkerpool(workerpool);
654
655 appHandler.set(HandlerAdapter.newInstance(appHdl));
656
657 if (waitForConnect) {
658 connect(remoteAddress, connectTimeoutMillis, options, sslContext, isSecured);
659
660 } else {
661 Runnable connectTask = new Runnable() {
662
663 public void run() {
664 try {
665 connect(remoteAddress, connectTimeoutMillis, options, sslContext, isSecured);
666 } catch (IOException ioe) {
667 onDisconnect();
668 }
669 }
670 };
671 EXECUTOR.execute(connectTask);
672 }
673 }
|
|
From: Gregor R. <gre...@go...> - 2008-11-05 13:56:28
|
Hi David,
you bug can be the reason for the closed channel. If the onData implemention
throws an exception, xSocket will close the underlying connection. Please
re-run your test based on your fixed code.
Gregor
2008/11/5 David Alves <da...@st...>
> Hi
> Thanks for your insight Gregor.
> Indeed I was wodering why the readStringByDelimiter was returning a
> bytebuffer[] since in every case I tested the array only seemed to contain
> one element. I'll update my code as you sugest regarding this, and regarding
> the data serialization issue.
> But, correct me if I'm mistaken, that doesn't explain why the client always
> throws a ClosedChannelException after 67 object serializations, right?
> Any ideas as to why this is happening?
>
> Regards
> David Alves
>
> On Nov 5, 2008, at 7:08 AM, Gregor Roth wrote:
>
> Hi David,
>
> the <connection>.readByteBufferByDelimiter(…) returns an array of byte
> buffers. This doesn't mean, that several records (separated by a delimiter)
> is fetched. If you get an array longer than 1, it just means that more than
> one byte buffer is used to hold the record data. This is caused by a
> fragmented network I/O read. For performance reasons xSocket doesn't merge
> such fragmented byte buffers into a single buffer. xSocket's DataConverter
> class supports a toByteBuffer(ByteBuffer[] buffers) method to do this (which
> has performance impacts).
>
> In your code you have also to ensure that your delimiter will never appear
> as part of the serialized data. May be using a leading length filed would be
> a better approach
>
> Gregor
>
>
>
>
> 2008/11/5 David Alves <da...@st...>
>
>> Hi
>> I'm trying xsocket for the first time and I quite like the api and the
>> features.
>> I'm using a nonblockingpipeline over a multiplexed connection and all
>> seems fine, until the channel closes and a ClosedChannelException is thrown.
>> I'm reasearching some event processing mechanisms and as such I
>> serialize objects across the client to the server, and it all boils down to
>> the fact that I always can send 67 and just 67 events.
>> Strange no?
>> Any help would be greatly appreciated.
>> My send/receive code along with the trace is in the end of the email.
>>
>> Kind regards
>> David Alves
>>
>> ______________________
>>
>> Client: (All the connection creation code is done only once then a
>> generating thread tries to send event through the pipeline)
>>
>> Creation:
>> this.nativeConnection = new NonBlockingConnection(this.host, port,
>> Integer.MAX_VALUE);
>> this.multiplexedConnection = new MultiplexedConnection(nativeConnection
>> );
>> controlPipelineId = multiplexedConnection.createPipeline();
>> controlPipeline = multiplexedConnection.getNonBlockingPipeline(
>> controlPipelineId);
>>
>> Repeat:
>> FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
>> ObjectOutputStream oos = new ObjectOutputStream(fbaos);
>> oos.writeObject(event);
>> ByteBuffer objectBuffer = fbaos.getByteBuffer();
>> controlPipeline.write(objectBuffer);
>> controlPipeline.write(EVENT_SEPARATOR);
>>
>> ________________
>>
>> Server: (Implements IPipelineDataHandler)
>> ByteBuffer[] eventsBbs = pipeline
>> .readByteBufferByDelimiter(DummyMultiplexedNonBockingAdapter.
>> EVENT_SEPARATOR);
>> for (ByteBuffer eventBb : eventsBbs) {
>> FastByteArrayInputStream fbais = new FastByteArrayInputStream(eventBb);
>> ObjectInputStream ois = new ObjectInputStream(fbais);
>> Event event;
>> try {
>> event = (Event) ois.readObject();
>> } catch (ClassNotFoundException e) {
>> throw new IOException(e);
>> }
>> receiveEvent(event);
>> }
>>
>> Trace:
>>
>> Caused by: java.nio.channels.ClosedChannelException
>> at
>> org.xsocket.connection.AbstractNonBlockingStream.ensureStreamIsOpenAndWritable(
>> AbstractNonBlockingStream.java:1472)
>> at org.xsocket.connection.AbstractNonBlockingStream.write(
>> AbstractNonBlockingStream.java:1140)
>> at
>> pt.uc.dei.fincos.adapter.dummy.remote.DummyMultiplexedNonBockingAdapter.send(
>> DummyMultiplexedNonBockingAdapter.java:72)
>> ... 19 more
>> java.lang.NullPointerException
>> at
>> pt.uc.dei.fincos.adapter.dummy.remote.DummyMultiplexedNonBockingAdapter.send(
>> DummyMultiplexedNonBockingAdapter.java:72)
>>
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's
>> challenge
>> Build the coolest Linux based applications with Moblin SDK & win great
>> prizes
>> Grand prize is a trip for two to an Open Source event anywhere in the
>> world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>> _______________________________________________
>> xSocket-develop mailing list
>> xSo...@li...
>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>
>>
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|
|
From: David A. <da...@st...> - 2008-11-05 13:26:57
|
Hi
Thanks for your insight Gregor.
Indeed I was wodering why the readStringByDelimiter was returning a
bytebuffer[] since in every case I tested the array only seemed to
contain one element. I'll update my code as you sugest regarding this,
and regarding the data serialization issue.
But, correct me if I'm mistaken, that doesn't explain why the client
always throws a ClosedChannelException after 67 object serializations,
right?
Any ideas as to why this is happening?
Regards
David Alves
On Nov 5, 2008, at 7:08 AM, Gregor Roth wrote:
> Hi David,
>
> the <connection>.readByteBufferByDelimiter(…) returns an array of
> byte buffers. This doesn't mean, that several records (separated by
> a delimiter) is fetched. If you get an array longer than 1, it just
> means that more than one byte buffer is used to hold the record
> data. This is caused by a fragmented network I/O read. For
> performance reasons xSocket doesn't merge such fragmented byte
> buffers into a single buffer. xSocket's DataConverter class supports
> a toByteBuffer(ByteBuffer[] buffers) method to do this (which has
> performance impacts).
>
> In your code you have also to ensure that your delimiter will never
> appear as part of the serialized data. May be using a leading length
> filed would be a better approach
>
> Gregor
>
>
>
>
> 2008/11/5 David Alves <da...@st...>
> Hi
>
> I'm trying xsocket for the first time and I quite like the api and
> the features.
> I'm using a nonblockingpipeline over a multiplexed connection and
> all seems fine, until the channel closes and a
> ClosedChannelException is thrown.
> I'm reasearching some event processing mechanisms and as such I
> serialize objects across the client to the server, and it all boils
> down to the fact that I always can send 67 and just 67 events.
> Strange no?
> Any help would be greatly appreciated.
> My send/receive code along with the trace is in the end of the email.
>
> Kind regards
> David Alves
>
> ______________________
>
> Client: (All the connection creation code is done only once then a
> generating thread tries to send event through the pipeline)
>
> Creation:
> this.nativeConnection = new NonBlockingConnection(this.host, port,
> Integer.MAX_VALUE);
> this.multiplexedConnection = new
> MultiplexedConnection(nativeConnection);
> controlPipelineId = multiplexedConnection.createPipeline();
> controlPipeline =
> multiplexedConnection.getNonBlockingPipeline(controlPipelineId);
>
> Repeat:
> FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
> ObjectOutputStream oos = new ObjectOutputStream(fbaos);
> oos.writeObject(event);
> ByteBuffer objectBuffer = fbaos.getByteBuffer();
> controlPipeline.write(objectBuffer);
> controlPipeline.write(EVENT_SEPARATOR);
>
> ________________
>
> Server: (Implements IPipelineDataHandler)
> ByteBuffer[] eventsBbs = pipeline
> .readByteBufferByDelimiter
> (DummyMultiplexedNonBockingAdapter.EVENT_SEPARATOR);
> for (ByteBuffer eventBb : eventsBbs) {
> FastByteArrayInputStream fbais = new
> FastByteArrayInputStream(eventBb);
> ObjectInputStream ois = new ObjectInputStream(fbais);
> Event event;
> try {
> event = (Event) ois.readObject();
> } catch (ClassNotFoundException e) {
> throw new IOException(e);
> }
> receiveEvent(event);
> }
>
> Trace:
>
> Caused by: java.nio.channels.ClosedChannelException
> at
> org
> .xsocket
> .connection
> .AbstractNonBlockingStream
> .ensureStreamIsOpenAndWritable(AbstractNonBlockingStream.java:1472)
> at
> org
> .xsocket
> .connection
> .AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1140)
> at
> pt
> .uc
> .dei
> .fincos
> .adapter
> .dummy
> .remote
> .DummyMultiplexedNonBockingAdapter
> .send(DummyMultiplexedNonBockingAdapter.java:72)
> ... 19 more
> java.lang.NullPointerException
> at
> pt
> .uc
> .dei
> .fincos
> .adapter
> .dummy
> .remote
> .DummyMultiplexedNonBockingAdapter
> .send(DummyMultiplexedNonBockingAdapter.java:72)
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win
> great prizes
> Grand prize is a trip for two to an Open Source event anywhere in
> the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|
|
From: Gregor R. <gre...@go...> - 2008-11-05 07:08:15
|
Hi David,
the <connection>.readByteBufferByDelimiter(…) returns an array of byte
buffers. This doesn't mean, that several records (separated by a delimiter)
is fetched. If you get an array longer than 1, it just means that more than
one byte buffer is used to hold the record data. This is caused by a
fragmented network I/O read. For performance reasons xSocket doesn't merge
such fragmented byte buffers into a single buffer. xSocket's DataConverter
class supports a toByteBuffer(ByteBuffer[] buffers) method to do this (which
has performance impacts).
In your code you have also to ensure that your delimiter will never appear
as part of the serialized data. May be using a leading length filed would be
a better approach
Gregor
2008/11/5 David Alves <da...@st...>
> Hi
> I'm trying xsocket for the first time and I quite like the api and the
> features.
> I'm using a nonblockingpipeline over a multiplexed connection and all seems
> fine, until the channel closes and a ClosedChannelException is thrown.
> I'm reasearching some event processing mechanisms and as such I serialize
> objects across the client to the server, and it all boils down to the fact
> that I always can send 67 and just 67 events.
> Strange no?
> Any help would be greatly appreciated.
> My send/receive code along with the trace is in the end of the email.
>
> Kind regards
> David Alves
>
> ______________________
>
> Client: (All the connection creation code is done only once then a
> generating thread tries to send event through the pipeline)
>
> Creation:
> this.nativeConnection = new NonBlockingConnection(this.host, port,
> Integer.MAX_VALUE);
> this.multiplexedConnection = new MultiplexedConnection(nativeConnection);
> controlPipelineId = multiplexedConnection.createPipeline();
> controlPipeline = multiplexedConnection.getNonBlockingPipeline(
> controlPipelineId);
>
> Repeat:
> FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
> ObjectOutputStream oos = new ObjectOutputStream(fbaos);
> oos.writeObject(event);
> ByteBuffer objectBuffer = fbaos.getByteBuffer();
> controlPipeline.write(objectBuffer);
> controlPipeline.write(EVENT_SEPARATOR);
>
> ________________
>
> Server: (Implements IPipelineDataHandler)
> ByteBuffer[] eventsBbs = pipeline
> .readByteBufferByDelimiter(DummyMultiplexedNonBockingAdapter.
> EVENT_SEPARATOR);
> for (ByteBuffer eventBb : eventsBbs) {
> FastByteArrayInputStream fbais = new FastByteArrayInputStream(eventBb);
> ObjectInputStream ois = new ObjectInputStream(fbais);
> Event event;
> try {
> event = (Event) ois.readObject();
> } catch (ClassNotFoundException e) {
> throw new IOException(e);
> }
> receiveEvent(event);
> }
>
> Trace:
>
> Caused by: java.nio.channels.ClosedChannelException
> at
> org.xsocket.connection.AbstractNonBlockingStream.ensureStreamIsOpenAndWritable(
> AbstractNonBlockingStream.java:1472)
> at org.xsocket.connection.AbstractNonBlockingStream.write(
> AbstractNonBlockingStream.java:1140)
> at
> pt.uc.dei.fincos.adapter.dummy.remote.DummyMultiplexedNonBockingAdapter.send(
> DummyMultiplexedNonBockingAdapter.java:72)
> ... 19 more
> java.lang.NullPointerException
> at
> pt.uc.dei.fincos.adapter.dummy.remote.DummyMultiplexedNonBockingAdapter.send(
> DummyMultiplexedNonBockingAdapter.java:72)
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|
|
From: David A. <da...@st...> - 2008-11-05 02:16:56
|
Hi
I'm trying xsocket for the first time and I quite like the api and
the features.
I'm using a nonblockingpipeline over a multiplexed connection and all
seems fine, until the channel closes and a ClosedChannelException is
thrown.
I'm reasearching some event processing mechanisms and as such I
serialize objects across the client to the server, and it all boils
down to the fact that I always can send 67 and just 67 events.
Strange no?
Any help would be greatly appreciated.
My send/receive code along with the trace is in the end of the email.
Kind regards
David Alves
______________________
Client: (All the connection creation code is done only once then a
generating thread tries to send event through the pipeline)
Creation:
this.nativeConnection = new NonBlockingConnection(this.host, port,
Integer.MAX_VALUE);
this.multiplexedConnection = new
MultiplexedConnection(nativeConnection);
controlPipelineId = multiplexedConnection.createPipeline();
controlPipeline =
multiplexedConnection.getNonBlockingPipeline(controlPipelineId);
Repeat:
FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(fbaos);
oos.writeObject(event);
ByteBuffer objectBuffer = fbaos.getByteBuffer();
controlPipeline.write(objectBuffer);
controlPipeline.write(EVENT_SEPARATOR);
________________
Server: (Implements IPipelineDataHandler)
ByteBuffer[] eventsBbs = pipeline
.readByteBufferByDelimiter
(DummyMultiplexedNonBockingAdapter.EVENT_SEPARATOR);
for (ByteBuffer eventBb : eventsBbs) {
FastByteArrayInputStream fbais = new
FastByteArrayInputStream(eventBb);
ObjectInputStream ois = new ObjectInputStream(fbais);
Event event;
try {
event = (Event) ois.readObject();
} catch (ClassNotFoundException e) {
throw new IOException(e);
}
receiveEvent(event);
}
Trace:
Caused by: java.nio.channels.ClosedChannelException
at
org
.xsocket
.connection
.AbstractNonBlockingStream
.ensureStreamIsOpenAndWritable(AbstractNonBlockingStream.java:1472)
at
org
.xsocket
.connection
.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1140)
at
pt
.uc
.dei
.fincos
.adapter
.dummy
.remote
.DummyMultiplexedNonBockingAdapter
.send(DummyMultiplexedNonBockingAdapter.java:72)
... 19 more
java.lang.NullPointerException
at
pt
.uc
.dei
.fincos
.adapter
.dummy
.remote
.DummyMultiplexedNonBockingAdapter
.send(DummyMultiplexedNonBockingAdapter.java:72) |
|
From: beijing w. <wel...@gm...> - 2008-11-01 03:33:54
|
thank you so much!it does work! 2008/10/31 Gregor Roth <gre...@go...> > > Sorry I added the wrong links in my last response. Meanwhile I wrote some > examples. Please see > http://xsocket.svn.sourceforge.net/viewvc/xsocket/xsocket/core/trunk/src/test/java/org/xsocket/connection/DataHandlerExampleTest.java?revision=3177&view=markup > > > Gregor > > > 2008/10/30 beijing welcome <wel...@gm...> > >> >> 2008/10/30 Gregor Roth <gre...@go...> >> >>> take a look into xSocket's Junit test: >>> - >>> http://xlightweb.svn.sourceforge.net/viewvc/xlightweb/xlightweb/core/trunk/src/test/java/org/xlightweb/CommandStreamingTest.java?view=markup >>> - >>> http://xlightweb.svn.sourceforge.net/viewvc/xlightweb/xlightweb/core/trunk/src/test/java/org/xlightweb/ChannelStreamingTest.java?view=markup >>> >>> >> >>> >>> May be it helps you. >> >> >> I changed the code to transfer the file, have further problem when write >> file, see inline. >> >> >> >>> >>> >>> Gregor >>> >>> >>> 2008/10/30 beijing welcome <wel...@gm...> >>> >>> >>>> >>>> 2008/10/30 Gregor Roth <gre...@go...> >>>> >>>>> … you do two things in our onData() implementation: Echoing the >>>>> received data and printing it. >>>>> >>>>> If you are using the async flush mode, the buffer will be written to >>>>> the network asynchronously by the internal I/O thread. This means by >>>>> returning from the write method the buffer will be accessed by the I/O >>>>> thread in the background in a concurrent way. Because you access the buffer >>>>> after the write call to print it race conditions occurs. The solution is to >>>>> duplicate the byte buffer by calling <ByteBuffer>.duplicate() method or not >>>>> to set the flush mode to async. >>>>> >>>> thanks for your quick response. >>>> oh, i just want to let server receive the stream and then send another >>>> stream back to client, the solution above may hurt something, what's the >>>> most effective method to do that? >>>> onData() seems not the correct place to implement this logical, could >>>> you please point me which interface should be the right one? >>>> >>>> >>>>> >>>>> Converting byte buffers to a string is a little bit tricky. You can use >>>>> the convenience method DataConverter.toString(<ByteBuffer[]>, encoding) to >>>>> convert the byte buffers to a string. >>>>> >>>>> Gregor >>>>> >>>>> >>>>> >>>>> 2008/10/29 beijing welcome <wel...@gm...> >>>>> >>>>>> hi, xSocket develop folks, >>>>>> >>>>>> This might be a very basic question, I want to read a file by stream >>>>>> and send to server, then do something, however, ByteBuffer[] in >>>>>> readByteBufferByDelimiter is empty in server side. >>>>>> >>>>>> paste the code below. >>>>>> >>>>>> Thank you in advance! >>>>>> >>>>>> =============== MServer.java ============== >>>>>> package mserver; >>>>>> >>>>>> import java.io.Closeable; >>>>>> import java.io.IOException; >>>>>> import java.net.InetAddress; >>>>>> import java.util.HashSet; >>>>>> import java.util.Set; >>>>>> >>>>>> import org.xsocket.connection.IConnectHandler; >>>>>> import org.xsocket.connection.IHandler; >>>>>> import org.xsocket.connection.INonBlockingConnection; >>>>>> import org.xsocket.connection.IServer; >>>>>> import org.xsocket.connection.Server; >>>>>> import org.xsocket.connection.ConnectionUtils; >>>>>> import org.xsocket.connection.IConnection.FlushMode; >>>>>> >>>>>> import mserver.MServerHandler; >>>>>> >>>>>> >>>>>> public class MServer implements Closeable { >>>>>> >>>>>> private IServer server = null; >>>>>> >>>>>> public MServer(int listenPort) throws Exception { >>>>>> >>>>>> IHandler hdl = new MServerHandler(); >>>>>> >>>>>> server = new Server(listenPort, hdl); >>>>>> server.setFlushMode(FlushMode.ASYNC); // performance >>>>>> improvement >>>>>> >>>>>> ConnectionUtils.start(server); >>>>>> ConnectionUtils.registerMBean(server); >>>>>> } >>>>>> >>>>>> public static void main(String... args) throws Exception { >>>>>> int port = 8888; >>>>>> new MServer(port); >>>>>> } >>>>>> >>>>>> public InetAddress getLocalAddress() { >>>>>> return server.getLocalAddress(); >>>>>> } >>>>>> >>>>>> public void close() throws IOException { >>>>>> if (server != null) { >>>>>> server.close(); >>>>>> } >>>>>> } >>>>>> >>>>>> } >>>>>> ============================================== >>>>>> >>>>>> =================== MServerHandler.java =========================== >>>>>> >>>>>> package mserver; >>>>>> >>>>>> import java.io.IOException; >>>>>> import java.nio.BufferUnderflowException; >>>>>> import java.nio.ByteBuffer; >>>>>> import java.nio.CharBuffer; >>>>>> import java.nio.charset.Charset; >>>>>> import java.nio.charset.CharsetDecoder; >>>>>> >>>>>> import org.xsocket.Execution; >>>>>> import org.xsocket.MaxReadSizeExceededException; >>>>>> import org.xsocket.connection.IConnectHandler; >>>>>> import org.xsocket.connection.IDataHandler; >>>>>> import org.xsocket.connection.INonBlockingConnection; >>>>>> import org.xsocket.connection.IConnection.FlushMode; >>>>>> >>>>>> @Execution(Execution.NONTHREADED) >>>>>> public class MServerHandler implements IConnectHandler, IDataHandler { >>>>>> public static final String DELIMITER = "\r\n"; >>>>>> static Charset charset = Charset.forName("gb2312"); >>>>>> static CharsetDecoder decoder = charset.newDecoder(); >>>>>> static CharBuffer charBuffer = null ; >>>>>> >>>>>> public boolean onConnect(INonBlockingConnection connection) throws >>>>>> IOException, BufferUnderflowException, MaxReadSizeExceededException { >>>>>> connection.setFlushmode(FlushMode.ASYNC); >>>>>> connection.setAutoflush(false); >>>>>> // connection.write("Welcome to MServer!"); >>>>>> System.out.println(connection.getRemoteAddress() + " >>>>>> connected!"); >>>>>> return true; >>>>>> } >>>>>> >>>>>> public boolean onData(INonBlockingConnection connection) throws >>>>>> IOException, BufferUnderflowException { >>>>>> ByteBuffer[] buffer = >>>>>> connection.readByteBufferByDelimiter(DELIMITER, Integer.MAX_VALUE); >>>>>> // connection.write("Server: "); >>>>>> >>>>>> connection.write(buffer); >>>>>> connection.write(DELIMITER); >>>>>> for (int j = 0; j < buffer.length; ++j) { >>>>>> buffer[j].flip(); >>>>>> charBuffer = decoder.decode(buffer[j]); >>>>>> // System.out.println( " charBuffer= " + charBuffer); >>>>>> // this line is empty! >>>>>> System.out.println(charBuffer.toString()); >>>>>> System.out.println(j); >>>>>> } >>>>>> connection.flush(); >>>>>> System.out.println("===="); >>>>>> return true; >>>>>> } >>>>>> } >>>>>> >>>>> >> I changed the code followed: >> >> public boolean onData(INonBlockingConnection connection) throws >> IOException, BufferUnderflowException { >> if (connection.available() < 0) return false; >> File file = File.createTempFile("test", null); >> System.out.println("avaliable1: " + connection.available()); >> // "hello" can be received successfully. >> String s = connection.readStringByDelimiter(DELIMITER); >> System.out.println(s); >> file.createNewFile(); >> //file.deleteOnExit(); >> String fullname = file.getAbsolutePath(); >> System.out.println("fullname: " + fullname); >> System.out.println("avaliable2: " + connection.available()); >> FileChannel fc = new FileOutputStream(file).getChannel(); >> long length = fc.transferTo(0, connection.available(), >> connection); >> * // !!! This line cannot be run???* >> System.out.println(length); >> fc.close(); >> connection.write(fc.size()); >> connection.flush(); >> >> System.out.println("===="); >> return true; >> } >> >> >> the server side output is: >> /127.0.0.1 connected! >> avaliable1: 179 >> hello >> fullname: C:\DOCUME~1\bati\LOCALS~1\Temp\test25638.tmp >> avaliable2: 172 >> avaliable1: -1 >> >> however, C:\DOCUME~1\bati\LOCALS~1\Temp\test25638.tmp is empty! I may >> miss something. >> >> >>>>>> >>>>>> >>>>>> ========================================= >>>>>> ================= MServerClient.java ======================== >>>>>> package mserver; >>>>>> >>>>>> import java.io.InputStreamReader; >>>>>> import java.io.LineNumberReader; >>>>>> import java.net.Socket; >>>>>> >>>>>> public class MServerClient { >>>>>> >>>>> static String filename = "c:\\111.txt"; >> public void startClient() throws Exception { >> int port = 8888; >> String host = "localhost"; >> INonBlockingConnection connection = null; >> try { >> connection = new NonBlockingConnection(host, port); >> connection.write("hello\r\n"); >> FileChannel fc = new FileInputStream(filename).getChannel(); >> connection.transferFrom(fc); >> fc.close(); >> System.out.println("done!"); >> } catch (Exception e) { >> e.printStackTrace(); >> } >> finally { >> if (connection != null) { >> connection.close(); >> } >> } >> >> } >>>>>> /** >>>>>> * @param args >>>>>> */ >>>>>> public static void main(String[] args) { >>>>>> // TODO Auto-generated method stub >>>>>> MServerClient client = new MServerClient(); >>>>>> try { >>>>>> client.startClient(); >>>>>> } catch (Exception e) { >>>>>> e.printStackTrace(); >>>>>> } >>>>>> } >>>>>> >>>>>> } >>>>>> >>>>>> ------------------------------------------------------------------------- >>>>>> This SF.Net email is sponsored by the Moblin Your Move Developer's >>>>>> challenge >>>>>> Build the coolest Linux based applications with Moblin SDK & win great >>>>>> prizes >>>>>> Grand prize is a trip for two to an Open Source event anywhere in the >>>>>> world >>>>>> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >>>>>> _______________________________________________ >>>>>> xSocket-develop mailing list >>>>>> xSo...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop >>>>>> >>>>>> >>>>> >>>> >>> >> > |
|
From: Gregor R. <gre...@go...> - 2008-10-31 06:48:15
|
Sorry I added the wrong links in my last response. Meanwhile I wrote some examples. Please see http://xsocket.svn.sourceforge.net/viewvc/xsocket/xsocket/core/trunk/src/test/java/org/xsocket/connection/DataHandlerExampleTest.java?revision=3177&view=markup Gregor 2008/10/30 beijing welcome <wel...@gm...> > > 2008/10/30 Gregor Roth <gre...@go...> > >> take a look into xSocket's Junit test: >> - >> http://xlightweb.svn.sourceforge.net/viewvc/xlightweb/xlightweb/core/trunk/src/test/java/org/xlightweb/CommandStreamingTest.java?view=markup >> - >> http://xlightweb.svn.sourceforge.net/viewvc/xlightweb/xlightweb/core/trunk/src/test/java/org/xlightweb/ChannelStreamingTest.java?view=markup >> >> > >> >> May be it helps you. > > > I changed the code to transfer the file, have further problem when write > file, see inline. > > > >> >> >> Gregor >> >> >> 2008/10/30 beijing welcome <wel...@gm...> >> >> >>> >>> 2008/10/30 Gregor Roth <gre...@go...> >>> >>>> … you do two things in our onData() implementation: Echoing the received >>>> data and printing it. >>>> >>>> If you are using the async flush mode, the buffer will be written to the >>>> network asynchronously by the internal I/O thread. This means by returning >>>> from the write method the buffer will be accessed by the I/O thread in the >>>> background in a concurrent way. Because you access the buffer after the >>>> write call to print it race conditions occurs. The solution is to duplicate >>>> the byte buffer by calling <ByteBuffer>.duplicate() method or not to set the >>>> flush mode to async. >>>> >>> thanks for your quick response. >>> oh, i just want to let server receive the stream and then send another >>> stream back to client, the solution above may hurt something, what's the >>> most effective method to do that? >>> onData() seems not the correct place to implement this logical, could you >>> please point me which interface should be the right one? >>> >>> >>>> >>>> Converting byte buffers to a string is a little bit tricky. You can use >>>> the convenience method DataConverter.toString(<ByteBuffer[]>, encoding) to >>>> convert the byte buffers to a string. >>>> >>>> Gregor >>>> >>>> >>>> >>>> 2008/10/29 beijing welcome <wel...@gm...> >>>> >>>>> hi, xSocket develop folks, >>>>> >>>>> This might be a very basic question, I want to read a file by stream >>>>> and send to server, then do something, however, ByteBuffer[] in >>>>> readByteBufferByDelimiter is empty in server side. >>>>> >>>>> paste the code below. >>>>> >>>>> Thank you in advance! >>>>> >>>>> =============== MServer.java ============== >>>>> package mserver; >>>>> >>>>> import java.io.Closeable; >>>>> import java.io.IOException; >>>>> import java.net.InetAddress; >>>>> import java.util.HashSet; >>>>> import java.util.Set; >>>>> >>>>> import org.xsocket.connection.IConnectHandler; >>>>> import org.xsocket.connection.IHandler; >>>>> import org.xsocket.connection.INonBlockingConnection; >>>>> import org.xsocket.connection.IServer; >>>>> import org.xsocket.connection.Server; >>>>> import org.xsocket.connection.ConnectionUtils; >>>>> import org.xsocket.connection.IConnection.FlushMode; >>>>> >>>>> import mserver.MServerHandler; >>>>> >>>>> >>>>> public class MServer implements Closeable { >>>>> >>>>> private IServer server = null; >>>>> >>>>> public MServer(int listenPort) throws Exception { >>>>> >>>>> IHandler hdl = new MServerHandler(); >>>>> >>>>> server = new Server(listenPort, hdl); >>>>> server.setFlushMode(FlushMode.ASYNC); // performance >>>>> improvement >>>>> >>>>> ConnectionUtils.start(server); >>>>> ConnectionUtils.registerMBean(server); >>>>> } >>>>> >>>>> public static void main(String... args) throws Exception { >>>>> int port = 8888; >>>>> new MServer(port); >>>>> } >>>>> >>>>> public InetAddress getLocalAddress() { >>>>> return server.getLocalAddress(); >>>>> } >>>>> >>>>> public void close() throws IOException { >>>>> if (server != null) { >>>>> server.close(); >>>>> } >>>>> } >>>>> >>>>> } >>>>> ============================================== >>>>> >>>>> =================== MServerHandler.java =========================== >>>>> >>>>> package mserver; >>>>> >>>>> import java.io.IOException; >>>>> import java.nio.BufferUnderflowException; >>>>> import java.nio.ByteBuffer; >>>>> import java.nio.CharBuffer; >>>>> import java.nio.charset.Charset; >>>>> import java.nio.charset.CharsetDecoder; >>>>> >>>>> import org.xsocket.Execution; >>>>> import org.xsocket.MaxReadSizeExceededException; >>>>> import org.xsocket.connection.IConnectHandler; >>>>> import org.xsocket.connection.IDataHandler; >>>>> import org.xsocket.connection.INonBlockingConnection; >>>>> import org.xsocket.connection.IConnection.FlushMode; >>>>> >>>>> @Execution(Execution.NONTHREADED) >>>>> public class MServerHandler implements IConnectHandler, IDataHandler { >>>>> public static final String DELIMITER = "\r\n"; >>>>> static Charset charset = Charset.forName("gb2312"); >>>>> static CharsetDecoder decoder = charset.newDecoder(); >>>>> static CharBuffer charBuffer = null ; >>>>> >>>>> public boolean onConnect(INonBlockingConnection connection) throws >>>>> IOException, BufferUnderflowException, MaxReadSizeExceededException { >>>>> connection.setFlushmode(FlushMode.ASYNC); >>>>> connection.setAutoflush(false); >>>>> // connection.write("Welcome to MServer!"); >>>>> System.out.println(connection.getRemoteAddress() + " >>>>> connected!"); >>>>> return true; >>>>> } >>>>> >>>>> public boolean onData(INonBlockingConnection connection) throws >>>>> IOException, BufferUnderflowException { >>>>> ByteBuffer[] buffer = >>>>> connection.readByteBufferByDelimiter(DELIMITER, Integer.MAX_VALUE); >>>>> // connection.write("Server: "); >>>>> >>>>> connection.write(buffer); >>>>> connection.write(DELIMITER); >>>>> for (int j = 0; j < buffer.length; ++j) { >>>>> buffer[j].flip(); >>>>> charBuffer = decoder.decode(buffer[j]); >>>>> // System.out.println( " charBuffer= " + charBuffer); >>>>> // this line is empty! >>>>> System.out.println(charBuffer.toString()); >>>>> System.out.println(j); >>>>> } >>>>> connection.flush(); >>>>> System.out.println("===="); >>>>> return true; >>>>> } >>>>> } >>>>> >>>> > I changed the code followed: > > public boolean onData(INonBlockingConnection connection) throws > IOException, BufferUnderflowException { > if (connection.available() < 0) return false; > File file = File.createTempFile("test", null); > System.out.println("avaliable1: " + connection.available()); > // "hello" can be received successfully. > String s = connection.readStringByDelimiter(DELIMITER); > System.out.println(s); > file.createNewFile(); > //file.deleteOnExit(); > String fullname = file.getAbsolutePath(); > System.out.println("fullname: " + fullname); > System.out.println("avaliable2: " + connection.available()); > FileChannel fc = new FileOutputStream(file).getChannel(); > long length = fc.transferTo(0, connection.available(), connection); > * // !!! This line cannot be run???* > System.out.println(length); > fc.close(); > connection.write(fc.size()); > connection.flush(); > > System.out.println("===="); > return true; > } > > > the server side output is: > /127.0.0.1 connected! > avaliable1: 179 > hello > fullname: C:\DOCUME~1\bati\LOCALS~1\Temp\test25638.tmp > avaliable2: 172 > avaliable1: -1 > > however, C:\DOCUME~1\bati\LOCALS~1\Temp\test25638.tmp is empty! I may miss > something. > > >>>>> >>>>> >>>>> ========================================= >>>>> ================= MServerClient.java ======================== >>>>> package mserver; >>>>> >>>>> import java.io.InputStreamReader; >>>>> import java.io.LineNumberReader; >>>>> import java.net.Socket; >>>>> >>>>> public class MServerClient { >>>>> >>>> static String filename = "c:\\111.txt"; > public void startClient() throws Exception { > int port = 8888; > String host = "localhost"; > INonBlockingConnection connection = null; > try { > connection = new NonBlockingConnection(host, port); > connection.write("hello\r\n"); > FileChannel fc = new FileInputStream(filename).getChannel(); > connection.transferFrom(fc); > fc.close(); > System.out.println("done!"); > } catch (Exception e) { > e.printStackTrace(); > } > finally { > if (connection != null) { > connection.close(); > } > } > > } >>>>> /** >>>>> * @param args >>>>> */ >>>>> public static void main(String[] args) { >>>>> // TODO Auto-generated method stub >>>>> MServerClient client = new MServerClient(); >>>>> try { >>>>> client.startClient(); >>>>> } catch (Exception e) { >>>>> e.printStackTrace(); >>>>> } >>>>> } >>>>> >>>>> } >>>>> >>>>> ------------------------------------------------------------------------- >>>>> This SF.Net email is sponsored by the Moblin Your Move Developer's >>>>> challenge >>>>> Build the coolest Linux based applications with Moblin SDK & win great >>>>> prizes >>>>> Grand prize is a trip for two to an Open Source event anywhere in the >>>>> world >>>>> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >>>>> _______________________________________________ >>>>> xSocket-develop mailing list >>>>> xSo...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop >>>>> >>>>> >>>> >>> >> > |
|
From: beijing w. <wel...@gm...> - 2008-10-30 16:34:25
|
2008/10/30 Gregor Roth <gre...@go...> > take a look into xSocket's Junit test: > - > http://xlightweb.svn.sourceforge.net/viewvc/xlightweb/xlightweb/core/trunk/src/test/java/org/xlightweb/CommandStreamingTest.java?view=markup > - > http://xlightweb.svn.sourceforge.net/viewvc/xlightweb/xlightweb/core/trunk/src/test/java/org/xlightweb/ChannelStreamingTest.java?view=markup > > > May be it helps you. I changed the code to transfer the file, have further problem when write file, see inline. > > > Gregor > > > 2008/10/30 beijing welcome <wel...@gm...> > > >> >> 2008/10/30 Gregor Roth <gre...@go...> >> >>> … you do two things in our onData() implementation: Echoing the received >>> data and printing it. >>> >>> If you are using the async flush mode, the buffer will be written to the >>> network asynchronously by the internal I/O thread. This means by returning >>> from the write method the buffer will be accessed by the I/O thread in the >>> background in a concurrent way. Because you access the buffer after the >>> write call to print it race conditions occurs. The solution is to duplicate >>> the byte buffer by calling <ByteBuffer>.duplicate() method or not to set the >>> flush mode to async. >>> >> thanks for your quick response. >> oh, i just want to let server receive the stream and then send another >> stream back to client, the solution above may hurt something, what's the >> most effective method to do that? >> onData() seems not the correct place to implement this logical, could you >> please point me which interface should be the right one? >> >> >>> >>> Converting byte buffers to a string is a little bit tricky. You can use >>> the convenience method DataConverter.toString(<ByteBuffer[]>, encoding) to >>> convert the byte buffers to a string. >>> >>> Gregor >>> >>> >>> >>> 2008/10/29 beijing welcome <wel...@gm...> >>> >>>> hi, xSocket develop folks, >>>> >>>> This might be a very basic question, I want to read a file by stream and >>>> send to server, then do something, however, ByteBuffer[] in >>>> readByteBufferByDelimiter is empty in server side. >>>> >>>> paste the code below. >>>> >>>> Thank you in advance! >>>> >>>> =============== MServer.java ============== >>>> package mserver; >>>> >>>> import java.io.Closeable; >>>> import java.io.IOException; >>>> import java.net.InetAddress; >>>> import java.util.HashSet; >>>> import java.util.Set; >>>> >>>> import org.xsocket.connection.IConnectHandler; >>>> import org.xsocket.connection.IHandler; >>>> import org.xsocket.connection.INonBlockingConnection; >>>> import org.xsocket.connection.IServer; >>>> import org.xsocket.connection.Server; >>>> import org.xsocket.connection.ConnectionUtils; >>>> import org.xsocket.connection.IConnection.FlushMode; >>>> >>>> import mserver.MServerHandler; >>>> >>>> >>>> public class MServer implements Closeable { >>>> >>>> private IServer server = null; >>>> >>>> public MServer(int listenPort) throws Exception { >>>> >>>> IHandler hdl = new MServerHandler(); >>>> >>>> server = new Server(listenPort, hdl); >>>> server.setFlushMode(FlushMode.ASYNC); // performance >>>> improvement >>>> >>>> ConnectionUtils.start(server); >>>> ConnectionUtils.registerMBean(server); >>>> } >>>> >>>> public static void main(String... args) throws Exception { >>>> int port = 8888; >>>> new MServer(port); >>>> } >>>> >>>> public InetAddress getLocalAddress() { >>>> return server.getLocalAddress(); >>>> } >>>> >>>> public void close() throws IOException { >>>> if (server != null) { >>>> server.close(); >>>> } >>>> } >>>> >>>> } >>>> ============================================== >>>> >>>> =================== MServerHandler.java =========================== >>>> >>>> package mserver; >>>> >>>> import java.io.IOException; >>>> import java.nio.BufferUnderflowException; >>>> import java.nio.ByteBuffer; >>>> import java.nio.CharBuffer; >>>> import java.nio.charset.Charset; >>>> import java.nio.charset.CharsetDecoder; >>>> >>>> import org.xsocket.Execution; >>>> import org.xsocket.MaxReadSizeExceededException; >>>> import org.xsocket.connection.IConnectHandler; >>>> import org.xsocket.connection.IDataHandler; >>>> import org.xsocket.connection.INonBlockingConnection; >>>> import org.xsocket.connection.IConnection.FlushMode; >>>> >>>> @Execution(Execution.NONTHREADED) >>>> public class MServerHandler implements IConnectHandler, IDataHandler { >>>> public static final String DELIMITER = "\r\n"; >>>> static Charset charset = Charset.forName("gb2312"); >>>> static CharsetDecoder decoder = charset.newDecoder(); >>>> static CharBuffer charBuffer = null ; >>>> >>>> public boolean onConnect(INonBlockingConnection connection) throws >>>> IOException, BufferUnderflowException, MaxReadSizeExceededException { >>>> connection.setFlushmode(FlushMode.ASYNC); >>>> connection.setAutoflush(false); >>>> // connection.write("Welcome to MServer!"); >>>> System.out.println(connection.getRemoteAddress() + " >>>> connected!"); >>>> return true; >>>> } >>>> >>>> public boolean onData(INonBlockingConnection connection) throws >>>> IOException, BufferUnderflowException { >>>> ByteBuffer[] buffer = >>>> connection.readByteBufferByDelimiter(DELIMITER, Integer.MAX_VALUE); >>>> // connection.write("Server: "); >>>> >>>> connection.write(buffer); >>>> connection.write(DELIMITER); >>>> for (int j = 0; j < buffer.length; ++j) { >>>> buffer[j].flip(); >>>> charBuffer = decoder.decode(buffer[j]); >>>> // System.out.println( " charBuffer= " + charBuffer); >>>> // this line is empty! >>>> System.out.println(charBuffer.toString()); >>>> System.out.println(j); >>>> } >>>> connection.flush(); >>>> System.out.println("===="); >>>> return true; >>>> } >>>> } >>>> >>> I changed the code followed: public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException { if (connection.available() < 0) return false; File file = File.createTempFile("test", null); System.out.println("avaliable1: " + connection.available()); // "hello" can be received successfully. String s = connection.readStringByDelimiter(DELIMITER); System.out.println(s); file.createNewFile(); //file.deleteOnExit(); String fullname = file.getAbsolutePath(); System.out.println("fullname: " + fullname); System.out.println("avaliable2: " + connection.available()); FileChannel fc = new FileOutputStream(file).getChannel(); long length = fc.transferTo(0, connection.available(), connection); * // !!! This line cannot be run???* System.out.println(length); fc.close(); connection.write(fc.size()); connection.flush(); System.out.println("===="); return true; } the server side output is: /127.0.0.1 connected! avaliable1: 179 hello fullname: C:\DOCUME~1\bati\LOCALS~1\Temp\test25638.tmp avaliable2: 172 avaliable1: -1 however, C:\DOCUME~1\bati\LOCALS~1\Temp\test25638.tmp is empty! I may miss something. >>>> >>>> >>>> ========================================= >>>> ================= MServerClient.java ======================== >>>> package mserver; >>>> >>>> import java.io.InputStreamReader; >>>> import java.io.LineNumberReader; >>>> import java.net.Socket; >>>> >>>> public class MServerClient { >>>> >>> static String filename = "c:\\111.txt"; public void startClient() throws Exception { int port = 8888; String host = "localhost"; INonBlockingConnection connection = null; try { connection = new NonBlockingConnection(host, port); connection.write("hello\r\n"); FileChannel fc = new FileInputStream(filename).getChannel(); connection.transferFrom(fc); fc.close(); System.out.println("done!"); } catch (Exception e) { e.printStackTrace(); } finally { if (connection != null) { connection.close(); } } } >>>> /** >>>> * @param args >>>> */ >>>> public static void main(String[] args) { >>>> // TODO Auto-generated method stub >>>> MServerClient client = new MServerClient(); >>>> try { >>>> client.startClient(); >>>> } catch (Exception e) { >>>> e.printStackTrace(); >>>> } >>>> } >>>> >>>> } >>>> >>>> ------------------------------------------------------------------------- >>>> This SF.Net email is sponsored by the Moblin Your Move Developer's >>>> challenge >>>> Build the coolest Linux based applications with Moblin SDK & win great >>>> prizes >>>> Grand prize is a trip for two to an Open Source event anywhere in the >>>> world >>>> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >>>> _______________________________________________ >>>> xSocket-develop mailing list >>>> xSo...@li... >>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop >>>> >>>> >>> >> > |
|
From: Gregor R. <gre...@go...> - 2008-10-30 07:08:34
|
take a look into xSocket's Junit test: - http://xlightweb.svn.sourceforge.net/viewvc/xlightweb/xlightweb/core/trunk/src/test/java/org/xlightweb/CommandStreamingTest.java?view=markup - http://xlightweb.svn.sourceforge.net/viewvc/xlightweb/xlightweb/core/trunk/src/test/java/org/xlightweb/ChannelStreamingTest.java?view=markup May be it helps you. Gregor 2008/10/30 beijing welcome <wel...@gm...> > > > 2008/10/30 Gregor Roth <gre...@go...> > >> … you do two things in our onData() implementation: Echoing the received >> data and printing it. >> >> If you are using the async flush mode, the buffer will be written to the >> network asynchronously by the internal I/O thread. This means by returning >> from the write method the buffer will be accessed by the I/O thread in the >> background in a concurrent way. Because you access the buffer after the >> write call to print it race conditions occurs. The solution is to duplicate >> the byte buffer by calling <ByteBuffer>.duplicate() method or not to set the >> flush mode to async. >> > thanks for your quick response. > oh, i just want to let server receive the stream and then send another > stream back to client, the solution above may hurt something, what's the > most effective method to do that? > onData() seems not the correct place to implement this logical, could you > please point me which interface should be the right one? > > >> >> Converting byte buffers to a string is a little bit tricky. You can use >> the convenience method DataConverter.toString(<ByteBuffer[]>, encoding) to >> convert the byte buffers to a string. >> >> Gregor >> >> >> >> 2008/10/29 beijing welcome <wel...@gm...> >> >>> hi, xSocket develop folks, >>> >>> This might be a very basic question, I want to read a file by stream and >>> send to server, then do something, however, ByteBuffer[] in >>> readByteBufferByDelimiter is empty in server side. >>> >>> paste the code below. >>> >>> Thank you in advance! >>> >>> =============== MServer.java ============== >>> package mserver; >>> >>> import java.io.Closeable; >>> import java.io.IOException; >>> import java.net.InetAddress; >>> import java.util.HashSet; >>> import java.util.Set; >>> >>> import org.xsocket.connection.IConnectHandler; >>> import org.xsocket.connection.IHandler; >>> import org.xsocket.connection.INonBlockingConnection; >>> import org.xsocket.connection.IServer; >>> import org.xsocket.connection.Server; >>> import org.xsocket.connection.ConnectionUtils; >>> import org.xsocket.connection.IConnection.FlushMode; >>> >>> import mserver.MServerHandler; >>> >>> >>> public class MServer implements Closeable { >>> >>> private IServer server = null; >>> >>> public MServer(int listenPort) throws Exception { >>> >>> IHandler hdl = new MServerHandler(); >>> >>> server = new Server(listenPort, hdl); >>> server.setFlushMode(FlushMode.ASYNC); // performance improvement >>> >>> >>> ConnectionUtils.start(server); >>> ConnectionUtils.registerMBean(server); >>> } >>> >>> public static void main(String... args) throws Exception { >>> int port = 8888; >>> new MServer(port); >>> } >>> >>> public InetAddress getLocalAddress() { >>> return server.getLocalAddress(); >>> } >>> >>> public void close() throws IOException { >>> if (server != null) { >>> server.close(); >>> } >>> } >>> >>> } >>> ============================================== >>> >>> =================== MServerHandler.java =========================== >>> >>> package mserver; >>> >>> import java.io.IOException; >>> import java.nio.BufferUnderflowException; >>> import java.nio.ByteBuffer; >>> import java.nio.CharBuffer; >>> import java.nio.charset.Charset; >>> import java.nio.charset.CharsetDecoder; >>> >>> import org.xsocket.Execution; >>> import org.xsocket.MaxReadSizeExceededException; >>> import org.xsocket.connection.IConnectHandler; >>> import org.xsocket.connection.IDataHandler; >>> import org.xsocket.connection.INonBlockingConnection; >>> import org.xsocket.connection.IConnection.FlushMode; >>> >>> @Execution(Execution.NONTHREADED) >>> public class MServerHandler implements IConnectHandler, IDataHandler { >>> public static final String DELIMITER = "\r\n"; >>> static Charset charset = Charset.forName("gb2312"); >>> static CharsetDecoder decoder = charset.newDecoder(); >>> static CharBuffer charBuffer = null ; >>> >>> public boolean onConnect(INonBlockingConnection connection) throws >>> IOException, BufferUnderflowException, MaxReadSizeExceededException { >>> connection.setFlushmode(FlushMode.ASYNC); >>> connection.setAutoflush(false); >>> // connection.write("Welcome to MServer!"); >>> System.out.println(connection.getRemoteAddress() + " >>> connected!"); >>> return true; >>> } >>> >>> public boolean onData(INonBlockingConnection connection) throws >>> IOException, BufferUnderflowException { >>> ByteBuffer[] buffer = >>> connection.readByteBufferByDelimiter(DELIMITER, Integer.MAX_VALUE); >>> // connection.write("Server: "); >>> >>> connection.write(buffer); >>> connection.write(DELIMITER); >>> for (int j = 0; j < buffer.length; ++j) { >>> buffer[j].flip(); >>> charBuffer = decoder.decode(buffer[j]); >>> // System.out.println( " charBuffer= " + charBuffer); >>> // this line is empty! >>> System.out.println(charBuffer.toString()); >>> System.out.println(j); >>> } >>> connection.flush(); >>> System.out.println("===="); >>> return true; >>> } >>> } >>> >>> >>> ========================================= >>> ================= MServerClient.java ======================== >>> package mserver; >>> >>> import java.io.InputStreamReader; >>> import java.io.LineNumberReader; >>> import java.net.Socket; >>> >>> public class MServerClient { >>> public void startClient() throws Exception { >>> int port = 8888; >>> Socket client = new Socket("localhost", port); >>> // next step is send a file here. >>> client.getOutputStream().write("test\r\n".getBytes()); >>> LineNumberReader lnr = new LineNumberReader( >>> new InputStreamReader(client.getInputStream())); >>> String response = lnr.readLine(); >>> System.out.println(response); >>> lnr.close(); >>> client.close(); >>> >>> } >>> /** >>> * @param args >>> */ >>> public static void main(String[] args) { >>> // TODO Auto-generated method stub >>> MServerClient client = new MServerClient(); >>> try { >>> client.startClient(); >>> } catch (Exception e) { >>> e.printStackTrace(); >>> } >>> } >>> >>> } >>> ------------------------------------------------------------------------- >>> This SF.Net email is sponsored by the Moblin Your Move Developer's >>> challenge >>> Build the coolest Linux based applications with Moblin SDK & win great >>> prizes >>> Grand prize is a trip for two to an Open Source event anywhere in the >>> world >>> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >>> _______________________________________________ >>> xSocket-develop mailing list >>> xSo...@li... >>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop >>> >>> >> > |
|
From: beijing w. <wel...@gm...> - 2008-10-30 00:23:19
|
2008/10/30 Gregor Roth <gre...@go...>
> … you do two things in our onData() implementation: Echoing the received
> data and printing it.
>
> If you are using the async flush mode, the buffer will be written to the
> network asynchronously by the internal I/O thread. This means by returning
> from the write method the buffer will be accessed by the I/O thread in the
> background in a concurrent way. Because you access the buffer after the
> write call to print it race conditions occurs. The solution is to duplicate
> the byte buffer by calling <ByteBuffer>.duplicate() method or not to set the
> flush mode to async.
>
thanks for your quick response.
oh, i just want to let server receive the stream and then send another
stream back to client, the solution above may hurt something, what's the
most effective method to do that?
onData() seems not the correct place to implement this logical, could you
please point me which interface should be the right one?
>
> Converting byte buffers to a string is a little bit tricky. You can use the
> convenience method DataConverter.toString(<ByteBuffer[]>, encoding) to
> convert the byte buffers to a string.
>
> Gregor
>
>
>
> 2008/10/29 beijing welcome <wel...@gm...>
>
>> hi, xSocket develop folks,
>>
>> This might be a very basic question, I want to read a file by stream and
>> send to server, then do something, however, ByteBuffer[] in
>> readByteBufferByDelimiter is empty in server side.
>>
>> paste the code below.
>>
>> Thank you in advance!
>>
>> =============== MServer.java ==============
>> package mserver;
>>
>> import java.io.Closeable;
>> import java.io.IOException;
>> import java.net.InetAddress;
>> import java.util.HashSet;
>> import java.util.Set;
>>
>> import org.xsocket.connection.IConnectHandler;
>> import org.xsocket.connection.IHandler;
>> import org.xsocket.connection.INonBlockingConnection;
>> import org.xsocket.connection.IServer;
>> import org.xsocket.connection.Server;
>> import org.xsocket.connection.ConnectionUtils;
>> import org.xsocket.connection.IConnection.FlushMode;
>>
>> import mserver.MServerHandler;
>>
>>
>> public class MServer implements Closeable {
>>
>> private IServer server = null;
>>
>> public MServer(int listenPort) throws Exception {
>>
>> IHandler hdl = new MServerHandler();
>>
>> server = new Server(listenPort, hdl);
>> server.setFlushMode(FlushMode.ASYNC); // performance improvement
>>
>> ConnectionUtils.start(server);
>> ConnectionUtils.registerMBean(server);
>> }
>>
>> public static void main(String... args) throws Exception {
>> int port = 8888;
>> new MServer(port);
>> }
>>
>> public InetAddress getLocalAddress() {
>> return server.getLocalAddress();
>> }
>>
>> public void close() throws IOException {
>> if (server != null) {
>> server.close();
>> }
>> }
>>
>> }
>> ==============================================
>>
>> =================== MServerHandler.java ===========================
>>
>> package mserver;
>>
>> import java.io.IOException;
>> import java.nio.BufferUnderflowException;
>> import java.nio.ByteBuffer;
>> import java.nio.CharBuffer;
>> import java.nio.charset.Charset;
>> import java.nio.charset.CharsetDecoder;
>>
>> import org.xsocket.Execution;
>> import org.xsocket.MaxReadSizeExceededException;
>> import org.xsocket.connection.IConnectHandler;
>> import org.xsocket.connection.IDataHandler;
>> import org.xsocket.connection.INonBlockingConnection;
>> import org.xsocket.connection.IConnection.FlushMode;
>>
>> @Execution(Execution.NONTHREADED)
>> public class MServerHandler implements IConnectHandler, IDataHandler {
>> public static final String DELIMITER = "\r\n";
>> static Charset charset = Charset.forName("gb2312");
>> static CharsetDecoder decoder = charset.newDecoder();
>> static CharBuffer charBuffer = null ;
>>
>> public boolean onConnect(INonBlockingConnection connection) throws
>> IOException, BufferUnderflowException, MaxReadSizeExceededException {
>> connection.setFlushmode(FlushMode.ASYNC);
>> connection.setAutoflush(false);
>> // connection.write("Welcome to MServer!");
>> System.out.println(connection.getRemoteAddress() + " connected!");
>> return true;
>> }
>>
>> public boolean onData(INonBlockingConnection connection) throws
>> IOException, BufferUnderflowException {
>> ByteBuffer[] buffer =
>> connection.readByteBufferByDelimiter(DELIMITER, Integer.MAX_VALUE);
>> // connection.write("Server: ");
>>
>> connection.write(buffer);
>> connection.write(DELIMITER);
>> for (int j = 0; j < buffer.length; ++j) {
>> buffer[j].flip();
>> charBuffer = decoder.decode(buffer[j]);
>> // System.out.println( " charBuffer= " + charBuffer);
>> // this line is empty!
>> System.out.println(charBuffer.toString());
>> System.out.println(j);
>> }
>> connection.flush();
>> System.out.println("====");
>> return true;
>> }
>> }
>>
>>
>> =========================================
>> ================= MServerClient.java ========================
>> package mserver;
>>
>> import java.io.InputStreamReader;
>> import java.io.LineNumberReader;
>> import java.net.Socket;
>>
>> public class MServerClient {
>> public void startClient() throws Exception {
>> int port = 8888;
>> Socket client = new Socket("localhost", port);
>> // next step is send a file here.
>> client.getOutputStream().write("test\r\n".getBytes());
>> LineNumberReader lnr = new LineNumberReader(
>> new InputStreamReader(client.getInputStream()));
>> String response = lnr.readLine();
>> System.out.println(response);
>> lnr.close();
>> client.close();
>>
>> }
>> /**
>> * @param args
>> */
>> public static void main(String[] args) {
>> // TODO Auto-generated method stub
>> MServerClient client = new MServerClient();
>> try {
>> client.startClient();
>> } catch (Exception e) {
>> e.printStackTrace();
>> }
>> }
>>
>> }
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's
>> challenge
>> Build the coolest Linux based applications with Moblin SDK & win great
>> prizes
>> Grand prize is a trip for two to an Open Source event anywhere in the
>> world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>> _______________________________________________
>> xSocket-develop mailing list
>> xSo...@li...
>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>
>>
> |
|
From: Gregor R. <gre...@go...> - 2008-10-29 17:48:54
|
… you do two things in our onData() implementation: Echoing the received
data and printing it.
If you are using the async flush mode, the buffer will be written to the
network asynchronously by the internal I/O thread. This means by returning
from the write method the buffer will be accessed by the I/O thread in the
background in a concurrent way. Because you access the buffer after the
write call to print it race conditions occurs. The solution is to duplicate
the byte buffer by calling <ByteBuffer>.duplicate() method or not to set the
flush mode to async.
Converting byte buffers to a string is a little bit tricky. You can use the
convenience method DataConverter.toString(<ByteBuffer[]>, encoding) to
convert the byte buffers to a string.
Gregor
2008/10/29 beijing welcome <wel...@gm...>
> hi, xSocket develop folks,
>
> This might be a very basic question, I want to read a file by stream and
> send to server, then do something, however, ByteBuffer[] in
> readByteBufferByDelimiter is empty in server side.
>
> paste the code below.
>
> Thank you in advance!
>
> =============== MServer.java ==============
> package mserver;
>
> import java.io.Closeable;
> import java.io.IOException;
> import java.net.InetAddress;
> import java.util.HashSet;
> import java.util.Set;
>
> import org.xsocket.connection.IConnectHandler;
> import org.xsocket.connection.IHandler;
> import org.xsocket.connection.INonBlockingConnection;
> import org.xsocket.connection.IServer;
> import org.xsocket.connection.Server;
> import org.xsocket.connection.ConnectionUtils;
> import org.xsocket.connection.IConnection.FlushMode;
>
> import mserver.MServerHandler;
>
>
> public class MServer implements Closeable {
>
> private IServer server = null;
>
> public MServer(int listenPort) throws Exception {
>
> IHandler hdl = new MServerHandler();
>
> server = new Server(listenPort, hdl);
> server.setFlushMode(FlushMode.ASYNC); // performance improvement
>
> ConnectionUtils.start(server);
> ConnectionUtils.registerMBean(server);
> }
>
> public static void main(String... args) throws Exception {
> int port = 8888;
> new MServer(port);
> }
>
> public InetAddress getLocalAddress() {
> return server.getLocalAddress();
> }
>
> public void close() throws IOException {
> if (server != null) {
> server.close();
> }
> }
>
> }
> ==============================================
>
> =================== MServerHandler.java ===========================
>
> package mserver;
>
> import java.io.IOException;
> import java.nio.BufferUnderflowException;
> import java.nio.ByteBuffer;
> import java.nio.CharBuffer;
> import java.nio.charset.Charset;
> import java.nio.charset.CharsetDecoder;
>
> import org.xsocket.Execution;
> import org.xsocket.MaxReadSizeExceededException;
> import org.xsocket.connection.IConnectHandler;
> import org.xsocket.connection.IDataHandler;
> import org.xsocket.connection.INonBlockingConnection;
> import org.xsocket.connection.IConnection.FlushMode;
>
> @Execution(Execution.NONTHREADED)
> public class MServerHandler implements IConnectHandler, IDataHandler {
> public static final String DELIMITER = "\r\n";
> static Charset charset = Charset.forName("gb2312");
> static CharsetDecoder decoder = charset.newDecoder();
> static CharBuffer charBuffer = null ;
>
> public boolean onConnect(INonBlockingConnection connection) throws
> IOException, BufferUnderflowException, MaxReadSizeExceededException {
> connection.setFlushmode(FlushMode.ASYNC);
> connection.setAutoflush(false);
> // connection.write("Welcome to MServer!");
> System.out.println(connection.getRemoteAddress() + " connected!");
> return true;
> }
>
> public boolean onData(INonBlockingConnection connection) throws
> IOException, BufferUnderflowException {
> ByteBuffer[] buffer =
> connection.readByteBufferByDelimiter(DELIMITER, Integer.MAX_VALUE);
> // connection.write("Server: ");
>
> connection.write(buffer);
> connection.write(DELIMITER);
> for (int j = 0; j < buffer.length; ++j) {
> buffer[j].flip();
> charBuffer = decoder.decode(buffer[j]);
> // System.out.println( " charBuffer= " + charBuffer);
> // this line is empty!
> System.out.println(charBuffer.toString());
> System.out.println(j);
> }
> connection.flush();
> System.out.println("====");
> return true;
> }
> }
>
>
> =========================================
> ================= MServerClient.java ========================
> package mserver;
>
> import java.io.InputStreamReader;
> import java.io.LineNumberReader;
> import java.net.Socket;
>
> public class MServerClient {
> public void startClient() throws Exception {
> int port = 8888;
> Socket client = new Socket("localhost", port);
> // next step is send a file here.
> client.getOutputStream().write("test\r\n".getBytes());
> LineNumberReader lnr = new LineNumberReader(
> new InputStreamReader(client.getInputStream()));
> String response = lnr.readLine();
> System.out.println(response);
> lnr.close();
> client.close();
>
> }
> /**
> * @param args
> */
> public static void main(String[] args) {
> // TODO Auto-generated method stub
> MServerClient client = new MServerClient();
> try {
> client.startClient();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> }
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|
|
From: beijing w. <wel...@gm...> - 2008-10-29 13:41:00
|
hi, xSocket develop folks,
This might be a very basic question, I want to read a file by stream and
send to server, then do something, however, ByteBuffer[] in
readByteBufferByDelimiter is empty in server side.
paste the code below.
Thank you in advance!
=============== MServer.java ==============
package mserver;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.util.HashSet;
import java.util.Set;
import org.xsocket.connection.IConnectHandler;
import org.xsocket.connection.IHandler;
import org.xsocket.connection.INonBlockingConnection;
import org.xsocket.connection.IServer;
import org.xsocket.connection.Server;
import org.xsocket.connection.ConnectionUtils;
import org.xsocket.connection.IConnection.FlushMode;
import mserver.MServerHandler;
public class MServer implements Closeable {
private IServer server = null;
public MServer(int listenPort) throws Exception {
IHandler hdl = new MServerHandler();
server = new Server(listenPort, hdl);
server.setFlushMode(FlushMode.ASYNC); // performance improvement
ConnectionUtils.start(server);
ConnectionUtils.registerMBean(server);
}
public static void main(String... args) throws Exception {
int port = 8888;
new MServer(port);
}
public InetAddress getLocalAddress() {
return server.getLocalAddress();
}
public void close() throws IOException {
if (server != null) {
server.close();
}
}
}
==============================================
=================== MServerHandler.java ===========================
package mserver;
import java.io.IOException;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import org.xsocket.Execution;
import org.xsocket.MaxReadSizeExceededException;
import org.xsocket.connection.IConnectHandler;
import org.xsocket.connection.IDataHandler;
import org.xsocket.connection.INonBlockingConnection;
import org.xsocket.connection.IConnection.FlushMode;
@Execution(Execution.NONTHREADED)
public class MServerHandler implements IConnectHandler, IDataHandler {
public static final String DELIMITER = "\r\n";
static Charset charset = Charset.forName("gb2312");
static CharsetDecoder decoder = charset.newDecoder();
static CharBuffer charBuffer = null ;
public boolean onConnect(INonBlockingConnection connection) throws
IOException, BufferUnderflowException, MaxReadSizeExceededException {
connection.setFlushmode(FlushMode.ASYNC);
connection.setAutoflush(false);
// connection.write("Welcome to MServer!");
System.out.println(connection.getRemoteAddress() + " connected!");
return true;
}
public boolean onData(INonBlockingConnection connection) throws
IOException, BufferUnderflowException {
ByteBuffer[] buffer =
connection.readByteBufferByDelimiter(DELIMITER, Integer.MAX_VALUE);
// connection.write("Server: ");
connection.write(buffer);
connection.write(DELIMITER);
for (int j = 0; j < buffer.length; ++j) {
buffer[j].flip();
charBuffer = decoder.decode(buffer[j]);
// System.out.println( " charBuffer= " + charBuffer);
// this line is empty!
System.out.println(charBuffer.toString());
System.out.println(j);
}
connection.flush();
System.out.println("====");
return true;
}
}
=========================================
================= MServerClient.java ========================
package mserver;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.net.Socket;
public class MServerClient {
public void startClient() throws Exception {
int port = 8888;
Socket client = new Socket("localhost", port);
// next step is send a file here.
client.getOutputStream().write("test\r\n".getBytes());
LineNumberReader lnr = new LineNumberReader(
new InputStreamReader(client.getInputStream()));
String response = lnr.readLine();
System.out.println(response);
lnr.close();
client.close();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MServerClient client = new MServerClient();
try {
client.startClient();
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
|
From: beijing w. <wel...@gm...> - 2008-10-29 13:30:43
|
hi, xSocket develop folks,
This might be a very basic question, I want to read a file by stream and
send to server, then do something, however, ByteBuffer[] in
readByteBufferByDelimiter is empty in server side.
paste the code below.
Thank you in advance!
=============== MServer.java ==============
package mserver;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.util.HashSet;
import java.util.Set;
import org.xsocket.connection.IConnectHandler;
import org.xsocket.connection.IHandler;
import org.xsocket.connection.INonBlockingConnection;
import org.xsocket.connection.IServer;
import org.xsocket.connection.Server;
import org.xsocket.connection.ConnectionUtils;
import org.xsocket.connection.IConnection.FlushMode;
import mserver.MServerHandler;
public class MServer implements Closeable {
private IServer server = null;
public MServer(int listenPort) throws Exception {
IHandler hdl = new MServerHandler();
server = new Server(listenPort, hdl);
server.setFlushMode(FlushMode.ASYNC); // performance improvement
ConnectionUtils.start(server);
ConnectionUtils.registerMBean(server);
}
public static void main(String... args) throws Exception {
int port = 8888;
new MServer(port);
}
public InetAddress getLocalAddress() {
return server.getLocalAddress();
}
public void close() throws IOException {
if (server != null) {
server.close();
}
}
}
==============================================
=================== MServerHandler.java ===========================
package mserver;
import java.io.IOException;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import org.xsocket.Execution;
import org.xsocket.MaxReadSizeExceededException;
import org.xsocket.connection.IConnectHandler;
import org.xsocket.connection.IDataHandler;
import org.xsocket.connection.INonBlockingConnection;
import org.xsocket.connection.IConnection.FlushMode;
@Execution(Execution.NONTHREADED)
public class MServerHandler implements IConnectHandler, IDataHandler {
public static final String DELIMITER = "\r\n";
static Charset charset = Charset.forName("gb2312");
static CharsetDecoder decoder = charset.newDecoder();
static CharBuffer charBuffer = null ;
public boolean onConnect(INonBlockingConnection connection) throws
IOException, BufferUnderflowException, MaxReadSizeExceededException {
connection.setFlushmode(FlushMode.ASYNC);
connection.setAutoflush(false);
// connection.write("Welcome to MServer!");
System.out.println(connection.getRemoteAddress() + " connected!");
return true;
}
public boolean onData(INonBlockingConnection connection) throws
IOException, BufferUnderflowException {
ByteBuffer[] buffer =
connection.readByteBufferByDelimiter(DELIMITER, Integer.MAX_VALUE);
// connection.write("Server: ");
connection.write(buffer);
connection.write(DELIMITER);
for (int j = 0; j < buffer.length; ++j) {
buffer[j].flip();
charBuffer = decoder.decode(buffer[j]);
// System.out.println( " charBuffer= " + charBuffer);
// this line is empty!
System.out.println(charBuffer.toString());
System.out.println(j);
}
connection.flush();
System.out.println("====");
return true;
}
}
=========================================
================= MServerClient.java ========================
package mserver;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.net.Socket;
public class MServerClient {
public void startClient() throws Exception {
int port = 8888;
Socket client = new Socket("localhost", port);
// next step is send a file here.
client.getOutputStream().write("test\r\n".getBytes());
LineNumberReader lnr = new LineNumberReader(
new InputStreamReader(client.getInputStream()));
String response = lnr.readLine();
System.out.println(response);
lnr.close();
client.close();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MServerClient client = new MServerClient();
try {
client.startClient();
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
|
From: Jacek K. <ve...@wp...> - 2008-10-28 15:27:59
|
Gregor,<br><br>Thank you for help. New version of xLightweb worked for me.<br><br>Best regards,<br>Jacek Kolodziejewski<br><br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">Hi,<br><br>I'm going to fix that. <br><br>Meanwhile a new version of xLightweb is available (which does not uses version ranges). Unfortunately the artefacts hasn´t synchronized to the central maven repository, yet. Sourceforge do have problems at the moment.<br> <br>Gregor <br><br><br><div class="gmail_quote">2008/10/23 Jacek Kołodziejewski <span dir="ltr"><ve...@wp...></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Hi,<br> <br> Since 10/19 I'm unable to compile code which uses xlightweb using Maven.<br> The problem I see is:<br> <br> [INFO]<br> ------------------------------------------------------------------------<br> [ERROR] BUILD ERROR<br> [INFO]<br> ------------------------------------------------------------------------<br> [INFO] Failed to resolve artifact.<br> <br> Couldn't find a version in [2.2] to match range [2.1.2,2.2)<br> org.xsocket:xSocket:jar:null<br> <br> from the specified remote repositories:<br> central (<a href="http://repo1.maven.org/maven2" target="_blank">http://repo1.maven.org/maven2</a>)<br> <br> <br> [INFO]<br> ------------------------------------------------------------------------<br> [INFO] For more information, run Maven with the -e switch<br> [INFO]<br> ------------------------------------------------------------------------<br> <br> Dependency in my pom.xml<br> <dependency><br> <groupId>org.xlightweb</groupId><br> <artifactId>xlightweb</artifactId><br> <version>2.0</version><br> <scope>test</scope><br> </dependency><br> <br> I've tried to use all versions of xlightweb available in maven<br> repository but all of them do no work. I've traced what maven do with<br> repository and I see that one of the steps is downloading<br> /nexus/content/repositories/central/org/xsocket/xSocket/maven-metadata.xml<br> and this file contains information about only one version of xsocket<br> (2.2) and xslightweb requires version lower than 2.2<br> version="1.0" encoding="UTF-8"?><metadata><br> <groupId>org.xsocket</groupId><br> <artifactId>xSocket</artifactId><br> <version>2.2</version><br> <versioning><br> <versions><br> <version>2.2</version><br> </versions><br> <lastUpdated>20081019161028</lastUpdated><br> </versioning><br> </metadata><br> <br> Maven repository contains much more versions of xsocket and I think that<br> they should be listed here. I suspect that this caused by<br> mistake made during upload of new xsocket release to maven repository.<br> <br> Best regards,<br> Jacek Kolodziejewski<br> <br> -------------------------------------------------------------------------<br> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge<br> Build the coolest Linux based applications with Moblin SDK & win great prizes<br> Grand prize is a trip for two to an Open Source event anywhere in the world<br> <a href="http://moblin-contest.org/redirect.php?banner_id=100&url=/" target="_blank">http://moblin-contest.org/redirect.php?banner_id=100&url=/</a><br> _______________________________________________<br> xSocket-develop mailing list<br> <a href="mailto:xSo...@li...">xSo...@li...</a><br> <a 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><br><br /><br /><br />----------------------------------------------------<br />Wspomnij Jana Pawła II i innych Wielkich Polaków, <br />których nie ma już z nami. <br />Zapal Wirtualny Znicz - kliknj: <br /><A HREF="http://klik.wp.pl/?adr=http://corto.www.wp.pl/as/znicz01.html&sid=540" TARGET="_blank">http://klik.wp.pl/?adr=http://corto.www.wp.pl/as/znicz01.html&sid=540</A> |
|
From: Gregor R. <gre...@go...> - 2008-10-23 20:13:44
|
Chad, nicely done!. Your tutorial is a small, very understandable tutorial. Thanks Gregor 2008/10/23 Chad Lung <cha...@gm...> > For anyone that is interested I've posted a short tutorial that uses > xSocket 2.2 to talk to Flash CS3. The article is short and simple however I > would appreciate any corrections or clarifications if they are required. > > http://giantflyingsaucer.com/blog/?p=205 > > Thanks, > > Chad Lung > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > > |
|
From: Chad L. <cha...@gm...> - 2008-10-23 19:10:16
|
For anyone that is interested I've posted a short tutorial that uses xSocket 2.2 to talk to Flash CS3. The article is short and simple however I would appreciate any corrections or clarifications if they are required. http://giantflyingsaucer.com/blog/?p=205 Thanks, Chad Lung |
|
From: Gregor R. <gre...@go...> - 2008-10-23 17:10:03
|
Hi, I'm going to fix that. Meanwhile a new version of xLightweb is available (which does not uses version ranges). Unfortunately the artefacts hasn´t synchronized to the central maven repository, yet. Sourceforge do have problems at the moment. Gregor 2008/10/23 Jacek Kołodziejewski <ve...@wp...> > Hi, > > Since 10/19 I'm unable to compile code which uses xlightweb using Maven. > The problem I see is: > > [INFO] > ------------------------------------------------------------------------ > [ERROR] BUILD ERROR > [INFO] > ------------------------------------------------------------------------ > [INFO] Failed to resolve artifact. > > Couldn't find a version in [2.2] to match range [2.1.2,2.2) > org.xsocket:xSocket:jar:null > > from the specified remote repositories: > central (http://repo1.maven.org/maven2) > > > [INFO] > ------------------------------------------------------------------------ > [INFO] For more information, run Maven with the -e switch > [INFO] > ------------------------------------------------------------------------ > > Dependency in my pom.xml > <dependency> > <groupId>org.xlightweb</groupId> > <artifactId>xlightweb</artifactId> > <version>2.0</version> > <scope>test</scope> > </dependency> > > I've tried to use all versions of xlightweb available in maven > repository but all of them do no work. I've traced what maven do with > repository and I see that one of the steps is downloading > /nexus/content/repositories/central/org/xsocket/xSocket/maven-metadata.xml > and this file contains information about only one version of xsocket > (2.2) and xslightweb requires version lower than 2.2 > version="1.0" encoding="UTF-8"?><metadata> > <groupId>org.xsocket</groupId> > <artifactId>xSocket</artifactId> > <version>2.2</version> > <versioning> > <versions> > <version>2.2</version> > </versions> > <lastUpdated>20081019161028</lastUpdated> > </versioning> > </metadata> > > Maven repository contains much more versions of xsocket and I think that > they should be listed here. I suspect that this caused by > mistake made during upload of new xsocket release to maven repository. > > Best regards, > Jacek Kolodziejewski > > ---------------------------------------------------- > ATRAKCYJNE NIERUCHOMOŚCI W ZAKOPANEM !!! > Apartamenty, Domy, Działki, Pensjonaty, Hotele, Lokale użytkowe... > Kliknij: http://klik.wp.pl/?adr=www.bachledanieruchomosci.pl&sid=528 > > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > |
|
From: Jacek K. <ve...@wp...> - 2008-10-23 09:08:25
|
Hi, Since 10/19 I'm unable to compile code which uses xlightweb using Maven. The problem I see is: [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Failed to resolve artifact. Couldn't find a version in [2.2] to match range [2.1.2,2.2) org.xsocket:xSocket:jar:null from the specified remote repositories: central (http://repo1.maven.org/maven2) [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ Dependency in my pom.xml <dependency> <groupId>org.xlightweb</groupId> <artifactId>xlightweb</artifactId> <version>2.0</version> <scope>test</scope> </dependency> I've tried to use all versions of xlightweb available in maven repository but all of them do no work. I've traced what maven do with repository and I see that one of the steps is downloading /nexus/content/repositories/central/org/xsocket/xSocket/maven-metadata.xml and this file contains information about only one version of xsocket (2.2) and xslightweb requires version lower than 2.2 version="1.0" encoding="UTF-8"?><metadata> <groupId>org.xsocket</groupId> <artifactId>xSocket</artifactId> <version>2.2</version> <versioning> <versions> <version>2.2</version> </versions> <lastUpdated>20081019161028</lastUpdated> </versioning> </metadata> Maven repository contains much more versions of xsocket and I think that they should be listed here. I suspect that this caused by mistake made during upload of new xsocket release to maven repository. Best regards, Jacek Kolodziejewski ---------------------------------------------------- Niezwykła i egzotyczna chińska saga, w której realizm splata się z bajkowością. To powieść o dojrzewaniu, miłości, zemście i przeznaczeniu."Bracia" - Da Chen. Już w księgarniach! http://klik.wp.pl/?adr=http%3A%2F%2Fcorto.www.wp.pl%2Fas%2Fbracia2.html&sid=527 |
|
From: Jacek K. <ve...@wp...> - 2008-10-23 08:49:18
|
Hi, Since 10/19 I'm unable to compile code which uses xlightweb using Maven. The problem I see is: [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Failed to resolve artifact. Couldn't find a version in [2.2] to match range [2.1.2,2.2) org.xsocket:xSocket:jar:null from the specified remote repositories: central (http://repo1.maven.org/maven2) [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ Dependency in my pom.xml <dependency> <groupId>org.xlightweb</groupId> <artifactId>xlightweb</artifactId> <version>2.0</version> <scope>test</scope> </dependency> I've tried to use all versions of xlightweb available in maven repository but all of them do no work. I've traced what maven do with repository and I see that one of the steps is downloading /nexus/content/repositories/central/org/xsocket/xSocket/maven-metadata.xml and this file contains information about only one version of xsocket (2.2) and xslightweb requires version lower than 2.2 version="1.0" encoding="UTF-8"?><metadata> <groupId>org.xsocket</groupId> <artifactId>xSocket</artifactId> <version>2.2</version> <versioning> <versions> <version>2.2</version> </versions> <lastUpdated>20081019161028</lastUpdated> </versioning> </metadata> Maven repository contains much more versions of xsocket and I think that they should be listed here. I suspect that this caused by mistake made during upload of new xsocket release to maven repository. Best regards, Jacek Kolodziejewski ---------------------------------------------------- ATRAKCYJNE NIERUCHOMOŚCI W ZAKOPANEM !!! Apartamenty, Domy, Działki, Pensjonaty, Hotele, Lokale użytkowe... Kliknij: http://klik.wp.pl/?adr=www.bachledanieruchomosci.pl&sid=528 |