本帖最后由 哇塞哇 于 2014-6-27 10:23 编辑
- import java.io.*;
- import java.net.*;
- public class Client{
- public static void main(String [] args)throws Exception{
- Socket o=new Socket("192.168.1.102",7777);
- System.out.println("请输入字符串");
- BufferedReader d=new BufferedReader(
- new InputStreamReader(System.in));
- BufferedReader dd=new BufferedReader(new InputStreamReader(o.getInputStream()));
- BufferedWriter ddd=new BufferedWriter(new OutputStreamWriter(o.getOutputStream()));
- String line=d.readLine();
-
- ddd.write(line);
-
- o.close();
- //d.close();
- //dd.close();
- //ddd.close();
- }
- }[code]import java.io.*;
- import java.net.*;
- public class Server{
- public static void main(String [] args)throws Exception{
- ServerSocket s=new ServerSocket(7777);
- Socket o=s.accept();
- InputStream k=o.getInputStream();
- OutputStream k1=o.getOutputStream();
- BufferedReader dd=new BufferedReader(new InputStreamReader(o.getInputStream()));
- BufferedWriter ddd=new BufferedWriter(new OutputStreamWriter(o.getOutputStream()));
- String line=null;
-
- line=dd.readLine();
- System.out.println(line);
- o.close();
- // kk.close();
- //kkk.close();
- }
- }
复制代码 [/code]
这个程序从客户端输入一串字符,在服务端总是打印null出来,这是为什么 |
|