[xSocket-develop] Odp: Accessing nbc from another class
Status: Inactive
Brought to you by:
grro
|
From: <jun...@wp...> - 2008-11-27 08:06:35
|
I still can't figure out what is wrong. Please, I really need Your help
on this one. I somebody would have time to help me I would be grateful.
Thank You in advance.
sly
Dnia 26-11-2008 o godz. 9:55 dytu iuyr napisał(a):
> hi,
>
> I have a problem. I can't send data using nbc.write("some text") to a
> client from function in my main class. How can I select the connection
> that I want to use if there are 2 different?
>
> In my main function in my main class of my java program I created two
> servers which are maintaining two different nbc on different sockets.
>
> srvHandler = new xSocketDataHandler();
> srv = new Server(8091, srvHandler);
> srv.start();
> srv2 = new Server(8090, new xSocketDataHandler());
> srv2.start();
>
>
> As You can see, xSocketDataHandler is another simple class (in file
> xSocketDataHandler.java) with onData function only. It looks like this:
>
> 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 INonBlockingConnection nbc;
>
> public boolean onData(INonBlockingConnection nbc) throws IOException,
> BufferUnderflowException, ClosedChannelException,
> MaxReadSizeExceededException
> {
> try
> {
> String data = nbc.readStringByDelimiter("\0");
> Main.stringSplit(data);
> nbc.write(data + "\0");
> //nbc.write("trele morele" + "\0");
>
> }
> catch(Exception ex)
> {
> System.out.println(ex.getMessage());
> }
>
> return true;
> }
>
>
> Now I want to access nbc from function StringSplit in my main class and
> be able to send some data for example to the client on the another side
> of connection on socket 8091, independently from onData function (now
> sending data works only in this function). I set nbc to public in
> xSocketDataHandler class and I tried many different ways of accessing
> that nbc but doesn't mater what I do, the client doesn't receive data.
>
>
> package xsocketserver;
>
> import org.xsocket.connection.*;
> import org.jdom.input.SAXBuilder;
> import org.jdom.Document;
> import org.jdom.JDOMException;
> import org.jdom.Element;
> import org.jdom.output.XMLOutputter;
> import org.jdom.Attribute;
> import java.io.*;
> //import xSocketDataHandler.*;
>
>
> public class Main
> {
> protected static IServer srv = null;
> protected static IServer srv2 = null;
> public static Document doc;
> public static Element webapp;
> public static INonBlockingConnection nbc;
> public static xSocketDataHandler srvHandler;
>
> public static void main(String[] args)
> {
>
>
>
> try
> {
> //nbc1 = new NonBlockingConnection("127.0.0.1", 8092);
> srvHandler = new xSocketDataHandler();
>
> srv = new Server(8091, srvHandler);
> srv.start();
> srv2 = new Server(8090, new xSocketDataHandler());
> srv2.start();
>
> //nbc = new NonBlockingConnection(srvHandler);
> //nbc1.write("aaaaaaabbbbbbbaaaaa" + "\0");
>
> }
> catch(Exception ex)
> {
> System.out.println(ex.getMessage());
> }
>
>
>
>
> }
>
>
> public static void stringSplit(String str)
> {
> try
> { nbc.write("some text");
> //xSocketDataHandler obj = new xSocketDataHandler();
> //obj.onData(true).nbc.write("dsfds");
> //srvHandler obj = new srvHandler();
> //obj.nbc.write("trele morele" + "\0");
> //nbc1.write("aaaaaaa" + "\0");
> }
> catch(Exception ex)
> {
> System.out.println(ex.getMessage());
> }
> }
>
> ----------------------------------------------------
> Uważaj na drodze:
> http://klik.wp.pl/?adr=http%3A%2F%2Fprorocznia.pl%2Ff.html%3Fi%3D37169O-283747030O0&sid=568
>
>
>
> -------------------------------------------------------------------------
> 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
----------------------------------------------------
Fascynujący labirynt Carlosa Ruiza Zafona, autora Cienia wiatru:
świat Barcelony, mroczne sekrety i Cmentarz Zapomnianych Książek w
najnowszej powieści pt. "Gra anioła"!
http://klik.wp.pl/?adr=http%3A%2F%2Fcorto.www.wp.pl%2Fas%2Fgraaniola.html&sid=569
|