Skip to content

Socket.ConnectAsync result get the socket error "InvalidArgument" for UDP #39268

@iozcelik

Description

@iozcelik

I use .net core 3.1 and creating a worker service.

I try to implement Socket.ConnectAsync both TCP and UDP. However UDP is not working as expected.

From documentation, it will be possibble. However, I am not successed.

If you are using a connection-oriented protocol, the ConnectAsync method starts an asynchronous request for a connection to the remote host. If you are using a connectionless protocol, ConnectAsync establishes a default remote host.

My code is simple:

var socket = new Socket(Endpoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);

var _connectEventArg = new SocketAsyncEventArgs();
_connectEventArg.RemoteEndPoint = Endpoint;
_connectEventArg.Completed += OnAsyncCompleted;

socket.ConnectAsync(_connectEventArg);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions