package o1game.Client import java.lang.Thread.sleep import java.net.Socket import scala.io.Source import scala.sys.process.stdout import o1game.constants.* class Client(ip: String, port: Int): private val socket = Socket(ip, port) private val input = socket.getInputStream private val output = socket.getOutputStream private val buffer: Array[Byte] = Array.ofDim(MAX_MSG_SIZE) private var bufferIndex = 0 def startClient(): Unit = while true do sleep(POLL_INTERVAL) while input.available() != 0 do val bytesRead = input.read(buffer) if bytesRead != -1 then print(buffer.take(bytesRead).toVector.map(_.toChar).mkString) stdout.flush() bufferIndex = s"Houston, I think this shouldn't be so hard.\n".toVector.map(_.toByte).copyToArray(buffer) output.write(buffer, 0, bufferIndex) output.flush()