SlideShare a Scribd company logo
ASP.NET CORE 帶您
讀源碼
WebSocket 篇
WebSocket
■ Duplex bi-directional Api for web
server  client
■ RFC 6455
https://tools.ietf.org/html/rfc6455
■ W3C standard:
https://www.w3.org/TR/websockets
/
■ Transport protocol intro:
https://www.youtube.com/watch?v=
9FqjRN4VYUU
■ Js Client & protocol packet format
intro: https://hpbn.co/websocket/
WebSocket
Connect State Transition
1. Connection Upgrade
(Protocol Switch)
2. Data In/Out arbitrarily
(Ping  Pong to detect online)
3. Close connection handshake
Transfer “Frame” format
Read the source?!
Experiment with source!!
(tracing/logging or make it
debuggable)■ Client :
websocket-sharp
https://sta.github.io/websocket-
sharp/
■ Server :
ASP.NET Core v2.1.1 Websocket
https://docs.microsoft.com/en-
us/aspnet/core/fundamentals/webso
ckets?view=aspnetcore-2.1
websocket-sharp
■ Run on .NET Framework 3.5 and above, Mono, Unity3D
■ A single DLL provide websocket client/server functionality, comply with RFC 6455
■ HTTPS encrypt/decrypt algorithm is via Framework functionality
■ MIT license
websocket-sharp
■ Client usage is very simple:
https://github.com/sta/websocket-
sharp#websocket-client
■ Has event hook let client handler websocket event
easily: http://bit.ly/2ztELl9
■ Mimic Js Websocket API:
https://developer.mozilla.org/en-
US/docs/Web/API/WebSocket
■ Entry Point: the “WebSocket” class: http://bit.ly/2L76Xf2
■ WebSocket Connect() Implementation:
– Connect() API : http://bit.ly/2KVjLsf
 doHandshake() : http://bit.ly/2J9ySJn
 setClientStream() : http://bit.ly/2zsdLCN
 createHandshakeRequest() : http://bit.ly/2KKAkHO
 sendHttpRequest() : http://bit.ly/2JeiYgX
 checkHandshakeResponse() : http://bit.ly/2zsim7O
