客户端
import java.io.*;
import java.net.*;
class TransClient{
public static void main(String[] args) throws Exception{
Socket s = new Socket("192.168.1.100",10005);
//定义读取键盘数据的流对象
BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
//定义目的,将数据写入到socket输出流,发给服务端
BufferedWriter bufOut = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
//定义一个socket读取流,读取服务端返回的大写信息
BufferedReader bufIn =
new BufferedReader(new InputStreamReader(s.getInputStream()));
String line = null;
while((line=bufr.readLine())!=null){
if("over".equals(line))
break;
bufOut.write(line);
bufOut.newLine();
bufOut.flush();
String str = bufIn.readLine();
System.out.println("Server:"+str);
}
bufr.close();
s.close();
}
}
|