服务端是delphi,用java写一个tcp客户端,用socket通讯客户端:请输入请求字符串:输入后,读取delphi服务端回应,打印输出回应内容:服务端时间:2008-05-01 11:20:32
处理结果:true
Elf=32
MD5Hex=242342242342sdfsfwerwr2424
处理结果:true
Elf=32
MD5Hex=242342242342sdfsfwerwr2424
调试欢乐多
new Socket() 啦!
很普通的通信啊! 根本不用管服务器端是用什么做的。至于协议,你得自几解决了!
String host="localhost";
int port= 9999;
Socket socket; public void createSocket()throws Exception{
socket=new Socket(host,port);
// socket.setSoTimeout(3000);
} public void communicate()throws Exception{
StringBuffer sb=new StringBuffer("send request"); //发出请求
OutputStream socketOut=socket.getOutputStream();
socketOut.write(sb.toString().getBytes());
socketOut.flush();
// socket.shutdownOutput(); //关闭输出流 //接收响应结果
InputStream socketIn=socket.getInputStream();
ByteArrayOutputStream buffer=new ByteArrayOutputStream();
byte[] buff=new byte[1024];
int len=-1;
while((len=socketIn.read(buff))!=-1){
buffer.write(buff,0,len);
} System.out.println(new String(buffer.toByteArray())); //把字节数组转换为字符串
/*
InputStream socketIn=socket.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(socketIn));
String data;
while((data=br.readLine())!=null){
System.out.println(data);
}
*/
socket.close();
} public static void main(String args[])throws Exception{
HTTPClient client=new HTTPClient();
client.createSocket();
client.communicate();
}
}
java客户端,有没现成的源码?要快
之前加上buffer.flush();试一试...
你太自信了! 你用delphi 开发一个客户端,调用看看吧!!
我可以把delphi的发给你看
如果你等在了第4部,我怀疑你的delphi 没有 flush