关于Socket连接问题??

XioSan 2004-03-24 05:58:35
在看王森的《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 cmd[] = command.getBytes() ;

dos.write(cmd,0,cmd.length) ;

//dos.writeChars(command) ;
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){}
}
出现Target port denied to untrusted applications
怎么回事?望高手指教!
...全文
106 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
iiisan 2004-09-07
  • 打赏
  • 举报
回复
结贴了!
XioSan 2004-03-25
  • 打赏
  • 举报
回复
还没解决啊!高手啊,进来吧!
XioSan 2004-03-25
  • 打赏
  • 举报
回复
我用Apache建立的服务器端口号是80,是不是不能该啊
XioSan 2004-03-25
  • 打赏
  • 举报
回复
我换了一个端口,可是它只是在Console上显示 TCP open 在模拟器上什么都没有,怎么办?
youngplayer 2004-03-24
  • 打赏
  • 举报
回复
端口号有问题吧 你换个端口号试试 最好是5位数的 避免重复
Lin_Zhoubo 2004-03-24
  • 打赏
  • 举报
回复
我也期待着
XioSan 2004-03-24
  • 打赏
  • 举报
回复
采用Http连接可以。

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