=> Create “NetworkStream (http://bit.ly/2L3q5xE)” for afterward R/W operation
■ WebSocket Send() Implementation:
– Send() API : http://bit.ly/2LaYY0I
 send(Opcode opcode, Stream stream, bool compressed) : http://bit.ly/2N31aYq
 send(Fin fin, Opcode opcode, byte[] data, bool compressed) : http://bit.ly/2KPszQQ
 sendBytes(byte[] bytes) : http://bit.ly/2zoQCkx
=> Wrap input into a lot of “WebSocketFrame (http://bit.ly/2N5zfHh)” then write to stream
■ WebSocket OnMessage event Implementation:
– EventHandler<MessageEventArgs> OnMessage :
■ There’re two place emit the event:
– messagec(MessageEventArgs e) : http://bit.ly/2L7etGO
■ This is binding to Action<> _message field, which is invoked On:
– open() : http://bit.ly/2uaCGpl
■ Being called at Connect() API : http://bit.ly/2L65rgE
– message() : http://bit.ly/2KMUt00
– startReceiving() : http://bit.ly/2NEcATw
– open() : http://bit.ly/2zssHAE
=> Get data from internal _messageEventQueue.Dequeue() then invoke the event.
ASP.NET Core Websocket Server
■ The whole implementation across many “Nuget Packges (https://www.nuget.org/packages)”:
– Microsoft.AspNetCore.Websockets
– Microsoft.AspNetCore.Http.Abstractions
– Microsoft.AspNetCore.Http
– Microsoft.AspNetCore.Http.Extensions
– Microsoft.AspNetCore.Http.Features
– Microsoft.AspNetCore.Server.Kestrel
– Microsoft.AspNetCore.Server.Kestrel.Core
– System.Net.WebSockets.WebSocketProtocol
– System.Net.WebSockets
■ It’s impossible to get through whole source code simply by human 👀!!!
■ We have to “experiment it” with debuggable source code or being able to logging detail
information.
Build ASP.Net Core Framework
Package
(make it debuggable)■ Build debuggable ASP.NET Core nuget packages?
1. Clone the official build repo: Universe https://github.com/aspnet/Universe
2. Build it…...since ASP.NET Core module’s source has almost unified folder
structure convention:
■ src: The real source code
■ test: Testing code
■ sample: sample project or test to verify production source
■ build: build configuration files
■ Write a example project to use those debuggable packages then run it, dive into….
Build ASP.Net Core Framework Package
■ To build individual packages:
1. In Windows machine, Install chocolatey, git for windows, Visual Studio 2017
and ASP.NET workload, node.js (for npm):
https://github.com/aspnet/Universe/wiki/Setting-a-machine-up-to-run-Universe
2. Clone Universe repo with correct tag ( -b 2.1.1), be sure to use --recursive to
get associated git submodule repo in modules folder.
3. Run build.cmd (build.sh) on top folder to let ASP.NET Core Buildtools setup
correct config files on first time, even if not all module can successful build.
4. Make sure the residue build process are all killed.
5. Switch to the module folder you want to build, delete anything in
artifactsbuild subfolder, then use:
build.cmd /p:CompileOnly=true /p:SkipTests=true
To build those Nuget packages of the module, Resulting files will reside in
module folder's artifactsbuild folder, and by default, they are debuggable.
Build ASP.Net Core Framework
Package
(make it debuggable)■ Use “find –iname“ or “dir /s” to find Nuget packages real source location in
Universe repo:
■ Exception:
Microsoft.AspNetCore.Server.Kestrel
Microsoft.AspNetCore.Server.Kestrel.Core
is in modulesKestrelHttpServer folder
■ But the
System.Net.WebSockets.WebSocketProtocol
System.Net.WebSockets
packages are .NET Core runtime’s built-in libraries, that belongs to the
“CoreFx (https://github.com/dotnet/corefx)” repo, not in ASP.NET Core
Time Savior: SourceLink support in
VisualStudio
(https://github.com/dotnet/sourcelink )
■ Visual Studio 2017 v15.7 and above support
SourceLink ( https://docs.microsoft.com/en-
us/visualstudio/releasenotes/vs2017-
relnotes#debug) ,
■ Begin from ASP.NET Core 2.0 it support
SourceLink too:
https://github.com/dotnet/core/issues/897,
but some packages may not ready:
https://github.com/dotnet/buildtools/issues/
1896
■ Most of time it just works 👍
■ Caveat:
– Can not use “GoToDefinition(F12)” if it hasn’t been using debugger dive into it.
– If source code already disappear on GitHub, it cannot work.
– Some too deep function(s) may not work (may be bug?!)
Example experiment project
■ Example source repo:
http://bit.ly/2KO3B4n
■ It use .NET Core SCD deployment
(http://bit.ly/2maxCgj)to let
ASP.NET core runtime use
debuggable Nuget packages we
created.
■ Runs only on Win10-x64
machine.
Some interesting digging result: (1)
■ WebSocket connection setup is implmented in “DefaultWebSocketManager”, its
AccetpWebSocketAsync() is forwarding Websocket upgrade connection work to
WebSocketMiddleware: http://bit.ly/2ukREs1
■ WebSocket SHA-1 encrypt key is hard-coded: http://bit.ly/2N2oTYT
Some interesting digging result: (2)
■ The real “Connection Upgrade” phase is done in
Microsoft.AspNetCore.Server.Kestrel
nuget package’s code, which is Web Server itself:
http://bit.ly/2umVGjz
■ And the WebSocket(http://bit.ly/2KO5uhK) instance is created from websocket
middleware using “HttpResponseStream” as source, the real class is
“ManagedWebSocket”, an internal un-documented Class:
Some interesting digging result: (3)
■ The Actual ReadAsync() & WriteAsync() implementation entry point is extension
methods: http://bit.ly/2uo2ZaL
■ Write data to websocket’s final operations is call HttpUpgradeStream’s
WriteAsync(), which is also located in Web Server itself (the
Microsoft.AspNetCore.Server.Kestrel.Core Nuget package) :
http://bit.ly/2uaKk33
■ Closing websocket implementation is done by ManagedWebSocket class itself:
http://bit.ly/2mbw9pW
WebSocket’s ReadAsync() final operation:
WebSocket’s WriteAsync() final operation:
Conclusion
■ ASP.NET Core use many Abstract class and Interface in its API, and the real
implementation is DefaultOOXX most of the time.
Ex:
WebSocketManager  DefaultWebSocketManager
HttpContext  DefaultHttpContext
■ ASP.NET Core’s Middleware is binding via “Microsoft.AspNetCore.Http.Features”
Nuget’s code.
Resources & Tools:
■ SourceGrpah: https://sourcegraph.com/
■ VSCode & OmniSharp extension:
https://code.visualstudio.com/Docs/languages/csharp
■ MDN:
– Websocket API: https://developer.mozilla.org/en-
US/docs/Web/API/Websockets_API
– Writing WebSocket servers: https://developer.mozilla.org/en-
US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers

More Related Content

What's hot

わかった気になるMySQL
わかった気になるMySQLわかった気になるMySQL
わかった気になるMySQL
yoku0825
 
MySQL Router REST API
MySQL Router REST APIMySQL Router REST API
MySQL Router REST API
Frederic Descamps
 
/etc/network/interfaces について
/etc/network/interfaces について/etc/network/interfaces について
/etc/network/interfaces について
Kazuhiro Nishiyama
 
Zap Scanning
Zap ScanningZap Scanning
Zap Scanning
Suresh Kumar
 
サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技
サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技
サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技
yoku0825
 
Fluentdで本番環境を再現
Fluentdで本番環境を再現Fluentdで本番環境を再現
Fluentdで本番環境を再現
Hiroshi Toyama
 
MySQL operator for_kubernetes
MySQL operator for_kubernetesMySQL operator for_kubernetes
MySQL operator for_kubernetes
rockplace
 
Advanced Jasper Reports
Advanced Jasper ReportsAdvanced Jasper Reports
Advanced Jasper Reports
Mindfire Solutions
 
XPDDS17: Introduction to Intel SGX and SGX Virtualization - Kai Huang, Intel
XPDDS17: Introduction to Intel SGX and SGX Virtualization - Kai Huang, IntelXPDDS17: Introduction to Intel SGX and SGX Virtualization - Kai Huang, Intel
XPDDS17: Introduction to Intel SGX and SGX Virtualization - Kai Huang, Intel
The Linux Foundation
 
Spanner移行について本気出して考えてみた
Spanner移行について本気出して考えてみたSpanner移行について本気出して考えてみた
Spanner移行について本気出して考えてみた
techgamecollege
 
Spring Boot on Amazon Web Services with Spring Cloud AWS
Spring Boot on Amazon Web Services with Spring Cloud AWSSpring Boot on Amazon Web Services with Spring Cloud AWS
Spring Boot on Amazon Web Services with Spring Cloud AWS
VMware Tanzu
 
Inside PostgreSQL Shared Memory
Inside PostgreSQL Shared MemoryInside PostgreSQL Shared Memory
Inside PostgreSQL Shared Memory
EDB
 
Spring Mvc,Java, Spring
Spring Mvc,Java, SpringSpring Mvc,Java, Spring
Spring Mvc,Java, Spring
ifnu bima
 
MySQL 8.0: GIS — Are you ready?
MySQL 8.0: GIS — Are you ready?MySQL 8.0: GIS — Are you ready?
MySQL 8.0: GIS — Are you ready?
Norvald Ryeng
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
HashiCorp Vault 紹介
HashiCorp Vault 紹介HashiCorp Vault 紹介
HashiCorp Vault 紹介
hashicorpjp
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot Actuator
Rowell Belen
 
MySQLレプリケーションあれやこれや
MySQLレプリケーションあれやこれやMySQLレプリケーションあれやこれや
MySQLレプリケーションあれやこれや
yoku0825
 
CSI Driverを開発し自社プライベートクラウドにより適した安全なKubernetes Secrets管理を実現した話
CSI Driverを開発し自社プライベートクラウドにより適した安全なKubernetes Secrets管理を実現した話CSI Driverを開発し自社プライベートクラウドにより適した安全なKubernetes Secrets管理を実現した話
CSI Driverを開発し自社プライベートクラウドにより適した安全なKubernetes Secrets管理を実現した話
Katsuya Yamaguchi
 
Ksplice - Keep your Database systems up to date with no downtime
Ksplice - Keep your Database systems up to date with no downtime Ksplice - Keep your Database systems up to date with no downtime
Ksplice - Keep your Database systems up to date with no downtime
Luis Marques
 

What's hot (20)

わかった気になるMySQL
わかった気になるMySQLわかった気になるMySQL
わかった気になるMySQL
 
MySQL Router REST API
MySQL Router REST APIMySQL Router REST API
MySQL Router REST API
 
/etc/network/interfaces について
/etc/network/interfaces について/etc/network/interfaces について
/etc/network/interfaces について
 
Zap Scanning
Zap ScanningZap Scanning
Zap Scanning
 
サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技
サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技
サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技
 
Fluentdで本番環境を再現
Fluentdで本番環境を再現Fluentdで本番環境を再現
Fluentdで本番環境を再現
 
MySQL operator for_kubernetes
MySQL operator for_kubernetesMySQL operator for_kubernetes
MySQL operator for_kubernetes
 
Advanced Jasper Reports
Advanced Jasper ReportsAdvanced Jasper Reports
Advanced Jasper Reports
 
XPDDS17: Introduction to Intel SGX and SGX Virtualization - Kai Huang, Intel
XPDDS17: Introduction to Intel SGX and SGX Virtualization - Kai Huang, IntelXPDDS17: Introduction to Intel SGX and SGX Virtualization - Kai Huang, Intel
XPDDS17: Introduction to Intel SGX and SGX Virtualization - Kai Huang, Intel
 
Spanner移行について本気出して考えてみた
Spanner移行について本気出して考えてみたSpanner移行について本気出して考えてみた
Spanner移行について本気出して考えてみた
 
Spring Boot on Amazon Web Services with Spring Cloud AWS
Spring Boot on Amazon Web Services with Spring Cloud AWSSpring Boot on Amazon Web Services with Spring Cloud AWS
Spring Boot on Amazon Web Services with Spring Cloud AWS
 
Inside PostgreSQL Shared Memory
Inside PostgreSQL Shared MemoryInside PostgreSQL Shared Memory
Inside PostgreSQL Shared Memory
 
Spring Mvc,Java, Spring
Spring Mvc,Java, SpringSpring Mvc,Java, Spring
Spring Mvc,Java, Spring
 
MySQL 8.0: GIS — Are you ready?
MySQL 8.0: GIS — Are you ready?MySQL 8.0: GIS — Are you ready?
MySQL 8.0: GIS — Are you ready?
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
HashiCorp Vault 紹介
HashiCorp Vault 紹介HashiCorp Vault 紹介
HashiCorp Vault 紹介
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot Actuator
 
MySQLレプリケーションあれやこれや
MySQLレプリケーションあれやこれやMySQLレプリケーションあれやこれや
MySQLレプリケーションあれやこれや
 
CSI Driverを開発し自社プライベートクラウドにより適した安全なKubernetes Secrets管理を実現した話
CSI Driverを開発し自社プライベートクラウドにより適した安全なKubernetes Secrets管理を実現した話CSI Driverを開発し自社プライベートクラウドにより適した安全なKubernetes Secrets管理を実現した話
CSI Driverを開発し自社プライベートクラウドにより適した安全なKubernetes Secrets管理を実現した話
 
Ksplice - Keep your Database systems up to date with no downtime
Ksplice - Keep your Database systems up to date with no downtime Ksplice - Keep your Database systems up to date with no downtime
Ksplice - Keep your Database systems up to date with no downtime
 

Similar to WebSocket on client & server using websocket-sharp & ASP.NET Core

Dependent things dependency management for apple sw - slideshare
Dependent things   dependency management for apple sw - slideshareDependent things   dependency management for apple sw - slideshare
Dependent things dependency management for apple sw - slideshare
Cavelle Benjamin
 
Rust Embedded Development on ESP32 and basics of Async with Embassy
Rust Embedded Development on ESP32 and basics of Async with EmbassyRust Embedded Development on ESP32 and basics of Async with Embassy
Rust Embedded Development on ESP32 and basics of Async with Embassy
Juraj Michálek
 
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
William Chong
 
Node.js an Exectutive View
Node.js an Exectutive ViewNode.js an Exectutive View
Node.js an Exectutive View
Manuel Eusebio de Paz Carmona
 
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Florent BENOIT
 
The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
Oleg Podsechin
 
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808
Cisco DevNet
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
Fabien Potencier
 
Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!
🎤 Hanno Embregts 🎸
 
Getting started with open mobile development on the Openmoko platform
Getting started with open mobile development on the Openmoko platformGetting started with open mobile development on the Openmoko platform
Getting started with open mobile development on the Openmoko platform
Jean-Michel Bouffard
 
Improve your Java Environment with Docker
Improve your Java Environment with DockerImprove your Java Environment with Docker
Improve your Java Environment with Docker
HanoiJUG
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Eugene Yokota
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
biicode
 
GDGSCL - Docker a jeho provoz v Heroku a AWS
GDGSCL - Docker a jeho provoz v Heroku a AWSGDGSCL - Docker a jeho provoz v Heroku a AWS
GDGSCL - Docker a jeho provoz v Heroku a AWS
Ladislav Prskavec
 
Plugins 2.0: The Overview
Plugins 2.0: The OverviewPlugins 2.0: The Overview
Plugins 2.0: The Overview
Atlassian
 
DevFest 2022 - Cloud Workstation Introduction TaiChung
DevFest 2022 - Cloud Workstation Introduction TaiChungDevFest 2022 - Cloud Workstation Introduction TaiChung
DevFest 2022 - Cloud Workstation Introduction TaiChung
KAI CHU CHUNG
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'a
corehard_by
 
A glance at the Rust SWC
A glance at the Rust SWCA glance at the Rust SWC
A glance at the Rust SWC
Thien Ly
 
oSC-2023-Cross-Build.pdf
oSC-2023-Cross-Build.pdfoSC-2023-Cross-Build.pdf
oSC-2023-Cross-Build.pdf
AdrianSchrter1
 
(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems
sosorry
 

Similar to WebSocket on client & server using websocket-sharp & ASP.NET Core (20)

Dependent things dependency management for apple sw - slideshare
Dependent things   dependency management for apple sw - slideshareDependent things   dependency management for apple sw - slideshare
Dependent things dependency management for apple sw - slideshare
 
Rust Embedded Development on ESP32 and basics of Async with Embassy
Rust Embedded Development on ESP32 and basics of Async with EmbassyRust Embedded Development on ESP32 and basics of Async with Embassy
Rust Embedded Development on ESP32 and basics of Async with Embassy
 
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
 
Node.js an Exectutive View
Node.js an Exectutive ViewNode.js an Exectutive View
Node.js an Exectutive View
 
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
 
The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
 
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
 
Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!
 
Getting started with open mobile development on the Openmoko platform
Getting started with open mobile development on the Openmoko platformGetting started with open mobile development on the Openmoko platform
Getting started with open mobile development on the Openmoko platform
 
Improve your Java Environment with Docker
Improve your Java Environment with DockerImprove your Java Environment with Docker
Improve your Java Environment with Docker
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
GDGSCL - Docker a jeho provoz v Heroku a AWS
GDGSCL - Docker a jeho provoz v Heroku a AWSGDGSCL - Docker a jeho provoz v Heroku a AWS
GDGSCL - Docker a jeho provoz v Heroku a AWS
 
Plugins 2.0: The Overview
Plugins 2.0: The OverviewPlugins 2.0: The Overview
Plugins 2.0: The Overview
 
DevFest 2022 - Cloud Workstation Introduction TaiChung
DevFest 2022 - Cloud Workstation Introduction TaiChungDevFest 2022 - Cloud Workstation Introduction TaiChung
DevFest 2022 - Cloud Workstation Introduction TaiChung
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'a
 
A glance at the Rust SWC
A glance at the Rust SWCA glance at the Rust SWC
A glance at the Rust SWC
 
oSC-2023-Cross-Build.pdf
oSC-2023-Cross-Build.pdfoSC-2023-Cross-Build.pdf
oSC-2023-Cross-Build.pdf
 
(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems
 

More from Chen Yu Pao

HoloLens 2的 MR(Mixed Reality)開發入門
HoloLens 2的 MR(Mixed Reality)開發入門HoloLens 2的 MR(Mixed Reality)開發入門
HoloLens 2的 MR(Mixed Reality)開發入門
Chen Yu Pao
 
SkiaSharp on Xamarin Forms
SkiaSharp on Xamarin FormsSkiaSharp on Xamarin Forms
SkiaSharp on Xamarin Forms
Chen Yu Pao
 
ReactiveUI Xamarin.Forms
ReactiveUI Xamarin.FormsReactiveUI Xamarin.Forms
ReactiveUI Xamarin.Forms
Chen Yu Pao
 
Xamarin Form using ASP.NET Core SignalR client
Xamarin Form using ASP.NET Core SignalR clientXamarin Form using ASP.NET Core SignalR client
Xamarin Form using ASP.NET Core SignalR client
Chen Yu Pao
 
使用JetBrains Rider開發Xamarin Forms
使用JetBrains Rider開發Xamarin Forms使用JetBrains Rider開發Xamarin Forms
使用JetBrains Rider開發Xamarin Forms
Chen Yu Pao
 
Xamarin ARKit Introduction 01
Xamarin ARKit Introduction 01Xamarin ARKit Introduction 01
Xamarin ARKit Introduction 01
Chen Yu Pao
 
Xamarin native forms
Xamarin native formsXamarin native forms
Xamarin native forms
Chen Yu Pao
 
Xamarin的Azure後端懶人包
Xamarin的Azure後端懶人包Xamarin的Azure後端懶人包
Xamarin的Azure後端懶人包
Chen Yu Pao
 
Proto actor 串接 Go 與 C# 簡易上手
Proto actor 串接 Go 與 C# 簡易上手Proto actor 串接 Go 與 C# 簡易上手
Proto actor 串接 Go 與 C# 簡易上手
Chen Yu Pao
 

More from Chen Yu Pao (9)

HoloLens 2的 MR(Mixed Reality)開發入門
HoloLens 2的 MR(Mixed Reality)開發入門HoloLens 2的 MR(Mixed Reality)開發入門
HoloLens 2的 MR(Mixed Reality)開發入門
 
SkiaSharp on Xamarin Forms
SkiaSharp on Xamarin FormsSkiaSharp on Xamarin Forms
SkiaSharp on Xamarin Forms
 
ReactiveUI Xamarin.Forms
ReactiveUI Xamarin.FormsReactiveUI Xamarin.Forms
ReactiveUI Xamarin.Forms
 
Xamarin Form using ASP.NET Core SignalR client
Xamarin Form using ASP.NET Core SignalR clientXamarin Form using ASP.NET Core SignalR client
Xamarin Form using ASP.NET Core SignalR client
 
使用JetBrains Rider開發Xamarin Forms
使用JetBrains Rider開發Xamarin Forms使用JetBrains Rider開發Xamarin Forms
使用JetBrains Rider開發Xamarin Forms
 
Xamarin ARKit Introduction 01
Xamarin ARKit Introduction 01Xamarin ARKit Introduction 01
Xamarin ARKit Introduction 01
 
Xamarin native forms
Xamarin native formsXamarin native forms
Xamarin native forms
 
Xamarin的Azure後端懶人包
Xamarin的Azure後端懶人包Xamarin的Azure後端懶人包
Xamarin的Azure後端懶人包
 
Proto actor 串接 Go 與 C# 簡易上手
Proto actor 串接 Go 與 C# 簡易上手Proto actor 串接 Go 與 C# 簡易上手
Proto actor 串接 Go 與 C# 簡易上手
 

Recently uploaded

Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
Drona Infotech
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 

Recently uploaded (20)

Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 

WebSocket on client & server using websocket-sharp & ASP.NET Core

  • 2. WebSocket ■ Duplex bi-directional Api for web server  client ■ RFC 6455 https://tools.ietf.org/html/rfc6455 ■ W3C standard: https://www.w3.org/TR/websockets / ■ Transport protocol intro: https://www.youtube.com/watch?v= 9FqjRN4VYUU ■ Js Client & protocol packet format intro: https://hpbn.co/websocket/
  • 3. WebSocket Connect State Transition 1. Connection Upgrade (Protocol Switch) 2. Data In/Out arbitrarily (Ping  Pong to detect online) 3. Close connection handshake Transfer “Frame” format
  • 5. Experiment with source!! (tracing/logging or make it debuggable)■ Client : websocket-sharp https://sta.github.io/websocket- sharp/ ■ Server : ASP.NET Core v2.1.1 Websocket https://docs.microsoft.com/en- us/aspnet/core/fundamentals/webso ckets?view=aspnetcore-2.1
  • 6. websocket-sharp ■ Run on .NET Framework 3.5 and above, Mono, Unity3D ■ A single DLL provide websocket client/server functionality, comply with RFC 6455 ■ HTTPS encrypt/decrypt algorithm is via Framework functionality ■ MIT license
  • 7. websocket-sharp ■ Client usage is very simple: https://github.com/sta/websocket- sharp#websocket-client ■ Has event hook let client handler websocket event easily: http://bit.ly/2ztELl9 ■ Mimic Js Websocket API: https://developer.mozilla.org/en- US/docs/Web/API/WebSocket
  • 8. ■ Entry Point: the “WebSocket” class: http://bit.ly/2L76Xf2 ■ WebSocket Connect() Implementation: – Connect() API : http://bit.ly/2KVjLsf  doHandshake() : http://bit.ly/2J9ySJn  setClientStream() : http://bit.ly/2zsdLCN  createHandshakeRequest() : http://bit.ly/2KKAkHO  sendHttpRequest() : http://bit.ly/2JeiYgX  checkHandshakeResponse() : http://bit.ly/2zsim7O => Create “NetworkStream (http://bit.ly/2L3q5xE)” for afterward R/W operation ■ WebSocket Send() Implementation: – Send() API : http://bit.ly/2LaYY0I  send(Opcode opcode, Stream stream, bool compressed) : http://bit.ly/2N31aYq  send(Fin fin, Opcode opcode, byte[] data, bool compressed) : http://bit.ly/2KPszQQ  sendBytes(byte[] bytes) : http://bit.ly/2zoQCkx => Wrap input into a lot of “WebSocketFrame (http://bit.ly/2N5zfHh)” then write to stream
  • 9. ■ WebSocket OnMessage event Implementation: – EventHandler<MessageEventArgs> OnMessage : ■ There’re two place emit the event: – messagec(MessageEventArgs e) : http://bit.ly/2L7etGO ■ This is binding to Action<> _message field, which is invoked On: – open() : http://bit.ly/2uaCGpl ■ Being called at Connect() API : http://bit.ly/2L65rgE – message() : http://bit.ly/2KMUt00 – startReceiving() : http://bit.ly/2NEcATw – open() : http://bit.ly/2zssHAE => Get data from internal _messageEventQueue.Dequeue() then invoke the event.
  • 10. ASP.NET Core Websocket Server ■ The whole implementation across many “Nuget Packges (https://www.nuget.org/packages)”: – Microsoft.AspNetCore.Websockets – Microsoft.AspNetCore.Http.Abstractions – Microsoft.AspNetCore.Http – Microsoft.AspNetCore.Http.Extensions – Microsoft.AspNetCore.Http.Features – Microsoft.AspNetCore.Server.Kestrel – Microsoft.AspNetCore.Server.Kestrel.Core – System.Net.WebSockets.WebSocketProtocol – System.Net.WebSockets ■ It’s impossible to get through whole source code simply by human 👀!!! ■ We have to “experiment it” with debuggable source code or being able to logging detail information.
  • 11. Build ASP.Net Core Framework Package (make it debuggable)■ Build debuggable ASP.NET Core nuget packages? 1. Clone the official build repo: Universe https://github.com/aspnet/Universe 2. Build it…...since ASP.NET Core module’s source has almost unified folder structure convention: ■ src: The real source code ■ test: Testing code ■ sample: sample project or test to verify production source ■ build: build configuration files ■ Write a example project to use those debuggable packages then run it, dive into….
  • 12.
  • 13. Build ASP.Net Core Framework Package ■ To build individual packages: 1. In Windows machine, Install chocolatey, git for windows, Visual Studio 2017 and ASP.NET workload, node.js (for npm): https://github.com/aspnet/Universe/wiki/Setting-a-machine-up-to-run-Universe 2. Clone Universe repo with correct tag ( -b 2.1.1), be sure to use --recursive to get associated git submodule repo in modules folder. 3. Run build.cmd (build.sh) on top folder to let ASP.NET Core Buildtools setup correct config files on first time, even if not all module can successful build. 4. Make sure the residue build process are all killed. 5. Switch to the module folder you want to build, delete anything in artifactsbuild subfolder, then use: build.cmd /p:CompileOnly=true /p:SkipTests=true To build those Nuget packages of the module, Resulting files will reside in module folder's artifactsbuild folder, and by default, they are debuggable.
  • 14. Build ASP.Net Core Framework Package (make it debuggable)■ Use “find –iname“ or “dir /s” to find Nuget packages real source location in Universe repo: ■ Exception: Microsoft.AspNetCore.Server.Kestrel Microsoft.AspNetCore.Server.Kestrel.Core is in modulesKestrelHttpServer folder ■ But the System.Net.WebSockets.WebSocketProtocol System.Net.WebSockets packages are .NET Core runtime’s built-in libraries, that belongs to the “CoreFx (https://github.com/dotnet/corefx)” repo, not in ASP.NET Core
  • 15. Time Savior: SourceLink support in VisualStudio (https://github.com/dotnet/sourcelink ) ■ Visual Studio 2017 v15.7 and above support SourceLink ( https://docs.microsoft.com/en- us/visualstudio/releasenotes/vs2017- relnotes#debug) , ■ Begin from ASP.NET Core 2.0 it support SourceLink too: https://github.com/dotnet/core/issues/897, but some packages may not ready: https://github.com/dotnet/buildtools/issues/ 1896 ■ Most of time it just works 👍
  • 16. ■ Caveat: – Can not use “GoToDefinition(F12)” if it hasn’t been using debugger dive into it. – If source code already disappear on GitHub, it cannot work. – Some too deep function(s) may not work (may be bug?!)
  • 17. Example experiment project ■ Example source repo: http://bit.ly/2KO3B4n ■ It use .NET Core SCD deployment (http://bit.ly/2maxCgj)to let ASP.NET core runtime use debuggable Nuget packages we created. ■ Runs only on Win10-x64 machine.
  • 18.
  • 19. Some interesting digging result: (1) ■ WebSocket connection setup is implmented in “DefaultWebSocketManager”, its AccetpWebSocketAsync() is forwarding Websocket upgrade connection work to WebSocketMiddleware: http://bit.ly/2ukREs1 ■ WebSocket SHA-1 encrypt key is hard-coded: http://bit.ly/2N2oTYT
  • 20. Some interesting digging result: (2) ■ The real “Connection Upgrade” phase is done in Microsoft.AspNetCore.Server.Kestrel nuget package’s code, which is Web Server itself: http://bit.ly/2umVGjz ■ And the WebSocket(http://bit.ly/2KO5uhK) instance is created from websocket middleware using “HttpResponseStream” as source, the real class is “ManagedWebSocket”, an internal un-documented Class:
  • 21. Some interesting digging result: (3) ■ The Actual ReadAsync() & WriteAsync() implementation entry point is extension methods: http://bit.ly/2uo2ZaL ■ Write data to websocket’s final operations is call HttpUpgradeStream’s WriteAsync(), which is also located in Web Server itself (the Microsoft.AspNetCore.Server.Kestrel.Core Nuget package) : http://bit.ly/2uaKk33 ■ Closing websocket implementation is done by ManagedWebSocket class itself: http://bit.ly/2mbw9pW
  • 24. Conclusion ■ ASP.NET Core use many Abstract class and Interface in its API, and the real implementation is DefaultOOXX most of the time. Ex: WebSocketManager  DefaultWebSocketManager HttpContext  DefaultHttpContext ■ ASP.NET Core’s Middleware is binding via “Microsoft.AspNetCore.Http.Features” Nuget’s code.
  • 25. Resources & Tools: ■ SourceGrpah: https://sourcegraph.com/ ■ VSCode & OmniSharp extension: https://code.visualstudio.com/Docs/languages/csharp ■ MDN: – Websocket API: https://developer.mozilla.org/en- US/docs/Web/API/Websockets_API – Writing WebSocket servers: https://developer.mozilla.org/en- US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers