阅读背景:

如何将msg发送回Scala Server中的客户端

来源:互联网 
import java.net._
import java.io._
import java.util._


object Server2{

def displayUsageInfo = {
    println("Parameters are:");
    println("  1) The port number that the server will listen on")
}

def main(args: Array[String]):Unit = {
    if(args.length != 1) {
        displayUsageInfo
    } 
    else {
        try {
            val sock=new ServerSocket(Integer.parseInt(args(0)))
            var finished = false
            while (!finished){
                println("waiting");
                val connection=sock.accept()
                println("connection from " + connection.getRemoteSocketAddress())

                val is = connection.getInputStream()  
                val in = new BufferedReader(new InputStreamReader(is))
                var line = in.readLine

                while (line!=null && !finished) {
                    line match {
                        case "quit" => finished = true
                        case _ => println("Received " + line)
                    }
                if(line == "<gia-sou/>"){
                    printf("he"); //here!!!!!!!!!!
                }

                    if(!finished){
                        line = in.readLine
                    }
                }
                connection.close
            }
        } catch {
            case e:BindException =>
                println("Cannot bind to port. Is a server already running?")
            case e:NumberFormatException =>
                println("Port number should be an integer")
            case e:IllegalArgumentException =>
                println("The port number needs to be less than 65536")
            case ex:Throwable => println("Exception: " +ex.toString())
        }
    }
}
}
import java.net._
import java.io._
import java.



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: