Socket s = new Socket("localhost", 10006);
FileInputStream fis = new FileInputStream("h://1.png");
OutputStream out = s.getOutputStream();
byte[] buf = new byte[1024];
int len =0;
while((len=fis.read(buf))!=-1) {
out.write(buf,0,len);
}
s.shutdownOutput();
InputStream in = s.getInputStream();
byte[] bufIn =new byte[1024];
int lenIn = in.read(bufIn);
String text = new String(bufIn,0,lenIn);
System.out.println(text);
fis.close();
s.close();
ServerSocket ss = new ServerSocket(10006);
Socket s = ss.accept();
String ip = s.getInetAddress().getHostAddress();
System.out.println(ip);
InputStream in =s.getInputStream();
File dir = new File("h:\\pic");
if(dir.exists()) {
dir.mkdirs();
}
File file = new File(dir,ip+".png");
FileOutputStream fos = new FileOutputStream(file);
byte[] buf =new byte[1024];
int len =0;
while((len=in.read(buf))!=-1) {
fos.write(buf, 0, len);
}
OutputStream out = s.getOutputStream();
out.write("上传成功".getBytes());
fos.close();
s.close();
ss.close();