C#C
C#3y ago
S-IERRA

❔ Sockets, SendTo is erroring

A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied.

With my setup, the socket is connected in a different class but I am trying to send a message to that socket via its endpoint where I get an error, is that possible or do I have to use the socket class its self?

    public static async Task SendToEndPointAsync(IPEndPoint target, WebSocketOpcodes webSocketOpCode, WebSocketEvents? eventType = null, string? dataSerialized = null)
    {
        try
        {
            var socketMessage = new WebSocketMessage(webSocketOpCode, dataSerialized, eventType, null);

            string messageSerialized = JsonSerializer.Serialize(socketMessage);

            byte[] dataCompressed = Encoding.UTF8.GetBytes(messageSerialized); /

            await Listener.SendToAsync(dataCompressed, SocketFlags.None, target);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }
Was this page helpful?