菜鸟急求帮助~

yandongmei 2007-01-16 09:24:25
我用java写了个socket通信的客户端程序,但是有的时候给服务端发信息服务端收不到,有的时候可以收到,程序运行没有错误,请高手指点下~~

public class newYCTClient {
private static Logger logger = Logger.getLogger(newYCTClient.class.getName());
protected Socket socket;
protected InputStream in;
protected OutputStream out;
byte infoFromYCT[]= null;
public void connect(String IP,int port) {//连接客户端和服务器
try {
socket = new Socket(IP,port);
// socket.setSoTimeout(10000);
in = socket.getInputStream();
out = socket.getOutputStream();
}catch(Exception ioe) {
ioe.printStackTrace();
}
System.out.println("客户端连接服务端");
}

/**
* 发送和接收报文数据
* @param str 要发送的报文数据
* @return 返回接收到的报文数据
*/
public String FileInfo(String str) {
//接收到的总的数据
String infoFromNFC = null;
//按报文种类截完后的报文数据
String newinfoFromNFC = null;
BufferedReader br;
//缓冲数据用于装接收到的数据
char[] c = new char[340];
for(int i=0;i<c.length;i++) {
c[i]=0x30;
}
//发送数据
try {
OutputStreamWriter osw;
BufferedWriter bw;
osw = new OutputStreamWriter(out);
bw = new BufferedWriter(osw);
bw.write(str);
bw.flush();
}catch(IOException ioe) {
ioe.printStackTrace();
}
//接收信息
try {
br=new BufferedReader(new InputStreamReader(in));
br.read(c);
infoFromNFC = String.valueOf(c);
}catch(IOException ioe) {
ioe.printStackTrace();
}

this.Close();
return newinfoFromNFC;
// return infoFromNFC;
}

public int Close(){
try{
out.close();
in.close();
socket.close();

}catch (IOException e){
e.printStackTrace();
return 0;
}
return 1;
}
}
...全文
262 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yandongmei 2007-01-16
  • 打赏
  • 举报
回复
就是我给服务端发数据包,他那边显示收不到,我也不敢确定是不是我程序的问题 ,要不是我程序的问题,那问题出在哪里啊???急~~~~~~~谢谢
飞鸟0922 2007-01-16
  • 打赏
  • 举报
回复
你说“有的时候给服务端发信息服务端收不到”具体是什么意思,

我想:

问题可能不是因为这段程序引起的。
yandongmei 2007-01-16
  • 打赏
  • 举报
回复
服务器端我没有代码 是连别人的服务器.
飞鸟0922 2007-01-16
  • 打赏
  • 举报
回复
服务器端的代码那?怎么不贴啊?

62,615

社区成员

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

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