C
C#15mo 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);
}
}
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);
}
}
20 Replies
JakenVeina
JakenVeina15mo ago
the socket is connected in a different class
the error says otherwise the socket is not connected what is Listener?
S-IERRA
S-IERRAOP15mo ago
Listener is the main socket listening to all connections Similar to TCP Listener also as far as I can tell the connection stays alive other wise I'd be getting an error let me check tho
JakenVeina
JakenVeina15mo ago
but what IS it?
S-IERRA
S-IERRAOP15mo ago
Acts as a server OH EWAIT Im sorry i'm tired as fuck
public static readonly Socket Listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
public static readonly Socket Listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
JakenVeina
JakenVeina15mo ago
rubberduck
S-IERRA
S-IERRAOP15mo ago
@jakenveina
No description
S-IERRA
S-IERRAOP15mo ago
ignore the debug info and stuff
No description
S-IERRA
S-IERRAOP15mo ago
but its connected just the way i send it isnt thru the Socket class its thru the server -> Ip Endpoint i could make it send via the actual client socket thats on the server just would be alot more annoying because i would have to redesign alot of stuff Tho I assume I can't just send out data from the server when the 2 sockets arent connected (even tho they are but the way im sending isnt connected ig)
JakenVeina
JakenVeina15mo ago
the actual client socket thats on the server
huh?
Omnissiah
Omnissiah15mo ago
are you sure you are using the correct socket? like you have .Accept() and stuff
S-IERRA
S-IERRAOP15mo ago
yes i do
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
ihavegoodname
ihavegoodname14mo ago
This is inspirational iskra Can you provide all of your code so we can help you mroe? Project file would be fine
S-IERRA
S-IERRAOP14mo ago
i alr fixed the problem
ihavegoodname
ihavegoodname14mo ago
r u ever gonna release this or ni no
S-IERRA
S-IERRAOP14mo ago
Not going to disclose that Most likely tho
ihavegoodname
ihavegoodname14mo ago
since its not for rogue anymore
S-IERRA
S-IERRAOP14mo ago
What is rogue
ihavegoodname
ihavegoodname14mo ago
i dont know never heard of it
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server