ztkmkoo / dss

Asynchronous distributed server system (dss)
MIT License
19 stars 13 forks source link

Feature/52 add websocket handler and its service interface #131

Closed Doyuni closed 4 years ago

Doyuni commented 4 years ago

I added websocket handler first. I will add service interface later.

Websocket Process

  1. Open Handshake : It occurs in DssHttpRequestHandler.java

    • Client's handshake request : HTTP Upgrade Request using only GET method
      GET /chat HTTP/1.1
      Host: dssserver.example.com
      Upgrade: websocket
      Connection: Upgrade
      Sec-WebSocket-Key: ScmyStFFNlK9TVHteROMKA==
      Origin: http://example.com
      Sec-WebSocket-Version: 13
    • Server's handshake response : Accept websocket connection with value combined websocket-key & GUID
      HTTP/1.1 101 Switching Protocols
      upgrade: websocket
      connection: upgrade
      sec-websocket-accept: t3gjBK9ILNyvtnyC+vneMlV98g4=
  2. Sending and Receiving Data Frame (Current: Echo message) : It occurs in DssWebSocketHandler.java

    • If client sends message to dss server, dss server receives message called Websocket Frame.
  3. Close connection

    I tested it works fine using Jetty websocket client or Echo Test ([https://www.websocket.org/echo.html])(https://www.websocket.org/echo.html).

Here is test logs.

[INFO ] [DssWebSocketServer.java]start(66) : Server Started
[INFO ] [DssWebSocketChannelInitializer.java]initChannel(20) : Try to initChannel
[INFO ] [DssHttpRequestHandler.java]handleHttpRequest(47) : Request URI: /websocket
[INFO ] [DssHttpRequestHandler.java]handleHttpRequest(65) : Request WebSocket Protocol
[INFO ] [DssHttpRequestHandler.java]handleHandshake(95) : Handshake Start
[INFO ] [DssHttpRequestHandler.java]handleHandshake(98) : ws://localhost:8181/websocket
[INFO ] [DssHttpRequestHandler.java]handleHandshake(106) : Handshake Success
[INFO ] [DssWebSocketHandler.java]channelRead(17) : Client Channel : [id: 0x70e76c8c, L:/127.0.0.1:8181 - R:/127.0.0.1:55702]
[INFO ] [DssWebSocketHandler.java]channelRead(23) : TextWebSocketFrame Received
[INFO ] [DssWebSocketHandler.java]channelRead(28) : Received Message : Hello! Dss Server
[INFO ] [DssWebSocketHandler.java]channelRead(17) : Client Channel : [id: 0x70e76c8c, L:/127.0.0.1:8181 - R:/127.0.0.1:55702]
[INFO ] [DssWebSocketHandler.java]channelRead(36) : CloseWebSocketFrame Received
[INFO ] [DssWebSocketHandler.java]channelRead(39) : ReasonText : 
[INFO ] [DssWebSocketHandler.java]channelRead(40) : StatusCode : 1000
[INFO ] [DssWebSocketChannelInitializer.java]initChannel(20) : Try to initChannel
[INFO ] [DssHttpRequestHandler.java]handleHttpRequest(47) : Request URI: /websocket?encoding=text
[INFO ] [DssHttpRequestHandler.java]handleHttpRequest(65) : Request WebSocket Protocol
[INFO ] [DssHttpRequestHandler.java]handleHandshake(95) : Handshake Start
[INFO ] [DssHttpRequestHandler.java]handleHandshake(98) : ws://127.0.0.1:8181/websocket
[INFO ] [DssHttpRequestHandler.java]handleHandshake(106) : Handshake Success
[INFO ] [DssWebSocketHandler.java]channelRead(17) : Client Channel : [id: 0xfed0f797, L:/127.0.0.1:8181 - R:/127.0.0.1:55731]
[INFO ] [DssWebSocketHandler.java]channelRead(23) : TextWebSocketFrame Received
[INFO ] [DssWebSocketHandler.java]channelRead(28) : Received Message : Hello

Code Review

Thank you for reading.