package cn.innet.demo.tcp.touppdate;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class Client {
public static void main(String[] args) throws UnknownHostException, IOException {
Socket socket = new Socket("192.168.0.100", 8888);
BufferedReader key_bufr = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter socket_bufw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
BufferedReader socket_bufr = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line = null;
System.out.println("连接成功");
while((line = key_bufr.readLine())!=null){
if("over".equals(line)){
break;
}
System.out.println("读取到的:"+line);
socket_bufw.write(line);
System.out.println("已写出");
socket_bufw.flush();
System.out.println("已刷新");
System.out.println(socket_bufr.readLine());
}
socket.close();
}
}
===========================================================
package cn.innet.demo.tcp.touppdate;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(8888);
Socket socket = serverSocket.accept();
String ip = socket.getInetAddress().getHostAddress();
System.out.println(ip+"......connected");
BufferedReader socket_bufr = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter socket_bufw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
String line = null;
System.out.println("等待读取网络流数据");
while((line = socket_bufr.readLine())!=null){
System.out.println(line);
socket_bufw.write(line.toUpperCase());
socket_bufw.flush();
}
serverSocket.close();
socket.close();
}
}
============================================================
为什么我的客户端写的数据服务端接收不到啊 客户端卡在"已刷新",服务端卡在"等待读取网络流数据".....我明明是从客户端把数据写到网络流里 然后服务端那边去接收的呀