Skip to content

RFC - Support WebSockets with channels #66

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

Merged
merged 2 commits into from
Jan 3, 2018
Merged

RFC - Support WebSockets with channels #66

merged 2 commits into from
Jan 3, 2018

Conversation

qmfrederik
Copy link
Contributor

The port forward, attach and exec commands all return WebSockets which contain data in different channels.

This PR adds code which can take such as WebSocket and decompose (de-multiplex) it into different Streams.

A client could use this API like this:

using (WebSocket webSocket = await kubernetes.WebSocketNamespacedPodPortforwardAsync(webDriverPod.Metadata.Name, "8080", 17894, null, default(CancellationToken)).ConfigureAwait(false))
using (StreamDemuxer muxer = new StreamDemuxer(webSocket))
using (Stream stream = muxer.GetStream(0, 0))
{
    // You can read/write to the stream here to interact with the remote socket.
}

From a design point of view, the StreamDemuxer class has a ClientLoop which reads all the data of the WebSocket and stores it in individual ByteBuffers - one for each channel.

For each channel, there's a corresponding DemuxedStream which reads the bytes from the ByteBuffer class. So you get a producer-consumer implementation.

As outlined in the other issue, I'm not entirely satisfied with this implementation because of the buffering, but it may be a good first start.

Opening the PR mainly to get your feedback, let me know what you think!

@brendandburns
Copy link
Contributor

This looks like a good approach to me. In the Java implementation I used PipedInput/OutputStreams for a similar sort of feel.

@brendandburns
Copy link
Contributor

(oh and sorry for the delay in responding...)

@brendandburns
Copy link
Contributor

Though there are build errors:

Copyright (C) Microsoft Corporation. All rights reserved.

StreamDemuxer.cs(38,16): error CS0246: The type or namespace name 'Stream' could not be found (are you missing a using directive or an assembly reference?) [/home/travis/build/kubernetes-client/csharp/src/KubernetesClient.csproj]

Build FAILED.

StreamDemuxer.cs(38,16): error CS0246: The type or namespace name 'Stream' could not be found (are you missing a using directive or an assembly reference?) [/home/travis/build/kubernetes-client/csharp/src/KubernetesClient.csproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:07.65
StreamDemuxer.cs(38,16): error CS0246: The type or namespace name 'Stream' could not be found (are you missing a using directive or an assembly reference?) [/home/travis/build/kubernetes-client/csharp/src/KubernetesClient.csproj]

Build FAILED.

StreamDemuxer.cs(38,16): error CS0246: The type or namespace name 'Stream' could not be found (are you missing a using directive or an assembly reference?) [/home/travis/build/kubernetes-client/csharp/src/KubernetesClient.csproj]

    0 Warning(s)
    1 Error(s)

@qmfrederik
Copy link
Contributor Author

@brendandburns Thanks! The build issue should be fixed now.

@brendandburns
Copy link
Contributor

LGTM, merging.

@brendandburns brendandburns merged commit ff7a455 into kubernetes-client:master Jan 3, 2018
JonJam pushed a commit to JonJam/csharp that referenced this pull request Sep 8, 2018
* Add support for demuxing streams from WebSockets.

* Add missing using statement, fix unit test
k8s-ci-robot pushed a commit that referenced this pull request Dec 5, 2022
* Doc (#66)

* add doc

* ln -s md

* add pipeline

* Update docfx.yaml

* Update docfx.yaml

* Update docfx.yaml

* Update docfx.yaml

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

Successfully merging this pull request may close these issues.

2 participants