Re: [xSocket-develop] Problem with new xSocket Connection, basic question
Status: Inactive
Brought to you by:
grro
|
From: Gregor R. <gre...@go...> - 2008-11-25 10:34:23
|
Hi, you are using the run() method to start the server. The run() method is a blocking method, this means you will never return from srv.run() (until the server stops). The srv2.run() will not be called in your code. The Server class also supports a start() method which returns after the server is started. Following code should work srv = new Server(8090, new xSocketDataHandler()); srv.start(); srv2 = new Server(8091, new xSocketDataHandler()); srv2.run(); For a more detailed explanation refer to xSocket'S tutorial: http://xsocket.sourceforge.net/core/tutorial/V2/TutorialCore.htm Gregor 2008/11/25 dytu iuyr <jun...@wp...> > hello, > > I'm student and I'm working on some project. I'm sorry if its not the > right place for posting my question but I couldn't find any forum > regarding xSocket. Anyway my problem is as follows: I want to control > some kind of gateway using Flash interface. Between Flash interface and > gateway there is java program with xSocket running. Thanks to great > tutorial of Chad Lung on this site: > http://giantflyingsaucer.com/blog/?p=205 i was able to establish > connection between interface and java program. Now I'm trying to > establish second simultaneous socket connection with that gateway. I'm > not sure if my approach is right (I have no experience in writing > network app) but I'm trying to create another server with another name > which will listen for incoming messages on another socket. As You can > see it is simple modification of tutorial. The problem is although I > don't get any error it doesn't work. Can someone have a look at my code > and tell me what is wrong with it? Thank You in advance. > > Here is my code: > > package xsocketserver; > > import org.xsocket.connection.*; > > public class Main > { > protected static IServer srv = null; > protected static IServer srv2 = null; > > public static void main(String[] args) > { > try > { > srv = new Server(8090, new xSocketDataHandler()); > srv.run(); > srv2 = new Server(8091, new xSocketDataHandler()); > srv2.run(); > > } > catch(Exception ex) > { > System.out.println(ex.getMessage()); > } > } > > protected static void shutdownServer() > { > try > { > srv.close(); > } > catch(Exception ex) > { > System.out.println(ex.getMessage()); > } > } > } > > > package xsocketserver; > > import java.io.IOException; > import java.nio.BufferUnderflowException; > import java.nio.channels.ClosedChannelException; > import org.xsocket.*; > import org.xsocket.connection.*; > > public class xSocketDataHandler implements IDataHandler > { > > public boolean onData(INonBlockingConnection nbc) throws IOException, > BufferUnderflowException, ClosedChannelException, > MaxReadSizeExceededException > { > try > { > String data = nbc.readStringByDelimiter("\0"); > nbc.write(data + "\0"); > > if(data.equalsIgnoreCase("SHUTDOWN")) > Main.shutdownServer(); > } > catch(Exception ex) > { > System.out.println(ex.getMessage()); > } > > return true; > } > } > > ---------------------------------------------------- > Zbuduj drzewo genealogiczne swojej rodziny! > Sprawdź jakie to łatwe i proste :) > Zacznij już teraz: > > http://klik.wp.pl/?adr=http%3A%2F%2Fcorto.www.wp.pl%2Fas%2Fbliscy.html&sid=567 > > > > ------------------------------------------------------------------------- > 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 > |