[xSocket-develop] Problem with new xSocket Connection, basic question
Status: Inactive
Brought to you by:
grro
|
From: dytu i. <jun...@wp...> - 2008-11-25 09:12:17
|
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 |