Blackberry version "hello world", which use a socket to send msg to a server

来源:互联网 发布:手机解锁软件大全 编辑:程序博客网 时间:2024/05/18 01:18

// HelloWorldScreen.java

import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;


public class HelloWorldScreen extends MainScreen {

    public HelloWorldScreen() {
        add(new LabelField("Hello World"));
    }

}

// helloworld.java

import java.io.OutputStreamWriter;

import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;

import net.rim.device.api.ui.UiApplication;



public class helloworld extends UiApplication {

    public helloworld() {
        HelloWorldScreen screen  = new HelloWorldScreen();
        pushScreen(screen);
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        helloworld app = new helloworld();
       
        try
        {
            // Socket开始
            final String URL = "socket://58.250.173.37:8018;deviceside=true";
            StreamConnection conn = null;
            conn = (StreamConnection)Connector.open(URL);
           
            OutputStreamWriter _out = new OutputStreamWriter(conn.openOutputStream());
            String data = "loveXJR";
            int length = data.length();
            _out.write(data, 0, length);
            _out.close();
            conn.close();   
            // Socket结束
        }
        catch(Exception e)
        {           
        }
       
        app.enterEventDispatcher();
    }
}
原创粉丝点击