Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Posts: 21
Registered: ‎04-23-2011
My Device: 9700
My Carrier: xl

socket client Listening incoming messages from socket server

hi all I create javascript extension for socket client. why my code can't linsten message from server

Below my code :



package connections;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;

import net.rim.blackberry.api.stringpattern.PatternRepository;
import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.script.ScriptableFunction;
import net.rim.device.api.ui.component.Dialog;
public final class SocketFunction extends ScriptableFunction {
	private BrowserField _browserField;
	public SocketFunction(BrowserField bfRef)
		this._browserField = bfRef;
	private static String URL = "socket://;deviceside=false";
    public Object invoke(Object obj, Object[] args) throws Exception
	    //String sb = "IDX|10.30|abgx|9500|2|NI|F|KZ|D\n";
        StreamConnection conn = null;
	   	conn = (StreamConnection)Connector.open(URL,Connector.READ_WRITE);
	   	OutputStreamWriter _out = new OutputStreamWriter(conn.openOutputStream());
	   	String data = "IDX|10.30|abgx|9500|2|NI|F|KZ|D";
	   	_out.write(data+ "\n");
	   	InputStreamReader _in = new InputStreamReader(conn.openInputStream());
	   	StringBuffer sb = new StringBuffer();
	   	int c = 0;
        while (((c = _in.read()) != '\n') && (c != -1)) {
        	sb.append((char) c);
      String sp = sb.toString().substring(0, (sb.toString()).length()-1);
      return UNDEFINED;




What wrong ??