From 8595e892abc0e0554f589ed2eb88c351a347fbd4 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 17 Nov 2024 02:38:55 +0200 Subject: Implemented talking --- src/main/scala/Server/Client.scala | 5 ----- src/main/scala/Server/Server.scala | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) (limited to 'src/main/scala/Server') diff --git a/src/main/scala/Server/Client.scala b/src/main/scala/Server/Client.scala index 7c7a786..3cd2b36 100644 --- a/src/main/scala/Server/Client.scala +++ b/src/main/scala/Server/Client.scala @@ -100,11 +100,6 @@ class Client(val socket: Socket): if nextCRLF != -1 then val message = this.incompleteMessage.take(nextCRLF) val rest = this.incompleteMessage.drop(nextCRLF + 2) - assert(rest.headOption != Some(CRLF(1))) // I will compile this with - // assertions off... I'd - // like to know how to make - // tests work with this - // config... this.incompleteMessage = rest ++ Array.fill(nextCRLF + 1)(0.toByte) // TODO: the conversion may probably be exploited to crash the server Some(String(message)) diff --git a/src/main/scala/Server/Server.scala b/src/main/scala/Server/Server.scala index 4a984a5..7864c49 100644 --- a/src/main/scala/Server/Server.scala +++ b/src/main/scala/Server/Server.scala @@ -160,14 +160,14 @@ class Server( private def writeToAll(message: String): Unit = this.clients.mapAndRemove(c => val output = c.socket.getOutputStream - output.write(message.toVector.map(_.toByte).toArray) + output.write(stringToByteArray(message)) output.flush() ) private def writeToClient(message: String, client: Client): Unit = try { val output = client.socket.getOutputStream - output.write(message.toVector.map(_.toByte).toArray) + output.write(stringToByteArray(message)) output.flush() } catch { case e: IOException => client.failedProtocol() @@ -178,7 +178,7 @@ class Server( this.clients.mapAndRemove(c => val output = c.socket.getOutputStream val data = c.dataToThisClient() - output.write(data.toVector.map(_.toByte).toArray) + output.write(stringToByteArray(data)) output.flush() ) -- cgit v1.2.3