Re: [xSocket-develop] Trying to implement a Dual Port Server with XSocket
Status: Inactive
Brought to you by:
grro
|
From: Phyo A. <phy...@gm...> - 2009-11-03 23:53:08
|
Hi gregor; Thanks a lot.I have see How it works now 1 . TcpClinent Sents Channel ID 2. Web Server Sets tcpclient's Communication at Sent ID at http://127.0.0.1/(sentID) <http://127.0.0.1/%28sentID%29> 3. Web Client Tries to post Hello You to that url. 4. "Hello You" arrived to tcp client which set Channel ID. What I am trying to achieve is to make both incoming connections , readable and writable , to act Dual Port server as just a simple IO Pipe between two side of TCP Clients .Other side read what Other side Writes and vice-versa . Not just for http I want to be any kind of TCP connection so they will be send as it is. So i am learning how to modify dual port server to work as that way. 1. Will replace HttpRequestHandler part with TcpConnectHandler 2. To Put whole Connection , so both can read or write there? I need some suggestion 3. When OnData , copy data to another side and write there , vice-versa. Please suggest and share me some idea tools , i like xsocket , a lot more simpler and powerful than Apache Mina! Regards, Phyo. On Mon, Nov 2, 2009 at 7:03 AM, Gregor Roth <gre...@gm...> wrote: > Hi Phyo, > > please see also the JUnit class SimpleDualPortServerTest which is located > in the same package. I suppose that the exception will be caused by a non > PUT/POST-Reuest and/or by a invalid URI. Please consider that the > SimpleDualPortServer is a simple, incomplete example. Especially validations > checks are missing. E.g. if a GET-Request is received, an exception will be > caused by the missing body. > > Gregor > > ----- Original Message ----- > > From: Phyo Arkar > > Sent: 11/01/09 01:29 am > > To: Gregor Roth > > Subject: Re: [xSocket-develop] Trying to implement a Dual Port Server with > XSocket > > > > When i run , and connect with web browser to port 8080 (i change ports to > 8080 and 9090) it got error , as below.. > > on browser it gives InternalServerError too. > > Am i doing something wrong? > > Nov 1, 2009 6:55:54 AM org.xsocket.connection.Server$LifeCycleHandler > onConnected > INFO: server listening on 0.0.0.0:8080<http://mail-eu.gmx.com/fm07/cgi/derefer?TYPE=2&DEST=http%3A%2F%2F0.0.0.0%3A8080>(xLightweb 2.9/xSocket 2.7) > Nov 1, 2009 6:55:54 AM org.xsocket.connection.Server$LifeCycleHandler > onConnected > INFO: server listening on 0.0.0.0:9090<http://mail-eu.gmx.com/fm07/cgi/derefer?TYPE=2&DEST=http%3A%2F%2F0.0.0.0%3A9090>(xSocket 2.7) > Nov 1, 2009 6:56:16 AM > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter > performRequestHandler > WARNING: [78a41f9f124ad22431b5f0a2165S1] error occured by calling on > request > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter$MultithreadedRequestHandlerAdapter@1a1c887<#124b7ce92b5aa6b9_124b3b44687db324_>java.lang.NumberFormatException: For input string: "" > at java.lang.NumberFormatException.forInputString(Unknown Source) > at java.lang.Integer.parseInt(Unknown Source) > at java.lang.Integer.parseInt(Unknown Source) > at > SimpleDualPortServer$HttpRequestHandler.onRequest(SimpleDualPortServer.java:116) > at > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter.performRequestHandler(AbstractHttpConnection.java:2083) > at > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter.access$1400(AbstractHttpConnection.java:1993) > at > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter$MultithreadedRequestHandlerAdapter$1.run(AbstractHttpConnection.java:2271) > at > org.xsocket.SerializedTaskQueue.performPendingTasks(SerializedTaskQueue.java:161) > at > org.xsocket.SerializedTaskQueue.access$0(SerializedTaskQueue.java:139) > at > org.xsocket.SerializedTaskQueue$MultithreadedTaskProcessor.run(SerializedTaskQueue.java:189) > at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown > Source) > at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) > at java.lang.Thread.run(Unknown Source) > > Nov 1, 2009 6:56:16 AM > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter > performRequestHandler > WARNING: [78a41f9f124ad22431b5f0a2165S2] error occured by calling on > request > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter$MultithreadedRequestHandlerAdapter@1a1c887<#124b7ce92b5aa6b9_124b3b44687db324_>java.lang.NumberFormatException: For input string: "favicon.ico" > at java.lang.NumberFormatException.forInputString(Unknown Source) > at java.lang.Integer.parseInt(Unknown Source) > at java.lang.Integer.parseInt(Unknown Source) > at > SimpleDualPortServer$HttpRequestHandler.onRequest(SimpleDualPortServer.java:116) > at > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter.performRequestHandler(AbstractHttpConnection.java:2083) > at > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter.access$1400(AbstractHttpConnection.java:1993) > at > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter$MultithreadedRequestHandlerAdapter$1.run(AbstractHttpConnection.java:2271) > at > org.xsocket.SerializedTaskQueue.performPendingTasks(SerializedTaskQueue.java:161) > at > org.xsocket.SerializedTaskQueue.access$0(SerializedTaskQueue.java:139) > at > org.xsocket.SerializedTaskQueue$MultithreadedTaskProcessor.run(SerializedTaskQueue.java:189) > at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown > Source) > at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) > at java.lang.Thread.run(Unknown Source) > > Nov 1, 2009 6:56:19 AM > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter > performRequestHandler > WARNING: [78a41f9f124ad22431b5f0a2165S3] error occured by calling on > request > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter$MultithreadedRequestHandlerAdapter@1a1c887<#124b7ce92b5aa6b9_124b3b44687db324_>java.lang.NumberFormatException: For input string: "favicon.ico" > at java.lang.NumberFormatException.forInputString(Unknown Source) > at java.lang.Integer.parseInt(Unknown Source) > at java.lang.Integer.parseInt(Unknown Source) > at > SimpleDualPortServer$HttpRequestHandler.onRequest(SimpleDualPortServer.java:116) > at > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter.performRequestHandler(AbstractHttpConnection.java:2083) > at > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter.access$1400(AbstractHttpConnection.java:1993) > at > org.xlightweb.AbstractHttpConnection$RequestHandlerAdapter$MultithreadedRequestHandlerAdapter$1.run(AbstractHttpConnection.java:2271) > at > org.xsocket.SerializedTaskQueue.performPendingTasks(SerializedTaskQueue.java:161) > at > org.xsocket.SerializedTaskQueue.access$0(SerializedTaskQueue.java:139) > at > org.xsocket.SerializedTaskQueue$MultithreadedTaskProcessor.run(SerializedTaskQueue.java:189) > at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown > Source) > at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) > at java.lang.Thread.run(Unknown Source) > > > > On Sun, Nov 1, 2009 at 6:00 AM, Phyo Arkar <phy...@gm...<#124b7ce92b5aa6b9_124b3b44687db324_> > > wrote: > >> Dear Gregor >> >> Thanks a lot , I am check the code and i will test it out >> >> Regards, >> >> Phyo >> >> >> On Sat, Oct 31, 2009 at 8:10 PM, Gregor Roth <gre...@gm...<#124b7ce92b5aa6b9_124b3b44687db324_> >> > wrote: >> >>> Hi Phyo, >>> >>> >>> you can find a simple example for a dual port server here: >>> http://xlightweb.svn.sourceforge.net/viewvc/xlightweb/xlightweb/core/trunk/src/test/java/org/xlightweb/SimpleDualPortServer.java?view=markup<http://mail-eu.gmx.com/fm07/cgi/derefer?TYPE=2&DEST=http%3A%2F%2Fxlightweb.svn.sourceforge.net%2Fviewvc%2Fxlightweb%2Fxlightweb%2Fcore%2Ftrunk%2Fsrc%2Ftest%2Fjava%2Forg%2Fxlightweb%2FSimpleDualPortServer.java%3Fview%3Dmarkup> >>> >>> >>> Gregor >>> >>> >>> >>> ----- Original Message ----- >>> >>> From: Phyo Arkar >>> >>> Sent: 10/31/09 02:42 am >>> >>> To: xso...@li...<#124b7ce92b5aa6b9_124b3b44687db324_> >>> >>> Subject: [xSocket-develop] Trying to implement a Dual Port Server with >>> XSocket >>> >>> >>> >>> Hello XSocket Developers >>> >>> I am new to XSocket and trying to implement a Dual Port Server , One Port >>> accept incoming connection , read data and when other side connect , reply >>> to them >>> >>> >>> here is my example >>> >>> >>> RemoteWebServer<---Agent ---------------------------->XSocketServer:8090 >>> <----------------> XSocketServer:9080 <<<<--------->Browser >>> >>> >>> I am wondering how to communicate data Internally between >>> XSocketServer:8090 <---------> XSocketServer:9080; >>> >>> >>> I am thinking to use shared synchronized object : >>> >>> Only Xsocket is used on server side relay is with socat ( >>> dest-unreachable.com<http://mail-eu.gmx.com/fm07/cgi/derefer?TYPE=2&DEST=http%3A%2F%2Fmail-eu.gmx.com%2Ffm07%2Fcgi%2Fderefer%3FTYPE%3D2%26amp%3BDEST%3Dhttp%253A%252F%252Fdest-unreachable.com> >>> ) >>> >>> >>> >>> Below is my code as far as it goes it dont work :D. will appreciate a lot >>> for anyyy help : >>> >>> >>> //------------ Begins >>> import java.io.IOException; >>> import java.nio.BufferUnderflowException; >>> import org.xsocket.MaxReadSizeExceededException; >>> import org.xsocket.connection.IDataHandler; >>> import org.xsocket.connection.IConnectHandler; >>> >>> import org.xsocket.connection.INonBlockingConnection; >>> >>> class Shared { >>> >>> static INonBlockingConnection camNBC = null; >>> static INonBlockingConnection brwNBC = null; >>> boolean value_cam = false; >>> boolean value_brw = false; >>> >>> synchronized INonBlockingConnection get_cam() { >>> if (value_cam == false) >>> try { >>> wait(); >>> } catch (InterruptedException e) { >>> System.out.println("InterruptedException caught"); >>> } >>> System.out.println("Gives Cam's: " + camNBC); >>> value_cam = false; >>> notify(); >>> return camNBC; >>> } >>> >>> synchronized void put_cam(INonBlockingConnection nbc) { >>> if (value_cam == true) >>> try { >>> wait(); >>> } catch (InterruptedException e) { >>> System.out.println("InterruptedException caught"); >>> } >>> this.camNBC = nbc; >>> System.out.println("Set Camera: " + nbc); >>> value_cam = false; >>> notify(); >>> } >>> >>> synchronized INonBlockingConnection get_brw() { >>> if (value_brw == false) >>> try { >>> wait(); >>> } catch (InterruptedException e) { >>> System.out.println("InterruptedException caught"); >>> } >>> System.out.println("Gives brw: " + brwNBC); >>> value_brw = false; >>> notify(); >>> return brwNBC; >>> } >>> >>> synchronized void put_brw(INonBlockingConnection nbc) { >>> if (value_brw == true) >>> try { >>> wait(); >>> } catch (InterruptedException e) { >>> System.out.println("InterruptedException caught"); >>> } >>> this.brwNBC = nbc; >>> System.out.println("Set brw: " + nbc); >>> value_brw = false; >>> notify(); >>> } >>> >>> } >>> >>> class BrowserHandler implements IDataHandler,IConnectHandler { >>> >>> Shared s; >>> >>> BrowserHandler(Shared s) { >>> this.s = s; >>> } >>> @Override<#124b7ce92b5aa6b9_124b3b44687db324_124acef4188edf77_124aad346b05e7db_> >>> public boolean onConnect(INonBlockingConnection connection) >>> throws IOException, BufferUnderflowException, >>> MaxReadSizeExceededException { >>> // TODO Auto-generated method stub >>> s.put_brw(connection); >>> return false; >>> } >>> public boolean onData(INonBlockingConnection nbc) throws IOException, >>> BufferUnderflowException, MaxReadSizeExceededException { >>> String data = nbc.readStringByDelimiter("\n"); >>> this.s.get_cam().write(data + " \r\n\r\n"); >>> return true; >>> >>> } >>> >>> >>> } >>> >>> class CameraHandler implements IDataHandler,IConnectHandler { >>> >>> Shared s; >>> >>> public CameraHandler(Shared s) { >>> this.s = s; >>> } >>> @Override<#124b7ce92b5aa6b9_124b3b44687db324_124acef4188edf77_124aad346b05e7db_> >>> public boolean onConnect(INonBlockingConnection connection) >>> throws IOException, BufferUnderflowException, >>> MaxReadSizeExceededException { >>> // TODO Auto-generated method stub >>> s.put_cam(connection); >>> return false; >>> } >>> public boolean onData(INonBlockingConnection nbc) throws IOException, >>> BufferUnderflowException, MaxReadSizeExceededException { >>> >>> String data = nbc.readStringByDelimiter("\n"); >>> this.s.get_brw().write(data + " \r\n"); >>> return true; >>> } >>> >>> >>> } >>> >>> >>> import java.io.IOException; >>> import org.xsocket.connection.IServer; >>> import org.xsocket.connection.Server; >>> >>> >>> public class main { >>> >>> public static void main(String args[]) { >>> try { >>> Shared s= new Shared(); >>> IServer browse_side = new Server(8090, new BrowserHandler(s)); >>> IServer cam_side = new Server(9080, new CameraHandler(s)); >>> >>> // run it within the current thread. >>> //srv.run(); // the call will not return >>> >>> // ... or start it by using a dedicated thread >>> >>> browse_side.start(); >>> cam_side.start(); >>> } catch (IOException e) { >>> // TODO Auto-generated catch block >>> e.printStackTrace(); >>> } // returns after the server has been started >>> >>> >>> } >>> >>> } >>> >>> >>> >>> >>> >>> >>> >> > > > |