合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
## server::setoption ### 接口说明 >设置服务端配置参数 > +++ put:setoption var:option=ServerOption类# <<< success 无返回值 +++ ### 代码演示 ~~~ #import "socket" var socket_accept(var socketIndex) { println("检测到有一个连接:"..socketIndex); } var socket_data(var socketIndex,var buffer) { var s = buffer.tostring(); println(s); if(s == "e") { srv.closesocket(socketIndex); } var writer = new Buffer(); writer.writeString(buffer.tostring()); srv.send(socketIndex, writer); } var socket_close(var socketIndex,var err,var errstr) { println("检测到有一个关闭:{socketIndex},err:{err},errstr:{errstr}"); } var socket_parser(var headerbuffer) { var packagesize = headerbuffer.readInt32(); return packagesize; // 根据包头协议包大小 } println("start server"); var srv = new socket::server().setoption(new ServerOption(){ ip = "0.0.0.0", accept = socket_accept, data = socket_data, close = socket_close }).listen(4060); //使用带协议头方式 // var srv = new socket::server().setOption(new ServerOption(){ // ip = "0.0.0.0", // headersize = 4,//字节 // accept = socket_accept, // data = socket_data, // close = socket_close, // parser = socket_parser // }).listen(4060); println("start over"); while (true) srv.run(); ~~~