Class TcpServer

java.lang.Object
com.github.kokorin.jaffree.net.TcpServer
All Implemented Interfaces:
ProcessHelper, Closeable, AutoCloseable, Runnable
Direct Known Subclasses:
FtpServer, NegotiatingTcpServer

public abstract class TcpServer extends Object implements ProcessHelper
Abstract TCP Server implementing ProcessHelper.

This class is intended to be used in different ffmpeg Input & Output implementations which interact with ffmpeg via TCP sockets.

  • Constructor Details

    • TcpServer

      protected TcpServer(ServerSocket serverSocket)
      Creates TCP server.

      This implementation is not intended to be used anywhere except this project. It servers only the first accepted connection in single thread.

      Parameters:
      serverSocket - server socket to accept connection. Pay attention that server socket should listen on loopback (127.0.0.1) address for security reasons.
  • Method Details

    • run

      public final void run()
      Specified by:
      run in interface Runnable
    • serve

      protected abstract void serve(Socket socket) throws IOException
      Serves TCP connection.
      Parameters:
      socket - TCP socket
      Throws:
      IOException - socket IO exception
    • finalize

      protected final void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • close

      public void close() throws IOException
      Closes underlying TCP Socket.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if any IO error
    • getAddressAndPort

      public String getAddressAndPort()
      Returns string representation of host and port.
      Returns:
      host and port string
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • allocateSocket

      protected static ServerSocket allocateSocket()
      Allocates ServerSocket on random port of loopback network interface.
      Returns:
      ServerSocket