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

WebSocket ability to force IPv6 or IPv4 #45462

Open
xinbingyiran opened this issue Dec 2, 2020 · 14 comments
Open

WebSocket ability to force IPv6 or IPv4 #45462

xinbingyiran opened this issue Dec 2, 2020 · 14 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Net
Milestone

Comments

@xinbingyiran
Copy link

xinbingyiran commented Dec 2, 2020

UPDATE: Scoped to WebSocket only as there is no way to achieve that.
HttpClient has a way and HttpWebRequest is legacy API (so no need).


I find the sulution for httpclient from issues like this.

var handler = new SocketsHttpHandler{
   ConnectCallback = async (context,token)=>{
      // dns get ipv6 and connect
      return ipv6stream
   }
};
var client = new HttpClient(handler);// HttpClientHandle???

but it can useful for httpclient only,and it replaced httpclienthandle,will lost the diagnosticsHandler yet.

and I view the httpwebrequest and websocket source code, the SocketsHttpHandler is a private member of them only,and i can't get the ConnectCallback for using.

so how can i force ipv6 or ipv4 on httpwebrequest, websocket and httpclient(with diagnosticsHandler )

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Net untriaged New issue has not been triaged by the area owner labels Dec 2, 2020
@ghost
Copy link

ghost commented Dec 2, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

I find the sulution for httpclient from issues like this.

var handler = new SocketsHttpHandler{
   ConnectCallback = async (context,token)=>{
      // dns get ipv6 and connect
      return ipv6stream
   }
};
var client = new HttpClient(handler);// HttpClientHandle???

but it can useful for httpclient only,and it replaced httpclienthandle,will lost the diagnosticsHandler yet.

and I view the httpwebrequest and websocket source code, the SocketsHttpHandler is a private member of them only,and i can't get the ConnectCallback for using.

so how can i force ipv6 or ipv4 on httpwebrequest, websocket and httpclient(with diagnosticsHandler )

Author: xinbingyiran
Assignees: -
Labels:

area-System.Net, untriaged

Milestone: -

@scalablecory
Copy link
Contributor

There's no way to do this with HttpWebRequest or WebSocket.
The former is obsolete and not being invested in. We could consider an API for WebSocket, though.

Not being able to use DiagnosticsHandler with SocketsHttpHandler is a known wart -- tracking that at #31261

@xinbingyiran
Copy link
Author

Except DiagnosticsHandler,for replace the HttpWebRequest,I can use HttpClient via ConnectCallback to implement a ipv6 web request , I'm really looking forward to a similar API for 'WebSocket' as well.

@scalablecory
Copy link
Contributor

Except DiagnosticsHandler,for replace the HttpWebRequest,I can use HttpClient via ConnectCallback to implement a ipv6 web request , I'm really looking forward to a similar API for 'WebSocket' as well.

Actually, you can use WebSocket.CreateFromStream here, so I don't think any new API is needed.

@xinbingyiran
Copy link
Author

Except DiagnosticsHandler,for replace the HttpWebRequest,I can use HttpClient via ConnectCallback to implement a ipv6 web request , I'm really looking forward to a similar API for 'WebSocket' as well.

Actually, you can use WebSocket.CreateFromStream here, so I don't think any new API is needed.

If I use WebSocket.CreateFromStream,it means i must copy all code of 'WebSocketHandle.ConnectAsync',and add 'ConnectCallback' to 'SocketsHttpHandler',to completed the websocket protocol upgrade manual,just for use ConnectCallback
only.
does it has a simple implement such as add the 'SocketsHttpHandler' or 'ConnectCallback' member to 'ClientWebSocketOptions'.

@karelz karelz changed the title when i use tcp connection via httpwebrequest, websocket and httpclient,how can i force ipv6 or ipv4 When I use TCP connection via HttpWebRequest, WebSocket and HttpClient, how can I force IPv6 or IPv4 Dec 8, 2020
@karelz karelz added question Answer questions and provide assistance, not an issue with source code or documentation. and removed untriaged New issue has not been triaged by the area owner labels Dec 8, 2020
@karelz
Copy link
Member

karelz commented Dec 8, 2020

Triage: @xinbingyiran how much code is that? Is that inconveniently long code?

@karelz karelz added the untriaged New issue has not been triaged by the area owner label Dec 8, 2020
@xinbingyiran
Copy link
Author

Triage: @xinbingyiran how much code is that? Is that inconveniently long code?

Yes, It's not,but...
At present,if a developer need to switch a option for using ipv4 or ipv6,he must view the source code of runtime, to find the logic of connection(it may be a long time),and then copy all of them to his own code and change it carefully.
Only for using ipv6 or ConnectCallback of SocketsHttpHandler.do you think it's a better way than to offer an option?
And there is a SocketsHttpHandler for using in ClientWebSocketOptions,why not try exposing it or its callback method to the developer?

@wfurt
Copy link
Member

wfurt commented Dec 9, 2020

In general case, this should not be needed, right @xinbingyiran? If the service is not IPv6 capable, it should not be in DNS in first place. If IPv6 is not available on the client it should fall-back to IPv4. The ConnectCallback was added primarily for use-cases other than this.
While WebSocket may be interesting , HttpWebRequest is viewed as obsolete and it will be official marked as such soon.

@xinbingyiran
Copy link
Author

xinbingyiran commented Dec 9, 2020

What if I need to connect to a 'WebSocket' server that supports both IPv4 and IPv6(e.g. ws://localhost/) over the IPv4 protocol? Just like I need to make an IPv4 Web request, @wfurt .

Since HTTP is supported, how about WebSocket?

@wfurt
Copy link
Member

wfurt commented Dec 9, 2020

In that case, both address families should be fully interchangeable, right @xinbingyiran?
I'm not trying to say there is never reason - but most changes are driven by impact and that seems be bigger for HttpClient/SocketsHttpHandler.do as more commonly used.
Even with that, the work is not quite completed and I expect improvements for .NET 6.
WebSocket may see changes when everything is stable and proven to work well if there is broader need.

@xinbingyiran
Copy link
Author

Well, hopefully the next version of WebSocket will do that, since it will have to build HTTP first (which can be switched now) after all.

@karelz karelz changed the title When I use TCP connection via HttpWebRequest, WebSocket and HttpClient, how can I force IPv6 or IPv4 WebSocket ability to force IPv6 or IPv4 Dec 17, 2020
@karelz
Copy link
Member

karelz commented Dec 17, 2020

Triage: Issue scoped to just WebSocket. Top post updated.

@karelz karelz added api-approved API was approved in API review, it can be implemented api-suggestion Early API idea and discussion, it is NOT ready for implementation and removed question Answer questions and provide assistance, not an issue with source code or documentation. untriaged New issue has not been triaged by the area owner api-approved API was approved in API review, it can be implemented labels Dec 17, 2020
@karelz karelz added this to the Future milestone Dec 17, 2020
@antonfirsov
Copy link
Member

@xinbingyiran I'm wondering if you can elaborate a bit on your use-case.

In #47583 we are proposing a switch to globally disable IPv6, is this something you would find useful?

@geoffkizer
Copy link
Contributor

At some point we had discussed allowing you to specify and configure the instance of SocketsHttpHandler that is used by the WebSocket. Seems like that would allow you to address this scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Net
Projects
None yet
Development

No branches or pull requests

7 participants