Zip server socket : ServerSocket « Network « Java Tutorial






import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import java.net.Socket;
 
class ZipSocket extends Socket {

    private InputStream in;
    private OutputStream out;

    public ZipSocket() { super(); }

    public ZipSocket(String host, int port) 
        throws IOException {
        super(host, port);
    }

    public InputStream getInputStream() 
        throws IOException {
        if (in == null) {
            in = new ZipInputStream(super.getInputStream());
        }
        return in;
    }

    public OutputStream getOutputStream() 
        throws IOException {
        if (out == null) {
            out = new ZipOutputStream(super.getOutputStream());
        }
        return out;
    }

   
    public synchronized void close() throws IOException {
        OutputStream o = getOutputStream();
        o.flush();
  super.close();
    }

}



import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;

public class ZipServerSocket extends ServerSocket
{
  public ZipServerSocket(int port) throws IOException
  { 
  super(port);
  }

  public Socket accept() throws IOException
  { 
     Socket socket = new ZipSocket();
     implAccept(socket);
     return socket;
  }
}








19.14.ServerSocket
19.14.1.Create a ServerSocket
19.14.2.Hello Server
19.14.3.Time server
19.14.4.Thread based ServerSocket
19.14.5.Generic Server
19.14.6.Timer server with Thread
19.14.7.A multithreaded Socket Server
19.14.8.Get IP address from NetworkInterface and create server socket
19.14.9.Logging Server based on SocketServer
19.14.10.Data server
19.14.11.Object server
19.14.12.Compressed socket
19.14.13.Zip server socket