假如说这个代码怎么让开启两个窗口?我一运行什么都没有显示
- import java.io.*;
- import java.net.*;
- class PicClient
- {
- public static void main(String[] args)throws Exception{
- Socket s=new Socket("192.168.1.106",5555);
- File file=new File(args[0]);
- FileInputStream fis=new FileInputStream(file);
- 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 num=in.read(bufIn);
- System.out.println(new String(bufIn,0,num));
- s.close();
- fis.close();
- }
- }
- class PicThread implements Runnable
- {
- private Socket s;
- PicThread(Socket s){
- this.s=s;
- }
- public void run(){
- String ip=s.getInetAddress().getHostAddress();
- try
- {
- System.out.println(ip+"...connect");
- int count=1;
- InputStream in=s.getInputStream();
- File file=new File(ip+"("+(count)+")"+".jpg");
- while (file.exists())
- {
- file=new File(ip+"("+(count++)+")"+".jpg");
- }
- 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());
- s.close();
- fos.close();
- }
- catch (Exception e)
- {
- throw new RuntimeException(ip+"连接失败");
- }
- }
- }
- class PicServer
- {
- public static void main(String[] args)throws Exception{
- ServerSocket ss=new ServerSocket(5555);
- while (true)
- {
- Socket s=ss.accept();
- new Thread(new PicThread(s)).start();
- }
- }
- }
复制代码 |