Skip to content

how to define few ws routes? #26

@221V

Description

@221V

hello

how to define few ws routes?

for example,
from page 1 we connect to ws://localhost:8080/echo
and from page 2 we connect to ws://localhost:8081/ws2

but in dlang serverino code -

// Accept a new connection only if the request path is "/echo"
@onWebSocketUpgrade bool onUpgrade(Request req){
  return req.path == "/echo";
}

// Handle the WebSocket connection
@endpoint void echo(Request r, WebSocket ws){
  // Read messages from the client
  while(true){
    // Only if the message is valid
    if( WebSocketMessage msg = ws.receiveMessage() ){
      // Send the message back to the client
      ws.send("I received your message: `" ~ msg.asString ~ "`");
    }
  }
}

@route!"/"
@endpoint void index(Request r, Output o){ o.serveFile("static/index.html"); }

@route!"/style.css"
@endpoint void css(Request r, Output o){ o.serveFile("static/style.css"); }

what - and how - needs to change here?
for get different paths - and handlers - for different ws paths - as for different http path

thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions