⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sockettest.java

📁 J2ME开发实例,内含有可运行的实例代码!
💻 JAVA
字号:
//SocketTest.java
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.* ;
import java.io.*;
public class SocketTest extends MIDlet
{
	private Display display;
	public SocketTest()
	{
		display = Display.getDisplay(this);
	}
	public void startApp()
	{
		try
		{
			String url = "socket://127.0.0.1:80" ;
			String command = "GET /test.html HTTP/1.0 \n\n" ;
			//打开连接
			StreamConnection sc = (StreamConnection)
				Connector.open(url) ;
			//发送请求
			DataOutputStream dos =
				new DataOutputStream(sc.openOutputStream()) ;
			byte bytes[] = command.getBytes() ;
			dos.write(bytes,0,bytes.length) ;
			dos.flush() ;
			//取得回应
			DataInputStream dis =
				new DataInputStream(sc.openInputStream()) ;
			String content = "" ;
			int ic ;
			while( (ic = dis.read()) != -1 )
			{
				content = content + (char)ic ;
			}
			Form f = new Form("Socket Test");
			f.append(content) ;
			display.setCurrent(f) ;
		}
		catch(Exception e)
		{
			System.out.println(e.getMessage()) ;
			notifyDestroyed() ;
		}
	}
	public void pauseApp()
	{ }
	public void destroyApp(boolean unconditional)
	{}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -