WebSocketServer wsServer = new WebSocketServer(); if (!wsServer.Setup("127.0.0.1", 2012)) { //設定IP 與 埠失敗 通常是IP 和埠範圍不對引起的 IPV4 IPV6 } if (!wsServer.Start()) { //開啟服務失敗 基本上是埠被佔用或者被 某防毒軟體攔截造成的 return; } wsServer.NewSessionConnected += (session) => { //有新的連線 }; wsServer.SessionClosed += (session, reason) => { //有斷開的連線 }; wsServer.NewMessageReceived += (session, message) => { //接收到新的文字訊息 }; wsServer.NewDataReceived += (session, bytes) => { //接收到新的二進位制訊息 };Console.ReadKey(); wsServer.Stop();
WebSocketServer wsServer = new WebSocketServer(); if (!wsServer.Setup("127.0.0.1", 2012)) { //設定IP 與 埠失敗 通常是IP 和埠範圍不對引起的 IPV4 IPV6 } if (!wsServer.Start()) { //開啟服務失敗 基本上是埠被佔用或者被 某防毒軟體攔截造成的 return; } wsServer.NewSessionConnected += (session) => { //有新的連線 }; wsServer.SessionClosed += (session, reason) => { //有斷開的連線 }; wsServer.NewMessageReceived += (session, message) => { //接收到新的文字訊息 }; wsServer.NewDataReceived += (session, bytes) => { //接收到新的二進位制訊息 };Console.ReadKey(); wsServer.Stop();