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

TcpListener.LocalEndPoint property should really be IPEndPoint, not EndPoint #63117

Closed
geoffkizer opened this issue Dec 24, 2021 · 3 comments
Closed
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Net.Sockets
Milestone

Comments

@geoffkizer
Copy link
Contributor

Since TcpListener is specific to TCP, the LocalEndPoint is always an IPEndPoint, yet it's typed as EndPoint. This means users of this property need to downcast to IPEndPoint to access the actual IPAddress and Port.

We should consider adding new API here so that it's obvious that this can only be an IPEndPoint, and users don't have to do the downcast themselves.

We could simply add a new property like "LocalIPEndPoint", or perhaps "ListenEndPoint" -- I like the latter personally, it calls out that this is different than the typical Local/RemoteEndPoint semantics for connected sockets.

Or we could choose to avoid EndPoint/IPEndPoint entirely and expose the IPAddress and Port as separate properties, something like "ListenIPAddress" and "ListenPort".

@geoffkizer geoffkizer added api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Net.Sockets labels Dec 24, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Dec 24, 2021
@ghost
Copy link

ghost commented Dec 24, 2021

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

Issue Details

Since TcpListener is specific to TCP, the LocalEndPoint is always an IPEndPoint, yet it's typed as EndPoint. This means users of this property need to downcast to IPEndPoint to access the actual IPAddress and Port.

We should consider adding new API here so that it's obvious that this can only be an IPEndPoint, and users don't have to do the downcast themselves.

We could simply add a new property like "LocalIPEndPoint", or perhaps "ListenEndPoint" -- I like the latter personally, it calls out that this is different than the typical Local/RemoteEndPoint semantics for connected sockets.

Or we could choose to avoid EndPoint/IPEndPoint entirely and expose the IPAddress and Port as separate properties, something like "ListenIPAddress" and "ListenPort".

Author: geoffkizer
Assignees: -
Labels:

api-suggestion, area-System.Net.Sockets

Milestone: -

@karelz
Copy link
Member

karelz commented Jan 6, 2022

Triage: Changing the return type would be binary breaking change.
Note TcpListener is not sealed and the property is not virtual.

We should add the new API LocalIPEndPoint, then obsolete and hide from editor the old API.
It would bring small value to customer, not a high pri.

It may make more sense to prioritize it in the context of #63162.

@karelz karelz removed the untriaged New issue has not been triaged by the area owner label Jan 6, 2022
@karelz karelz added this to the Future milestone Jan 6, 2022
@wfurt
Copy link
Member

wfurt commented Jan 25, 2023

triage: we should keep it as it is to prevent breaking change and favor #63162 instead to come up with something more complete and usable.

@wfurt wfurt closed this as completed Jan 25, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 24, 2023
@karelz karelz modified the milestones: Future, 8.0.0 Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Net.Sockets
Projects
None yet
Development

No branches or pull requests

3 participants