本帖最后由 陌路行者 于 2013-7-15 14:14 编辑
- import java.io.*;
- import java.net.*;
- class PicClient
- {
- public static void main(String[] args) throws Exception
- {
- Socket s = new Socket("192.168.1.12",8866);
- BufferedInputStream bis =
- new BufferedInputStream(new FileInputStream("1.jpg"));
- BufferedOutputStream bos =
- new BufferedOutputStream(s.getOutputStream());
- //byte[] buf = new byte[1024];
- int len = 0;
- while((len=bis.read())!=-1)
- {
- bos.write(len);
- }
- s.shutdownOutput();
- BufferedInputStream bufIn =
- new BufferedInputStream(s.getInputStream());
- //byte[] bufInput = new byte[1024];
-
- int num = 0;
- while((num=bufIn.read())!=-1)
- {
- System.out.println(num);
- }
- bis.close();
- s.close();
- }
- }
- class PicServer
- {
- public static void main(String[] args) throws Exception
- {
- ServerSocket ss = new ServerSocket(8866);
-
- Socket s = ss.accept();
- String ip = s.getInetAddress().getHostAddress();
- System.out.println(ip+".......connected");
- BufferedInputStream bis =
- new BufferedInputStream(s.getInputStream());
- BufferedOutputStream bos =
- new BufferedOutputStream(new FileOutputStream("2.jpg"));
- //byte[] buf = new byte[1024];
- int len = 0;
- while((len=bis.read())!=-1)
- {
- bos.write(len);
- }
- BufferedOutputStream bosOut =
- new BufferedOutputStream(s.getOutputStream());
- bosOut.write("上传成功".getBytes());
- bos.close();
- s.close();
- ss.close();
- }
- }
复制代码 而且还读不到服务端反馈的信息 |