xsocket-develop Mailing List for xsocket (Page 15)
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: Dragan G. <dg...@gm...> - 2008-07-31 15:26:04
|
Hi all, I'm using xSocket to write proxy which will use information from client SSL certificate in order to forward to one of the possible target URLs. I have used HttpProxy example from xsocketHttp V2_0_beta1 and added SSL support using SSLContext. That all is working, but I'm having problems to get right SSLSession object from SSLContext because I need id of the session in order to do that (I need SSLSession object in order to reach client SSL certificate). So if I pass SSLContext reference to my ForwardHandler and do something like this: SSLSessionContext sslSessionContext = sslContext.getServerSessionContext(); I just need sessionId in order to get SSLSession object.This id can be reached via SSLSocket for example, but I don't see how to get it. Is there any other way to get client SSL certificate in mutual SSL authentication case? |
|
From: Bjarki B. <bja...@gm...> - 2008-07-31 15:05:25
|
Greetings, I came across the xSocket via this article: http://www.javaworld.com/javaworld/jw-03-2008/jw-03-asynchhttp.html?page=1 I have been working on a bayeux java implementation (as a part of my masters dissertation) and I took a look at your SVN repository where you have a bayeux implementation going. Would you say that your bayeux implementation is fairly mature? I would like to get a nonblocking java bayeux client working, how much work needs to be done on yours? Maybe I can expand on it and implement what is left? Why are all of the classes in org.xsocket.bayeux.http defined as "final class.."? I'm not able to instansiate any of those classes unless my class is in the same package. Is that the idea? Regards, - Bjarki Bjorgulfsson |
|
From: Nico H. <ni...@ge...> - 2008-07-23 12:25:58
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
The code examples doesnt work. <br>
<br>
<br>
<div class="moz-signature">-- <br>
<meta http-equiv="Content-Type" content="text/html; ">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949.27">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Grande}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Grande; min-height: 15.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Lucida Grande; color: #808080}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Lucida Grande; color: #808080; min-height: 12.0px}
</style>
<p class="p1"><b>Dipl. Inf. (FH) Nico Haberer</b></p>
<p class="p2"><br>
</p>
<p class="p3"><img src="cid:par...@ge..."></p>
<p class="p3">Brauchst du es auch jeden Tag?</p>
<p class="p4"><br>
</p>
<p class="p3">Fon: (0681) - 91 00 57 67</p>
<p class="p3">Fax: (0681) - 91 00 57 69</p>
<p class="p4"><br>
</p>
<p class="p3">E-Mail: <a class="moz-txt-link-abbreviated" href="mailto:ni...@ge...">ni...@ge...</a></p>
<p class="p4"><br>
</p>
<p class="p3">Amtsgericht Saarbrücken HRA 10128</p>
<p class="p3">Geschäftsführer: Dipl. Inf. (FH) Kevin Dewi, Michael
Zimmer</p>
</div>
</body>
</html>
|
|
From: Gregor R. <gre...@go...> - 2008-07-18 13:18:21
|
Hi Maurizio, thanks for your feedback. I'm going write some JUnit-Tests based on your code. The next version of xSocket-http 2.0 (beta-2) should fix these bugs. Because beta-2 is a performance and bug fixing release, your wishes will be input for the following version xSocket-http 2.0 (final). Gregor 2008/7/18 Masar <ma...@ma...>: > > Hi Gregor, > I did some test with your library and found it very useful. > In the attach you can find a sample HttpClient I did to test the lib: > feel free to include it in the library if you think it could be useful > as a sample. > > Now I can tell you the problems I found; I did my tests on Linux with > Sun java version "1.6.0_06", xSocket-2.1.jar, xSocket-http-2.0-beta-1.jar > > 1) When I do httpClient.close() some TCP connections are non closed > immediately but remain connected to the remote hosts for about 40 > seconds (see *2). If I use the non pooled version > httpClient.setPooled(false) I do not have the problem. > > 2) If there is an host that is non existant (es: > www.asdasdadasdasdasdasd.com) > the problem is worst, all the connections are not closed. > > 3) If there is a non responding host (es: http://www.google.com:81) I > cannot control the TCP timeout because it seems I have no access to > the HttpClientConnection to set the parameter SO_TIMEOUT. > > Next two wishes: > 1) It could be useful to have an Attachment in the HttpClient send, > that I could retrieve from IHttpResponseHandler, this would let me use > a single instance of IHttpResponseHandler instead of one for each > Request. > > HttpClient > void send(IHttpRequest request, IHttpResponseHandler > responseHandler, > Object oAttachment) > > IHttpResponseHandler > void onResponse(IHttpResponse response, Object oAttachment) > void onException(IOException ioe, Object oAttachment) > > 2) I don't like annotations used to modify a function mode of operation, > because they are difficult to document and easily to forget, I would > prefer > a flag in HttpClient to specify the InvokeOn mode of operation. > > Thanks > > Maurizio Sartori > > > ------------------------------------------------------------------------- > 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: Masar <ma...@Ma...> - 2008-07-18 13:03:57
|
Hi Gregor, I did some test with your library and found it very useful. In the attach you can find a sample HttpClient I did to test the lib: feel free to include it in the library if you think it could be useful as a sample. Now I can tell you the problems I found; I did my tests on Linux with Sun java version "1.6.0_06", xSocket-2.1.jar, xSocket-http-2.0-beta-1.jar 1) When I do httpClient.close() some TCP connections are non closed immediately but remain connected to the remote hosts for about 40 seconds (see *2). If I use the non pooled version httpClient.setPooled(false) I do not have the problem. 2) If there is an host that is non existant (es: www.asdasdadasdasdasdasd.com) the problem is worst, all the connections are not closed. 3) If there is a non responding host (es: http://www.google.com:81) I cannot control the TCP timeout because it seems I have no access to the HttpClientConnection to set the parameter SO_TIMEOUT. Next two wishes: 1) It could be useful to have an Attachment in the HttpClient send, that I could retrieve from IHttpResponseHandler, this would let me use a single instance of IHttpResponseHandler instead of one for each Request. HttpClient void send(IHttpRequest request, IHttpResponseHandler responseHandler, Object oAttachment) IHttpResponseHandler void onResponse(IHttpResponse response, Object oAttachment) void onException(IOException ioe, Object oAttachment) 2) I don't like annotations used to modify a function mode of operation, because they are difficult to document and easily to forget, I would prefer a flag in HttpClient to specify the InvokeOn mode of operation. Thanks Maurizio Sartori |
|
From: Masar <ma...@Ma...> - 2008-07-18 12:54:04
|
Hi Gregor, I did some test with your library and found it very useful. In the attach you can find a sample HttpClient I did to test the lib: feel free to include it in the library if you think it could be useful as a sample. Now I can tell you the problems I found; I did my tests on Linux with Sun java version "1.6.0_06", xSocket-2.1.jar, xSocket-http-2.0-beta-1.jar 1) When I do httpClient.close() some TCP connections are non closed immediately but remain connected to the remote hosts for about 40 seconds (see *2). If I use the non pooled version httpClient.setPooled(false) I do not have the problem. 2) If there is an host that is non existant (es: www.asdasdadasdasdasdasd.com) the problem is worst, all the connections are not closed. 3) If there is a non responding host (es: http://www.google.com:81) I cannot control the TCP timeout because it seems I have no access to the HttpClientConnection to set the parameter SO_TIMEOUT. Next two wishes: 1) It could be useful to have an Attachment in the HttpClient send, that I could retrieve from IHttpResponseHandler, this would let me use a single instance of IHttpResponseHandler instead of one for each Request. HttpClient void send(IHttpRequest request, IHttpResponseHandler responseHandler, Object oAttachment) IHttpResponseHandler void onResponse(IHttpResponse response, Object oAttachment) void onException(IOException ioe, Object oAttachment) 2) I don't like annotations used to modify a function mode of operation, because they are difficult to document and easily to forget, I would prefer a flag in HttpClient to specify the InvokeOn mode of operation. Thanks Maurizio Sartori |
|
From: Masar <ma...@Ma...> - 2008-07-18 12:31:15
|
The missing file |
|
From: Poladian, G. <gra...@ci...> - 2008-06-26 11:28:51
|
Thanks. Will do.
_____
From: Gregor Roth [mailto:gre...@go...]
Sent: Thursday, June 26, 2008 1:31 AM
To: xSo...@li...
Cc: Poladian, Grant [CMB-IT]
Subject: Re: [xSocket-develop] xsocket ssl through proxy problem
Hi Grant,
this seems to be a bug. I supposes xSocket interprets the http
connection as 'non persistent' by receiving the CONNECT response. This
could be the reason why the connection is disconnected.
Please file the bug
Thanks
Gregor
2008/6/25 Poladian, Grant <gra...@ci...>:
First, very nice job with this library. Its very well organized
and works well.
Currently, using xsocket 2.1 and http 2.0 beta 1.
When connecting to https server through a proxy the following
combination does not work.
--------------------------------------------
HttpRequest connect_http = new
HttpRequest("CONNECT","somecompany.com:443");
...
NonBlockingConnection proxy_conn = new
NonBlockingConnection("proxy.net",8080,ssl_context,false);
HttpClientConnection http_conn = new HttpClientConnection
(proxy_conn);
IHttpResponse connect_response = proxy_conn.call(connect_http);
Thread.sleep(2000);
System.out.println("Activating Secure Mode ...");
http_conn.activateSecureMode();
Getting the following exception:
Activating Secure Mode ...
java.nio.channels.ClosedChannelException
at
org.xsocket.connection.AbstractNonBlockingStream.readByteBufferByLength(
AbstractNonBlockingStream.java:546)
at
org.xsocket.connection.NonBlockingConnection.readByteBufferByLength(NonB
lockingConnection.java:1259)
at
org.xsocket.connection.NonBlockingConnection.activateSecuredMode(NonBloc
kingConnection.java:1212)
at
org.xsocket.connection.http.AbstractHttpConnection.activateSecuredMode(A
bstractHttpConnection.java:429)
--------------------------------------------
However, the following works fine
--------------------------------------------
static String CONNECT_STRING = "CONNECT somecompany.com:443
HTTP/1.1\r\n"
+"Connection: keep-alive\r\n"
+"Proxy-Connection: keep-alive\r\n"
+"Pragma: no-cache\r\n"
+"Keep-Alive: 300\r\n"
+"Host: somecompany.com:443\r\n"
+"\r\n";
NonBlockingConnection proxy_conn = new
NonBlockingConnection("proxy.net",8080,ssl_context,false);
proxy_conn.write(CONNECT_STRING);
proxy_conn.flush();
while(not_finished_reading) {
proxy_conn.read(...)
}
proxy_conn.activateSecuredMode();
--------------------------------------------
After stepping through the code a bit it seems that the channel
is being closed after the CONNECT
request is processed. So the subsequent handshake fails. You
need to be stepping in the dispather and main
threads to see this.
Regards,
Grant
------------------------------------------------------------------------
-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
xSocket-develop mailing list
xSo...@li...
https://lists.sourceforge.net/lists/listinfo/xsocket-develop
|
|
From: Gregor R. <gre...@go...> - 2008-06-26 05:31:10
|
Hi Grant,
this seems to be a bug. I supposes xSocket interprets the http connection as
'non persistent' by receiving the CONNECT response. This could be the reason
why the connection is disconnected.
Please file the bug
Thanks
Gregor
2008/6/25 Poladian, Grant <gra...@ci...>:
>
> First, very nice job with this library. Its very well organized and works
> well.
> Currently, using xsocket 2.1 and http 2.0 beta 1.
>
> When connecting to https server through a proxy the following combination
> does not work.
>
> --------------------------------------------
> HttpRequest connect_http = new HttpRequest("CONNECT","somecompany.com:443
> ");
> ...
> NonBlockingConnection proxy_conn = new NonBlockingConnection("proxy.net
> ",8080,ssl_context,false);
> HttpClientConnection http_conn = new HttpClientConnection (proxy_conn);
>
> IHttpResponse connect_response = proxy_conn.call(connect_http);
>
> Thread.sleep(2000);
> System.out.println("Activating Secure Mode ...");
> http_conn.activateSecureMode();
>
> Getting the following exception:
>
> Activating Secure Mode ...
> java.nio.channels.ClosedChannelException
> at
> org.xsocket.connection.AbstractNonBlockingStream.readByteBufferByLength(AbstractNonBlockingStream.java:546)
> at
> org.xsocket.connection.NonBlockingConnection.readByteBufferByLength(NonBlockingConnection.java:1259)
> at
> org.xsocket.connection.NonBlockingConnection.activateSecuredMode(NonBlockingConnection.java:1212)
> at
> org.xsocket.connection.http.AbstractHttpConnection.activateSecuredMode(AbstractHttpConnection.java:429)
> --------------------------------------------
>
> However, the following works fine
>
> --------------------------------------------
> static String CONNECT_STRING = "CONNECT somecompany.com:443 HTTP/1.1\r\n"
> +"Connection: keep-alive\r\n"
> +"Proxy-Connection: keep-alive\r\n"
> +"Pragma: no-cache\r\n"
> +"Keep-Alive: 300\r\n"
> +"Host: somecompany.com:443\r\n"
> +"\r\n";
> NonBlockingConnection proxy_conn = new NonBlockingConnection("proxy.net
> ",8080,ssl_context,false);
> proxy_conn.write(CONNECT_STRING);
> proxy_conn.flush();
>
> while(not_finished_reading) {
> proxy_conn.read(...)
> }
>
> proxy_conn.activateSecuredMode();
> --------------------------------------------
>
> After stepping through the code a bit it seems that the channel is being
> closed after the CONNECT
> request is processed. So the subsequent handshake fails. You need to be
> stepping in the dispather and main
> threads to see this.
>
> Regards,
> Grant
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|
|
From: Gregor R. <gre...@go...> - 2008-06-26 04:15:01
|
Hi Joe, cookie-support is on the roadmap for the next release Gregor 2008/6/26 Joe Chen <joe...@gm...>: > Hi all, > Is it possible to set cookies for the HTTPClient? I wasn't able to find > any method that would allow me to do this. > > Thanks, > Joe > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > > |
|
From: Joe C. <joe...@gm...> - 2008-06-26 01:38:20
|
Hi all, Is it possible to set cookies for the HTTPClient? I wasn't able to find any method that would allow me to do this. Thanks, Joe |
|
From: Poladian, G. <gra...@ci...> - 2008-06-25 20:57:24
|
First, very nice job with this library. Its very well organized and
works well.
Currently, using xsocket 2.1 and http 2.0 beta 1.
When connecting to https server through a proxy the following
combination does not work.
--------------------------------------------
HttpRequest connect_http = new
HttpRequest("CONNECT","somecompany.com:443");
...
NonBlockingConnection proxy_conn = new
NonBlockingConnection("proxy.net",8080,ssl_context,false);
HttpClientConnection http_conn = new HttpClientConnection (proxy_conn);
IHttpResponse connect_response = proxy_conn.call(connect_http);
Thread.sleep(2000);
System.out.println("Activating Secure Mode ...");
http_conn.activateSecureMode();
Getting the following exception:
Activating Secure Mode ...
java.nio.channels.ClosedChannelException
at
org.xsocket.connection.AbstractNonBlockingStream.readByteBufferByLength(
AbstractNonBlockingStream.java:546)
at
org.xsocket.connection.NonBlockingConnection.readByteBufferByLength(NonB
lockingConnection.java:1259)
at
org.xsocket.connection.NonBlockingConnection.activateSecuredMode(NonBloc
kingConnection.java:1212)
at
org.xsocket.connection.http.AbstractHttpConnection.activateSecuredMode(A
bstractHttpConnection.java:429)
--------------------------------------------
However, the following works fine
--------------------------------------------
static String CONNECT_STRING = "CONNECT somecompany.com:443
HTTP/1.1\r\n"
+"Connection: keep-alive\r\n"
+"Proxy-Connection: keep-alive\r\n"
+"Pragma: no-cache\r\n"
+"Keep-Alive: 300\r\n"
+"Host: somecompany.com:443\r\n"
+"\r\n";
NonBlockingConnection proxy_conn = new
NonBlockingConnection("proxy.net",8080,ssl_context,false);
proxy_conn.write(CONNECT_STRING);
proxy_conn.flush();
while(not_finished_reading) {
proxy_conn.read(...)
}
proxy_conn.activateSecuredMode();
--------------------------------------------
After stepping through the code a bit it seems that the channel is being
closed after the CONNECT
request is processed. So the subsequent handshake fails. You need to be
stepping in the dispather and main
threads to see this.
Regards,
Grant
|
|
From: Gregor R. <gre...@go...> - 2008-06-22 05:36:37
|
Hi, xSocket core and the extension modules xSocket-http/xSocket-multiplexed have been released: xSocket V2.1 issues: - performance improvements (e.g. direct write by bypassing the selector loop in non threaded mode) - "true" support of replacing a handler at runtime (see also tutorial chapter 14 example) - additional convenience methods (e.g. <IServer>.start(), …) - improved user level flow control - some bug fixes (ssl, …) - tutorial update (clarifications and new chapters like 'using xSocket & Spring together') xSocket-http V2.0-beta-1 issues: - (last) major 2.0 API changes (e.g. server side handling) - uniform filter design for the client and server side - cleaning and harmonizing of the client und server-side methods - some bug fixes - tutorial update xSocket-multiplexed V2.0 issues: - minor adaptations to xSocket2.1 Gregor |
|
From: Gregor R. <gre...@go...> - 2008-06-17 12:06:47
|
Hi Mihail, a simple,latency-oriented test for an echo server can be found under http://xsocket.sourceforge.net/performance/performance_v2_0.htm Gregor 2008/6/17 Mihail Kostira <mih...@ma...>: > Hello, > > I'm building a non-blocking, TCP/IP socket server that will need to > support many clients simultaneously. > xSocket is looking very promising and I would like to get an idea how > stable and fast it is. Are there any xSocket stress tests and > benchmarks out there? > > Thanks, > > Mihail > > > > > ------------------------------------- > Powered by Mail.BG - http://mail.bg > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > |
|
From: Mihail K. <mih...@ma...> - 2008-06-17 11:52:24
|
Hello, I'm building a non-blocking, TCP/IP socket server that will need to support many clients simultaneously. xSocket is looking very promising and I would like to get an idea how stable and fast it is. Are there any xSocket stress tests and benchmarks out there? Thanks, Mihail ------------------------------------- Powered by Mail.BG - http://mail.bg |
|
From: Gregor R. <gre...@go...> - 2008-06-17 05:51:45
|
Hi Robert, in case of a disconnect the IDataHandler handler will be called before performing the IDisconnectHandler (if present). By performing a connection's read method a ClosedChannelException will be thrown. To check if the channel is open, just call the INonBlockingConnection's available() method. This method will return -1 in case of a closed channel. Please consider the different cases of disconnecting (see tutorial). Sometime connections break in such a way that the VM doesn't detect this. Such disconnects will only be detected by performing read or write operations. Gregor 2008/6/16 Robert Wierschke <wie...@go...>: > Hi, > > I'm getting a ClosedChannleException in the server handlers onData method > after calling Server.close(). > > Why does this happen? > > regards > robert > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > > |
|
From: Robert W. <wie...@go...> - 2008-06-16 20:42:01
|
Hi, I'm getting a ClosedChannleException in the server handlers onData method after calling Server.close(). Why does this happen? regards robert |
|
From: Gregor R. <gre...@go...> - 2008-06-15 17:55:01
|
Hi Robert,
the problem here is that the BlockingConnection replaces the assigned
handler of the NonBlockingConection by an internal one. The internal handler
is used by the BlockingConnection to be notified about network events.
Unfortunately this is not documented. I'm going to do this.
The workaround for your code is to set the origin handler by leaving the
onData method.
class TWPHandler implements IDataHandler, IConnectionScoped {
public boolean onData(INonBlockingConnection nbc) throws IOException,
BufferUnderflowException, MaxReadSizeExceededException {
IBlockingConnection bc = new BlockingConnection(nbc);
switch (this.mode) {
case INIT:
this.init(bc);
this.mode = MESSAGE;
case MESSAGE:
int messageId = this.readMessageId(bc);
Class<?> messageType = classForId.get(messageId);
Object requestMessage = this.readRequestMessage(bc,
messageType);
// handle the message
Object replyMessage =
handlerForClass.get(messageType).onMessage(requestMessage);
this.writeReplyMessage(bc, replyMessage);
}
nbc.setHandler(this);
return true;
}
}
regards
Gregor
2008/6/15 Robert Wierschke <wie...@go...>:
> Hi,
>
> how do I create a blocking server using streams? My current try only
> accepts one "message" per connection and than hangs!
>
> I just started using xSocket and have the following problem:
>
> I already have some (un-)/marshaling mechanism that I need to use on the
> server side. This mechanism unfortunately works with streams so I used
> Channels method to create a stream from the connection object
>
> private Object readRequestMessage(IBlockingConnection bc, Class<?>
> messageType) throws IOException {
>
> // wrap an InputStream around the incomming data to feed it into
> the unmarshaller
> InputStream in = Channels.newInputStream(bc);
>
> Unmarshaller unmarshaller = new Unmarshaller(in);
>
> Object result = unmarshaller.unmarshalMessage(messageType);
>
> return result;
>
> }
>
> private void writeReplyMessage(IBlockingConnection bc, Object
> replyMessage) throws IOException {
>
> if (replyMessage == null)
>
> return; // nothing to do
>
> OutputStream out = Channels.newOutputStream(bc);
>
> StructuredDataMarsahller marshaller = new
> StructuredDataMarsahller(out);
>
> marshaller.marshal(replyMessage);
>
> }
>
> Both messages are called from IDataHandler.onData
>
> class TWPHandler implements IDataHandler, IConnectionScoped {
>
> public boolean onData(INonBlockingConnection nbc) throws IOException,
> BufferUnderflowException, MaxReadSizeExceededException {
>
> IBlockingConnection bc = new BlockingConnection(nbc);
>
> switch (this.mode) {
>
> case INIT:
>
> this.init(bc);
>
> this.mode = MESSAGE;
>
> case MESSAGE:
>
> int messageId = this.readMessageId(bc);
> Class<?> messageType = classForId.get(messageId);
>
> Object requestMessage = this.readRequestMessage(bc,
> messageType);
> // handle the message
>
> Object replyMessage =
> handlerForClass.get(messageType).onMessage(requestMessage);
>
> this.writeReplyMessage(bc, replyMessage);
>
> }
> return true;
>
> }
> }
>
> I'm also using mark support because I need to read some bytes that the
> unmarshaller need to read again.
>
> private int readMessageId(IBlockingConnection bc) throws IOException
> {
>
> int messageId;
>
> synchronized (bc) {
>
> bc.markReadPosition();
>
> // read message id
> // ...
> bc.resetToReadMark(); // so that the id can be read again by
> the unmarshaller
>
> }
>
> return messageId;
>
> }
>
> This all works fine if there is only one request and one response message
> per connection. But if I try to send another request message on the same
> connection the server hangs forever.
>
> So what am I doing wrong?
>
> thanks in advance
> robert
>
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|
|
From: Gregor R. <gre...@go...> - 2008-06-15 17:54:33
|
Hi Stefan, you are right. By creating a (client-side) connection, the constructor call blocks until the connection has been connected. By adding a new constructor parameter (boolean waitForConnect), this behaviour will be controlled by the user. The upcoming version 2.1 will support this constructor parameter. xSocket-multiplexed doesn't support pipeline priorities. This will be a new feature. Gregor 2008/6/15 Stefan Ackermann <st...@gm...>: > Hi there > > I am thinking about replacing mina with xsocket in my p2p application > (tcpfile). Up until now I only have 2 questions: > > 1) > How can I connect non-blocking? When I create a NonBlockingConnection, it > immediately blocks until it is connected (or did I miss something?) > I would like to have a callback once it is connected. > > 2) > With the multiplexing: Is it possible to assign priorities to the > Pipelines? So I could send something big on one pipeline, and send > something small on another pipeline with a higher priority? > > So far what I have seen I really liked. It seems much simpler than mina, > and has more features that I care about... Keep it up :) > > Stefan > > > -- > Stefan Ackermann, > st...@gm... > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > |
|
From: Robert W. <wie...@go...> - 2008-06-15 10:57:03
|
Hi,
how do I create a blocking server using streams? My current try only accepts
one "message" per connection and than hangs!
I just started using xSocket and have the following problem:
I already have some (un-)/marshaling mechanism that I need to use on the
server side. This mechanism unfortunately works with streams so I used
Channels method to create a stream from the connection object
private Object readRequestMessage(IBlockingConnection bc, Class<?>
messageType) throws IOException {
// wrap an InputStream around the incomming data to feed it into
the unmarshaller
InputStream in = Channels.newInputStream(bc);
Unmarshaller unmarshaller = new Unmarshaller(in);
Object result = unmarshaller.unmarshalMessage(messageType);
return result;
}
private void writeReplyMessage(IBlockingConnection bc, Object
replyMessage) throws IOException {
if (replyMessage == null)
return; // nothing to do
OutputStream out = Channels.newOutputStream(bc);
StructuredDataMarsahller marshaller = new
StructuredDataMarsahller(out);
marshaller.marshal(replyMessage);
}
Both messages are called from IDataHandler.onData
class TWPHandler implements IDataHandler, IConnectionScoped {
public boolean onData(INonBlockingConnection nbc) throws IOException,
BufferUnderflowException, MaxReadSizeExceededException {
IBlockingConnection bc = new BlockingConnection(nbc);
switch (this.mode) {
case INIT:
this.init(bc);
this.mode = MESSAGE;
case MESSAGE:
int messageId = this.readMessageId(bc);
Class<?> messageType = classForId.get(messageId);
Object requestMessage = this.readRequestMessage(bc,
messageType);
// handle the message
Object replyMessage =
handlerForClass.get(messageType).onMessage(requestMessage);
this.writeReplyMessage(bc, replyMessage);
}
return true;
}
}
I'm also using mark support because I need to read some bytes that the
unmarshaller need to read again.
private int readMessageId(IBlockingConnection bc) throws IOException {
int messageId;
synchronized (bc) {
bc.markReadPosition();
// read message id
// ...
bc.resetToReadMark(); // so that the id can be read again by
the unmarshaller
}
return messageId;
}
This all works fine if there is only one request and one response message
per connection. But if I try to send another request message on the same
connection the server hangs forever.
So what am I doing wrong?
thanks in advance
robert
|
|
From: Stefan A. <st...@gm...> - 2008-06-15 10:07:42
|
Hi there I am thinking about replacing mina with xsocket in my p2p application (tcpfile). Up until now I only have 2 questions: 1) How can I connect non-blocking? When I create a NonBlockingConnection, it immediately blocks until it is connected (or did I miss something?) I would like to have a callback once it is connected. 2) With the multiplexing: Is it possible to assign priorities to the Pipelines? So I could send something big on one pipeline, and send something small on another pipeline with a higher priority? So far what I have seen I really liked. It seems much simpler than mina, and has more features that I care about... Keep it up :) Stefan -- Stefan Ackermann, st...@gm... |
|
From: <gre...@we...> - 2008-06-06 15:05:11
|
Hi Simon, connections through a proxy server hasn't yet implemented for xSocket-http. It's on the roadmap Gregor > -----Ursprüngliche Nachricht----- > Von: <xso...@li...> > Gesendet: 06.06.08 13:34:50 > An: xso...@li... > Betreff: xSocket-develop post from si...@sp... requires approval > As list administrator, your authorization is requested for the > following mailing list posting: > > List: xSo...@li... > From: si...@sp... > Subject: Connecting to web-server through Proxy using xsocket > Reason: Post by non-member to a members-only list > > At your convenience, visit: > > https://lists.sourceforge.net/lists/admindb/xsocket-develop > > to approve or deny the request. > > > <hr> > Hey all, > > I have the following problem: > > I want to connect to a webserver using the following snippet: > > IHttpClientEndpoint httpClientConnection = new > HttpClientConnection("www.google.com", 80); > HttpRequest httpRequest= new GetRequest(query); > HttpResponse response = httpClientConnection.call(httpRequest); > > The snippet hangs on the first line already - probably because I am > behind a web-proxy. > The exception: > > java.net.ConnectException: java.net.NoRouteToHostException: No route > to host: no further information > > > Setting the respective System Properties > -Dhttp.proxyHost=myproxy.xyz.com -Dhttp.proxyPort=3128 > doesn't help. > > Am I doing something wrong or is this a problem with xsocket? > > Thanks for your help, > Simon > > > > <hr> > If you reply to this message, keeping the Subject: header intact, > Mailman will discard the held message. Do this if the message is > spam. If you reply to this message and include an Approved: header > with the list password in it, the message will be approved for posting > to the list. The Approved: header can also appear in the first line > of the body of the reply. > -- Gregor Roth |
|
From: Simon S. (spamato.net) <si...@sp...> - 2008-06-06 11:34:16
|
Hey all,
I have the following problem:
I want to connect to a webserver using the following snippet:
IHttpClientEndpoint httpClientConnection = new
HttpClientConnection("www.google.com", 80);
HttpRequest httpRequest= new GetRequest(query);
HttpResponse response = httpClientConnection.call(httpRequest);
The snippet hangs on the first line already - probably because I am
behind a web-proxy.
The exception:
java.net.ConnectException: java.net.NoRouteToHostException: No route
to host: no further information
Setting the respective System Properties
-Dhttp.proxyHost=myproxy.xyz.com -Dhttp.proxyPort=3128
doesn't help.
Am I doing something wrong or is this a problem with xsocket?
Thanks for your help,
Simon
|
|
From: Gregor R. <gre...@go...> - 2008-06-01 14:33:21
|
Hi Jeff,
by using a connection scoped handler you have to use such a singleton
approach.
By the way, the Server class of the upcoming version 2.0.1 of xSocket-core
will support a new method getOpenConnections() to fetch the currently
running connections.
Gregor
2008/5/30 Jeff Crane <JC...@sp...>:
> I don't think I'm really using multiplexing, but I did start with the
> multiplexed server 2.0b1 code.
>
> I don't think about indexing the openConnections in the Handler because I
> failed to mention they are IConnectionScoped
>
>
>
> However, I have a singleton that does basically the same thing as you have
> illustrated.
>
>
>
> Psuedocode of my serverside network architecture:
>
>
>
> ServerHandler serverProtocolHandler = new ServerHandler();
>
> ServerHandler.addMyEventListener(Provider.getSingletonController()); // It
> has implemented IMyListener
>
> ...
>
> ConnectionUtils.start(server);
>
> ---
>
>
>
> ServerHandler implements
>
> IConnectHandler, IDisconnectHandler,
>
> IDataHandler, IIdleTimeoutHandler,
>
> IConnectionTimeoutHandler, IConnectionScoped
>
>
>
> boolean authorized = false;
>
> INonBlockingConnection connection; // For disconnect method.
> Not copied in this.copy().
>
>
>
> onConnection
>
> connection.setIdleTimeoutMillis(30 * 60 * 1000);
>
>
>
> onData
>
> this.connection = connection;
>
> try{
>
> byte[] readBytes =
> connection.readBytesByDelimiter(Constants.NETWORK_DELIMITER,length);
>
> ByteArrayInputStream bis = new
> ByteArrayInputStream(readBytes);
>
> ObjectInputStream incomingMyEventStream = new
> ObjectInputStream(bis);
>
> incomingMyEvent =
> incomingMyEventStream.readObject();
>
>
>
> if(this.authorized)
>
> {
>
> if(incomingMyEvent.getType() > 0) //
> Double check object is good by using a method
>
>
> fireEvent((castBasedOnSwitch)incomingMyEvent)
>
> }
>
> else // Must be initial message. Better be a login.
>
> {
>
>
> ((LoginMyEvent)incomingMyEvent).setConnection(connection);
>
>
> ((LoginMyEvent)incomingMyEvent).setConnectionHandler(this);
>
> fireEvent(incomingMyEvent);
>
> }
>
> catch(Exception e)
>
> {
>
> this.disconnect(); // Contains try{}catch{} for
> disconnect
>
> }
>
>
>
> ---
>
>
>
> SingletonController
>
>
>
> HashMap eventCommandMap;
>
>
>
> void handle(MyEvent event)
>
>
> eventCommandMap.get(Integer.valueOf(event.getType())).execute(event);
>
>
>
> ---
>
>
>
> LoginCommand
>
>
>
> void execute(MyEvent event)
>
> // Database lookup or whatever you want to store accounts in.
>
> int id = lookup( ((LoginMyEvent)event).getUserName(),
> ((LoginMyEvent)event).getPassword() );
>
>
>
> // however you want to check it, > -1 or != 0 or whatever. Also
> can create persistent serverside object in the validate(int).
>
> if(validate(id))
>
> ){
>
> // For indexing serverside persistent
> object->connection together. See addValidConnection(LoginMyEvent)
>
> ((LoginMyEvent)event).setId(id);
>
>
> ((LoginMyEvent)event).getConnectionHandler().setAuthorized(true);
>
>
>
> // ApplicationModel is application state data and
> accessors only.
>
>
> Provider.getSingletonController().getApplicationModel().addValidConnection((LoginMyEvent)event);
>
> }
>
> else
>
> {
>
>
> ((LoginMyEvent)event).getConnectionHandler().disconnect();
>
> }
>
>
>
> ---
>
>
>
> ApplicationModel:
>
>
>
> Set<Integer,INonBlockingConnection> validConnections;
>
>
>
> void addValidConnection(LoginMyEvent loginMyEvent)
>
> synchronized(validConnections)
>
>
> validConnections.put(Integer.valueOf(loginMyEvent.getId()),loginMyEvent.getConnection());
>
>
>
> ---
>
>
>
> The client uses the standard NIO client implementation found at
> http://rox-xmlrpc.sourceforge.net/niotut/
>
>
>
> Both client and Server have GUIs that an event-driven MVC with the
> singleton controller and an extra presentation layer for where SWING falls
> down.
>
>
>
> I'm not sure if this is entirely clear but I've tried to describe the
> process as succinctly as possible.
>
>
>
> Now I can create a severside persistent object and always lookup its
> connection for message sending whenever the server needs to send one.
>
> If the client sends a message the handler will validate and throw it to my
> application controller for proper handling.
>
>
>
> I'm not sure if there are synchronization issues I have yet to discover,
> from this, but in my simple unit tests it looks like it's working ^^
>
>
> ------------------------------
>
> *From:* Gregor Roth [mailto:gre...@go...]
> *Sent:* Thursday, May 29, 2008 11:13 PM
> *To:* xSo...@li...
> *Cc:* Jeff Crane
> *Subject:* Re: [xSocket-develop] xSocket (multiplexed) and serialized
> objects
>
>
>
> Hi Jeff,
>
> by implementing the onConnect and onDisconnect method you are able to
> manage the open connections. See enclosed example. Does this answer your
> question?
>
> Gregor
>
>
>
>
> private static final class Test implements IDataHandler, IConnectHandler,
> IDisconnectHandler {
>
> private final HashMap<String, INonBlockingConnection> openConnections =
> new HashMap<String,INonBlockingConnection>();
>
>
> public boolean onConnect(INonBlockingConnection connection) throws
> IOException, BufferUnderflowException, MaxReadSizeExceededException {
> connection.setIdleTimeoutMillis(30 * 60 * 1000); // if not data is
> be received within 30 min, the connection will be closed
>
> synchronized (openConnections) {
> openConnections.put(connection.getId(), connection);
> }
> return true;
> }
>
> public boolean onDisconnect(INonBlockingConnection connection) throws
> IOException {
> synchronized (openConnections) {
> openConnections.remove(connection.getId());
> }
> return true;
> }
>
>
> public boolean onData(INonBlockingConnection connection) throws
> IOException, BufferUnderflowException, MaxReadSizeExceededException {
>
> …
> data = connection.read...
> ...
> send(…);
>
> return true;
> }
>
> // will be called concurrently
> private void send(Object message) {
>
> HashMap<String, INonBlockingConnection> openConnectionsCopy = null;
> synchronized (openConnections) {
> openConnectionsCopy = (HashMap<String, INonBlockingConnection>)
> openConnections.clone();
> }
>
> for (INonBlockingConnection connection :
> openConnectionsCopy.values()) {
> try {
> synchronized (connection) { // connection methods are not
> threadsafe
> connection.write...
> ...
> }
> } catch (IOException ioe) {
> synchronized (openConnections) {
> openConnections.remove(connection.getId());
> }
> }
> }
> }
> }
>
>
>
>
>
> Hi Jeff,
>
> by implementing the onConnect and onDisconnect method you are able to
> manage the open connections. See enclosed example. Does this answers your
> question?
>
> Gregor
>
>
>
>
> private static final class Test implements IDataHandler,
> IConnectHandler, IDisconnectHandler {
>
> private final HashMap<String, INonBlockingConnection>
> openConnections = new HashMap<String, INonBlockingConnection>();
>
>
> public boolean onConnect(INonBlockingConnection connection) throws
> IOException, BufferUnderflowException, MaxReadSizeExceededException {
> connection.setIdleTimeoutMillis(30 * 60 * 1000); // if not data
> is be received within 30 min, the connection will be closed
>
> synchronized (openConnections) {
> openConnections.put(connection.getId(), connection);
> }
> return true;
> }
>
> public boolean onDisconnect(INonBlockingConnection connection)
> throws IOException {
> synchronized (openConnections) {
> openConnections.remove(connection.getId());
> }
> return true;
> }
>
>
> public boolean onData(INonBlockingConnection connection) throws
> IOException, BufferUnderflowException, MaxReadSizeExceededException {
>
> …
> data = connection.read...
> ...
> send(…);
>
> return true;
> }
>
> // will be called concurrently
> private void send(Object message) {
>
> HashMap<String, INonBlockingConnection> openConnectionsCopy =
> null;
> synchronized (openConnections) {
> openConnectionsCopy = (HashMap<String,
> INonBlockingConnection>) openConnections.clone();
> }
>
> for (INonBlockingConnection connection :
> openConnectionsCopy.values()) {
> try {
> synchronized (connection) { // connection methods are
> not threadsafe
> connection.write...
> ...
> }
> } catch (IOException ioe) {
> synchronized (openConnections) {
> openConnections.remove(connection.getId());
> }
> }
> }
> }
> }
>
>
>
>
>
> 2008/5/29 Jeff Crane <JC...@sp...>:
>
> I read and implemented the answer to my first question. ConnectionUtil held
> the function and usage.
>
>
>
> Clientside:
>
>
>
> client = new NonBlockingConnection(…);
>
> ByteArrayOutputStream bos = new ByteArrayOutputStream();
>
> ObjectOutputStream out = new ObjectOutputStream(bos);
>
> out.writeObject(genericObj);
>
> out.writeObject(DELIMITER);
>
> client.write(bos.size());
>
> client.write(bos.toByteArray());
>
>
>
>
>
> Server Protocol Handler in onData(…)
>
> int length =
> ConnectionUtils.validateSufficientDatasizeByIntLengthField(connection);
>
> byte[] test = connection.readBytesByDelimiter(DELIMITER,length);
>
>
>
> ByteArrayInputStream bis = new ByteArrayInputStream(test);
>
> ObjectInputStream incomingObjstream = new ObjectInputStream(bis);
>
>
>
> Object incomingObj = null;
>
> try{
>
> incomingObj = incomingObjstream.readObject();
>
> }
>
> catch(ClassNotFoundException e){e.printStackTrace();
>
> }
>
> incomingObjstream.close();
>
>
>
> 2. What is the standard practice to index open connections for sending? I
> use my protocol handler to read the object, handle the object, throw an
> event. If the server wants to disconnect or send a message, how do I do a
> lookup? I could do a singleton HashMap or pass a reference in the event
> thrown (which doesn't help if it's interacting with another connection) or
> am I missing something in the xSocket interfaces?
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|
|
From: Jeff C. <JC...@sp...> - 2008-05-30 18:25:45
|
I don't think I'm really using multiplexing, but I did start with the multiplexed server 2.0b1 code.
I don't think about indexing the openConnections in the Handler because I failed to mention they are IConnectionScoped
However, I have a singleton that does basically the same thing as you have illustrated.
Psuedocode of my serverside network architecture:
ServerHandler serverProtocolHandler = new ServerHandler();
ServerHandler.addMyEventListener(Provider.getSingletonController()); // It has implemented IMyListener
...
ConnectionUtils.start(server);
---
ServerHandler implements
IConnectHandler, IDisconnectHandler,
IDataHandler, IIdleTimeoutHandler,
IConnectionTimeoutHandler, IConnectionScoped
boolean authorized = false;
INonBlockingConnection connection; // For disconnect method. Not copied in this.copy().
onConnection
connection.setIdleTimeoutMillis(30 * 60 * 1000);
onData
this.connection = connection;
try{
byte[] readBytes = connection.readBytesByDelimiter(Constants.NETWORK_DELIMITER,length);
ByteArrayInputStream bis = new ByteArrayInputStream(readBytes);
ObjectInputStream incomingMyEventStream = new ObjectInputStream(bis);
incomingMyEvent = incomingMyEventStream.readObject();
if(this.authorized)
{
if(incomingMyEvent.getType() > 0) // Double check object is good by using a method
fireEvent((castBasedOnSwitch)incomingMyEvent)
}
else // Must be initial message. Better be a login.
{
((LoginMyEvent)incomingMyEvent).setConnection(connection);
((LoginMyEvent)incomingMyEvent).setConnectionHandler(this);
fireEvent(incomingMyEvent);
}
catch(Exception e)
{
this.disconnect(); // Contains try{}catch{} for disconnect
}
---
SingletonController
HashMap eventCommandMap;
void handle(MyEvent event)
eventCommandMap.get(Integer.valueOf(event.getType())).execute(event);
---
LoginCommand
void execute(MyEvent event)
// Database lookup or whatever you want to store accounts in.
int id = lookup( ((LoginMyEvent)event).getUserName(), ((LoginMyEvent)event).getPassword() );
// however you want to check it, > -1 or != 0 or whatever. Also can create persistent serverside object in the validate(int).
if(validate(id))
){
// For indexing serverside persistent object->connection together. See addValidConnection(LoginMyEvent)
((LoginMyEvent)event).setId(id);
((LoginMyEvent)event).getConnectionHandler().setAuthorized(true);
// ApplicationModel is application state data and accessors only.
Provider.getSingletonController().getApplicationModel().addValidConnection((LoginMyEvent)event);
}
else
{
((LoginMyEvent)event).getConnectionHandler().disconnect();
}
---
ApplicationModel:
Set<Integer,INonBlockingConnection> validConnections;
void addValidConnection(LoginMyEvent loginMyEvent)
synchronized(validConnections)
validConnections.put(Integer.valueOf(loginMyEvent.getId()),loginMyEvent.getConnection());
---
The client uses the standard NIO client implementation found at http://rox-xmlrpc.sourceforge.net/niotut/
Both client and Server have GUIs that an event-driven MVC with the singleton controller and an extra presentation layer for where SWING falls down.
I'm not sure if this is entirely clear but I've tried to describe the process as succinctly as possible.
Now I can create a severside persistent object and always lookup its connection for message sending whenever the server needs to send one.
If the client sends a message the handler will validate and throw it to my application controller for proper handling.
I'm not sure if there are synchronization issues I have yet to discover, from this, but in my simple unit tests it looks like it's working ^^
________________________________
From: Gregor Roth [mailto:gre...@go...]
Sent: Thursday, May 29, 2008 11:13 PM
To: xSo...@li...
Cc: Jeff Crane
Subject: Re: [xSocket-develop] xSocket (multiplexed) and serialized objects
Hi Jeff,
by implementing the onConnect and onDisconnect method you are able to manage the open connections. See enclosed example. Does this answer your question?
Gregor
private static final class Test implements IDataHandler, IConnectHandler, IDisconnectHandler {
private final HashMap<String, INonBlockingConnection> openConnections = new HashMap<String,INonBlockingConnection>();
public boolean onConnect(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
connection.setIdleTimeoutMillis(30 * 60 * 1000); // if not data is be received within 30 min, the connection will be closed
synchronized (openConnections) {
openConnections.put(connection.getId(), connection);
}
return true;
}
public boolean onDisconnect(INonBlockingConnection connection) throws IOException {
synchronized (openConnections) {
openConnections.remove(connection.getId());
}
return true;
}
public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
...
data = connection.read...
...
send(...);
return true;
}
// will be called concurrently
private void send(Object message) {
HashMap<String, INonBlockingConnection> openConnectionsCopy = null;
synchronized (openConnections) {
openConnectionsCopy = (HashMap<String, INonBlockingConnection>) openConnections.clone();
}
for (INonBlockingConnection connection : openConnectionsCopy.values()) {
try {
synchronized (connection) { // connection methods are not threadsafe
connection.write...
...
}
} catch (IOException ioe) {
synchronized (openConnections) {
openConnections.remove(connection.getId());
}
}
}
}
}
Hi Jeff,
by implementing the onConnect and onDisconnect method you are able to manage the open connections. See enclosed example. Does this answers your question?
Gregor
private static final class Test implements IDataHandler, IConnectHandler, IDisconnectHandler {
private final HashMap<String, INonBlockingConnection> openConnections = new HashMap<String, INonBlockingConnection>();
public boolean onConnect(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
connection.setIdleTimeoutMillis(30 * 60 * 1000); // if not data is be received within 30 min, the connection will be closed
synchronized (openConnections) {
openConnections.put(connection.getId(), connection);
}
return true;
}
public boolean onDisconnect(INonBlockingConnection connection) throws IOException {
synchronized (openConnections) {
openConnections.remove(connection.getId());
}
return true;
}
public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
...
data = connection.read...
...
send(...);
return true;
}
// will be called concurrently
private void send(Object message) {
HashMap<String, INonBlockingConnection> openConnectionsCopy = null;
synchronized (openConnections) {
openConnectionsCopy = (HashMap<String, INonBlockingConnection>) openConnections.clone();
}
for (INonBlockingConnection connection : openConnectionsCopy.values()) {
try {
synchronized (connection) { // connection methods are not threadsafe
connection.write...
...
}
} catch (IOException ioe) {
synchronized (openConnections) {
openConnections.remove(connection.getId());
}
}
}
}
}
2008/5/29 Jeff Crane <JC...@sp...<mailto:JC...@sp...>>:
I read and implemented the answer to my first question. ConnectionUtil held the function and usage.
Clientside:
client = new NonBlockingConnection(...);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(genericObj);
out.writeObject(DELIMITER);
client.write(bos.size());
client.write(bos.toByteArray());
Server Protocol Handler in onData(...)
int length = ConnectionUtils.validateSufficientDatasizeByIntLengthField(connection);
byte[] test = connection.readBytesByDelimiter(DELIMITER,length);
ByteArrayInputStream bis = new ByteArrayInputStream(test);
ObjectInputStream incomingObjstream = new ObjectInputStream(bis);
Object incomingObj = null;
try{
incomingObj = incomingObjstream.readObject();
}
catch(ClassNotFoundException e){e.printStackTrace();
}
incomingObjstream.close();
2. What is the standard practice to index open connections for sending? I use my protocol handler to read the object, handle the object, throw an event. If the server wants to disconnect or send a message, how do I do a lookup? I could do a singleton HashMap or pass a reference in the event thrown (which doesn't help if it's interacting with another connection) or am I missing something in the xSocket interfaces?
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
xSocket-develop mailing list
xSo...@li...<mailto:xSo...@li...>
https://lists.sourceforge.net/lists/listinfo/xsocket-develop
|