j2me中通过socket传输数据,发送的数据服务器端接受不到

yzbsd 2007-12-11 10:49:57
参照j2me中的networkdemo,发送代码如下:
import java.lang.Thread;
import java.io.OutputStream;
import java.io.IOException;
/**
*
* @author Administrator
*/
public class Sender extends Thread{
private OutputStream os;
private String message;
private boolean _bCtrl = true;
private byte[] _btSend;

/** Creates a new instance of Sender */
public Sender(OutputStream os) {
this.os = os;
start();
}

public synchronized void send(String msg) {
message = msg;
_bCtrl = false;
notify();
}
public synchronized void send(byte[] bsend) {
this._btSend = bsend;
_bCtrl = true;
notify();
}

public synchronized void run()
{
while (true)
{
// If no client to deal, wait until one connects
if (message == null && this._btSend == null)
{
try
{
wait();
}
catch (InterruptedException e)
{}
}
if (message == null && this._btSend == null)
{
break;
}

try
{
if(this._bCtrl)
{
if(this._btSend != null)
{
os.write(this._btSend);
this._btSend = null;
}
}
else
{
os.write(message.getBytes());
os.flush();
}
//os.write("\r\n".getBytes());
}
catch (IOException ioe)
{
System.out.println("发送错误" + ioe.getMessage());
}
message = null;
}
}

public synchronized void stop() {
message = null;
notify();
}
}
测试结果:在wtk中,发送数据在服务器端能够接受到,偶尔也有收不到的情况;但是在真机上,服务器一直收不到数据,但是手机客户端能收到。请各位指点迷津
...全文
97 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
c30gcrk 2007-12-12
  • 打赏
  • 举报
回复
这是真机适配问题了,建议看下nokia5200和nokia5500的配置表
yzbsd 2007-12-12
  • 打赏
  • 举报
回复
现在又有新的问题,在nokia5500上客户端可以接受到数据,但是在nokia5200上客户端就不行了,很奇怪
yzbsd 2007-12-12
  • 打赏
  • 举报
回复
找到原因了,修改如下代码:
if(this._bCtrl)
{
if(this._btSend != null)
{
os.write(this._btSend);
os.flush();
this._btSend = null;
}
}
else
{
os.write(message.getBytes());
os.flush();
}
zjsjava 2007-12-11
  • 打赏
  • 举报
回复
我的没有签名也可以啊!不过我发送的数据比较小!移动数据发送据说有限制的!看看你的数据量是多少!
yanhan0615 2007-12-11
  • 打赏
  • 举报
回复
就是一楼说的问题,必须要签名才能用手机的socket
yzbsd 2007-12-11
  • 打赏
  • 举报
回复
楼上,我用的是cmnet,sokcet连接可以建立,现在的问题是:client->server,server收不到数据;server->client,client可以接受到数据。
夏成沙 2007-12-11
  • 打赏
  • 举报
回复
首先,请确定你使用的是否是 Socket ,如果是,那么手机的接入点方式必须是 cmnet,同时好像还需要使用数字签名才可以使用Socket,默认值可以使用HttpConnection

13,100

社区成员

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

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