Skip to content

Instantly share code, notes, and snippets.

@Sciss
Created October 11, 2017 17:18
Show Gist options
  • Select an option

  • Save Sciss/9a8b198fe480e787851456a4c5749571 to your computer and use it in GitHub Desktop.

Select an option

Save Sciss/9a8b198fe480e787851456a4c5749571 to your computer and use it in GitHub Desktop.
// cf. https://stackoverflow.com/questions/13343260/telnet-like-connection-to-server-in-scala
class Connector(socket: java.net.Socket, handler: String => Unit) {
private val out = new java.io.PrintStream(socket.getOutputStream)
private val in = new java.io.BufferedReader(new java.io.InputStreamReader(socket.getInputStream))
private val receiver = new Thread {
override def run(): Unit = {
// var done = false
// while (!done) {
// val n = in.read()
// if(n < 0)
// done = true
// else
// handler(n.toChar)
// }
var msg = in.readLine()
while (msg != null) {
handler(msg)
msg = in.readLine()
}
}
start()
}
def print(msg: String): Unit = out.println(msg)
def close(): Unit = {
in .close()
out.close()
}
}
// cf. http://gqrx.dk/doc/remote-control
val socket = new java.net.Socket("127.0.0.1", 7356) // default port of gqrx
val c = new Connector(socket, println)
c.print("F 95200000")
c.print("l STRENGTH")
c.print("F 95300000")
c.print("l STRENGTH")
c.print("F 95400000")
c.print("l STRENGTH")
c.print("U RECORD 1")
c.print("U RECORD 0")
// c.close() -- that seems to hang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment