C
C#2y 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
JakenVeina2y ago
the socket is connected in a different class
the error says otherwise the socket is not connected what is Listener?
S-IERRA
S-IERRAOP2y 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
JakenVeina2y ago
but what IS it?
S-IERRA
S-IERRAOP2y 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
JakenVeina2y ago
rubberduck
S-IERRA
S-IERRAOP2y ago
@jakenveina
No description
S-IERRA
S-IERRAOP2y ago
ignore the debug info and stuff
No description
S-IERRA
S-IERRAOP2y 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
JakenVeina2y ago
the actual client socket thats on the server
huh?
Ꜳåąɐȁặⱥᴀᴬ
are you sure you are using the correct socket? like you have .Accept() and stuff
S-IERRA
S-IERRAOP2y ago
yes i do
Accord
Accord2y 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
ihavegoodname2y 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-IERRAOP2y ago
i alr fixed the problem
ihavegoodname
ihavegoodname2y ago
r u ever gonna release this or ni no
S-IERRA
S-IERRAOP2y ago
Not going to disclose that Most likely tho
ihavegoodname
ihavegoodname2y ago
since its not for rogue anymore
S-IERRA
S-IERRAOP2y ago
What is rogue
ihavegoodname
ihavegoodname2y ago
i dont know never heard of it
Accord
Accord2y 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.

Did you find this page helpful?