src/Pure/System/system_channel.scala
author wenzelm
Sat, 05 Aug 2017 15:48:02 +0200
changeset 66346 30663525e057
parent 62306 5c0a5c30cda8
child 69124 6ededdc829bb
permissions -rw-r--r--
default according to Java API, instead of jEdit usage;

/*  Title:      Pure/System/system_channel.scala
    Author:     Makarius

Socket-based system channel for inter-process communication.
*/

package isabelle


import java.io.{InputStream, OutputStream}
import java.net.{ServerSocket, InetAddress}


object System_Channel
{
  def apply(): System_Channel = new System_Channel
}

class System_Channel private
{
  private val server = new ServerSocket(0, 50, InetAddress.getByName("127.0.0.1"))

  val server_name: String = "127.0.0.1:" + server.getLocalPort
  override def toString: String = server_name

  def rendezvous(): (OutputStream, InputStream) =
  {
    val socket = server.accept
    socket.setTcpNoDelay(true)
    (socket.getOutputStream, socket.getInputStream)
  }

  def accepted() { server.close }
}