我现在用mina做服务器, 客户端 由于某些原因只能用 传统的 阻塞socket现在问题是,客户端可以连上服务器,但是 当 往服务器写 数据的时候, 服务器接收不到,请高手指点,下面是客户端代码:Socket socket = new Socket();
SocketAddress sa = new InetSocketAddress("192.168.1.112", 8888);
socket.connect(sa);
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.writeUTF("hello,world.");
while(true)
{
String theLine = in.readLine( );
System.out.println("read:"+theLine);
out.writeUTF("hello,world.");
if (theLine.equals(".")) break;
}
Thread.sleep(1000*10);
socket.close();
SocketAddress sa = new InetSocketAddress("192.168.1.112", 8888);
socket.connect(sa);
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.writeUTF("hello,world.");
while(true)
{
String theLine = in.readLine( );
System.out.println("read:"+theLine);
out.writeUTF("hello,world.");
if (theLine.equals(".")) break;
}
Thread.sleep(1000*10);
socket.close();
解决方案 »
- 求助:java有没有类似c#的dynamic的解决方案?主要用于com交互?
- java socket编程关于client和server连接问题!
- 为什么我的get方法取不到值呢,大伙帮我看看呀!
- java的异常处理
- 字符串这样赋值不对吗
- 在一个文件中如何定位位置,并追加或修改字符串?
- 请问在java中如何将一个xml格式的字符串转换成xml document 要求xml格式的字符串中可以有空格和换行
- java5中的枚举类型如何用在switch中
- java当中的object数组转换为string的问题
- ###actionPreformed在编译中出现的怪问题!
- <<CORE.JAVA.VOLUME I>>和VOLUME II 大家一共看了几遍?
- java实现二叉树旋转距离计算
你这个问题是由于没有Flush导致的,如果不调用flush()方法,那需要等缓冲区满以后,自动发送报文(注:缓冲区满是TCP协议层的概念,不同的操作系统对于TCP协议实现不同)