java socket
程序代码:import import import import import public class Client {
/**
* @param args
*/
public static void main(String[] args) {
Socket socket = null;
int count = 0;
try {
socket = new Socket(InetAddress.getLocalHost(),4700);
DataInputStream is = new DataInputStream(socket.getInputStream());
DataOutputStream os = new DataOutputStream(socket.getOutputStream());
System.out.print(is.readUTF());
while(true){
os.writeUTF("你好啊" + count);
count++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
程序这样写的话可以给服务器发送你好啊,可是如果 while(true){
os.writeUTF("你好啊" + count);
count++;}
改成
os.writeUTF("你好啊" + count);
那么这一条就发送不过去是为什么啊,怎么解决呢?






