Outspending
Outspending
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
ty
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
epic
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
yep, i just had to send the handshake packet before i started listening for packets
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
i'm so dumb
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
thanks for the help, its disposing cuz im closing the connection
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
it is 💀
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
one sec
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
maybe its breaking the loop...
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
wait-
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
legit very messy but i just wanna understand why its doing this
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
public class PacketListener
{
private bool _isRunning;

public PacketListener(ServerClient client)
{
_isRunning = true;

NetworkStream stream = client.Stream;
while (_isRunning)
{
byte[] buffer = new byte[1024];
int bytesRead = stream.Read(buffer, 0, buffer.Length);

if (bytesRead > 0)
{
stream.Write(buffer, 0, bytesRead);
}
else
{
break;
}
}

client.Client.Close();
Console.WriteLine("Client has disconnected.");
}

public void Stop()
{
_isRunning = false;
}
}
public class PacketListener
{
private bool _isRunning;

public PacketListener(ServerClient client)
{
_isRunning = true;

NetworkStream stream = client.Stream;
while (_isRunning)
{
byte[] buffer = new byte[1024];
int bytesRead = stream.Read(buffer, 0, buffer.Length);

if (bytesRead > 0)
{
stream.Write(buffer, 0, bytesRead);
}
else
{
break;
}
}

client.Client.Close();
Console.WriteLine("Client has disconnected.");
}

public void Stop()
{
_isRunning = false;
}
}
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
No description
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
works fine up until i try to connect aka sending the HandshakePacket
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
not sure why it ain't workin
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
i thought it was just because i was storing the TcpStream inside the class but i tried just method and idk
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
this is the class that is creating the ServerClient:
public class ServerConnection
{
private static bool _IsRunning;

private readonly TcpListener _listener;

public ServerConnection(IPAddress address, int port)
{
if (_IsRunning)
{
throw new Exception("Server is already running.");
}

_listener = new TcpListener(address, port);
_IsRunning = true;
}

public void Init()
{
try
{
_listener.Start();
Console.WriteLine("Server started. Waiting for connections...");

TcpClient client = _listener.AcceptTcpClient();
Console.WriteLine("Client connected.");

new ServerClient(client);
}
catch (Exception e)
{
Console.WriteLine("Server Error: " + e.Message);
}
}
}
public class ServerConnection
{
private static bool _IsRunning;

private readonly TcpListener _listener;

public ServerConnection(IPAddress address, int port)
{
if (_IsRunning)
{
throw new Exception("Server is already running.");
}

_listener = new TcpListener(address, port);
_IsRunning = true;
}

public void Init()
{
try
{
_listener.Start();
Console.WriteLine("Server started. Waiting for connections...");

TcpClient client = _listener.AcceptTcpClient();
Console.WriteLine("Client connected.");

new ServerClient(client);
}
catch (Exception e)
{
Console.WriteLine("Server Error: " + e.Message);
}
}
}
23 replies
CC#
Created by Outspending on 3/20/2024 in #help
TcpClient being Disposed
its erroring from
Stream.Write(packetBytes, 0, packetBytes.Length);
Stream.Write(packetBytes, 0, packetBytes.Length);
when im trying to send the handshake packet
23 replies