Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebSocketContext class #263

Merged
merged 8 commits into from
Jan 11, 2022
Merged

Add WebSocketContext class #263

merged 8 commits into from
Jan 11, 2022

Conversation

Feiko
Copy link
Member

@Feiko Feiko commented Jan 10, 2022

Description

Added internal class WebsocketContext exposing Headers, Socket and networkStream to only Friend System.Net.Websocket.
The WebsocketContext is created by calling HttpListnerContext.GetWebsocketContext().
Calling GetWebsocketContext also will also gracefully remove all references from HttpListner to the underlying Socket and NetworkStream without closing them. From this point it's up to the WebsocketServer to deal with the socket and networkstream.

Some properties had to be set from private to itnernal to make sure that GetWEbsocketContext() was able to gracefully remove all references and remove all resources from HttpListner. This does not expose anything to the outside except for System.Net.Websocket which is regarded as a Friend.

Motivation and Context

This will allow WebSocketServer to directly use HttpListnerContext to build up a websocket connection. This fixes the problem where you would have the websocketserver listening on one port and a HttpListner for serving static website on another port.

How Has This Been Tested?

Tested with browser and updated local websocketserver.

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (work on Unit Tests, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@dnfadmin
Copy link

dnfadmin commented Jan 10, 2022

CLA assistant check
All CLA requirements met.

Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@josesimoes josesimoes changed the title Added support for WebsocketServer by creating interal WebSocketContext - take 2 Add WebSocketContext class Jan 11, 2022
@josesimoes josesimoes enabled auto-merge (squash) January 11, 2022 13:26
@josesimoes josesimoes merged commit 3873a1b into nanoframework:develop Jan 11, 2022
@nfbot
Copy link
Member

nfbot commented Jan 11, 2022

@Feiko thank you again for your contribution! 🙏😄

.NET nanoFramework it's all about community involvement and no contribution is too small.
We would like to invite you to join the project Contributors list.

Please edit it and add an entry with your GitHub user in the appropriate location (names sorted alphabetically):

  <tr>
    <td><img src="https://github.com/Feiko.png?size=50&" height="50" width="50" ></td>
    <td><a href="https://github.com/Feiko">Feiko Gorter</a></td>
  </tr>

(feel free to adjust your name, if it's not correct)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants