[英]socket connection works good on emulator but can't send in real device(j2me)
我正在開發服務器/客戶端應用程序。該應用程序在仿真器上可以正常運行,但是當我在諾基亞5200或諾基亞6303i上對其進行測試時,盡管連接成功建立,但服務器在第一種讀取方法上會阻塞。 換句話說,客戶端(j2me)應用程序無法將數據發送到服務器。
我的客戶部分:
Thread occ=new Thread(new Runnable() {
public void run() {
try {
SocketConnection sc = (SocketConnection)Connector.open("socket://213.233.169.142:2000");
sc.setSocketOption(SocketConnection.DELAY, 0);
OutputStream os=sc.openDataOutputStream();
DataOutputStream dos=new DataOutputStream(os);
InputStream is=sc.openDataInputStream();
DataInputStream dis=new DataInputStream(is);
//dos.writeUTF(receiverT.getString());
os.write("saalam".getBytes());
os.flush();
dos.writeUTF(Midlet.userPhoneNumber);
dos.flush();
dos.writeUTF(messT.getString());
dos.flush();
while((!dis.readUTF().equals("system-use:code=2")) && false)
{
}
dos.close();
os.close();
sc.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
occ.start();
我的服務器部分:
serverSocket = new ServerSocket(2000);
Socket socket=serverSocket.accept();
System.out.println("connection stablished");
inp=new DataInputStream(mySocket.getInputStream());
outp=new DataOutputStream(mySocket.getOutputStream());
receiverTemp=inp.read();//the server code blocks on this line
senderTemp=inp.readUTF();
.
.
.
.
您是否在JAD文件中設置了套接字權限? 這個事實對於解決設備中的此類問題非常重要
問題終於解決了,問題是一些移動運營商不允許使用原始套接字發送/接收信息,因此我們在端口80上使用了HTTP套接字,並且可以正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.