C
C#9mo 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
JakenVeina9mo ago
the socket is connected in a different class
the error says otherwise the socket is not connected what is Listener?
S-IERRA
S-IERRA9mo 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
JakenVeina9mo ago
but what IS it?
S-IERRA
S-IERRA9mo 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
JakenVeina9mo ago
rubberduck
S-IERRA
S-IERRA9mo ago
@jakenveina
No description
S-IERRA
S-IERRA9mo ago
ignore the debug info and stuff
No description
S-IERRA
S-IERRA9mo 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
JakenVeina9mo ago
the actual client socket thats on the server
huh?
WEIRD FLEX
WEIRD FLEX9mo ago
are you sure you are using the correct socket? like you have .Accept() and stuff
S-IERRA
S-IERRA9mo ago
yes i do
Accord
Accord9mo 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
ihavegoodname9mo 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-IERRA9mo ago
i alr fixed the problem
ihavegoodname
ihavegoodname9mo ago
r u ever gonna release this or ni no
S-IERRA
S-IERRA9mo ago
Not going to disclose that Most likely tho
ihavegoodname
ihavegoodname9mo ago
since its not for rogue anymore
S-IERRA
S-IERRA9mo ago
What is rogue
ihavegoodname
ihavegoodname9mo ago
i dont know never heard of it
Accord
Accord9mo 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.