Re: [C#]TcpClient Problem...
Quote:
Originally Posted by
xSilv3rbullet
I'm using this code:
Code:
public void startServer(MainForm main)
{
try
{
setUp(main);
listener.Start(maxConnections);
main.richTextBox1.Text += "[INFO] Server is listening on port 8680.";
while (isRunning)
{
if (listener.Pending())
{
if (connected < maxConnections)
{
accept = listener.AcceptTcpClient();
Utils.writeLine(main.richTextBox1, Utils.writeTime());
Utils.writeLine(main.richTextBox1, accept.Client.RemoteEndPoint + " is attempting to connect to the server.");
Utils.writeLine(main.richTextBox1, "Tending to the request...");
Thread newclient = new Thread(delegate() { createNewSessionThread(accept, ((IPEndPoint)accept.Client.RemoteEndPoint).Address.ToString()); });
newclient.Start();
connected++;
}
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
The first time I debugged it, i got a firewall notice that asked me if I wanted to unblock the services.
I clicked "Unblock", and now, whenever I debug, it just freezes when the startServer function is called.
Application error or firewall related?
EDIT: I just checked my firewall exceptions, and loginserver.exe and loginserver.vshost.exe are unblocked (I'm running Windows 7, and I have both Private and Public checked off.)
Step into the startServer function and see which line it's "freezing" on.
It's almost certainly an app error, and an easy way to check for future reference is to turn OFF the firewall, run it, and if it starts working magically, you know.
Re: [C#]TcpClient Problem...
Quote:
Originally Posted by
jMerliN
Step into the startServer function and see which line it's "freezing" on.
It's almost certainly an app error, and an easy way to check for future reference is to turn OFF the firewall, run it, and if it starts working magically, you know.
Thanks, I'll try that.
Is anything wrong with the current code?
Re: [C#]TcpClient Problem...
Ok, apparently, it freezes at
Code:
if (listener.Pending())
{//Freezes here
Re: [C#]TcpClient Problem...
Quote:
Originally Posted by
xSilv3rbullet
Ok, apparently, it freezes at
Code:
if (listener.Pending())
{//Freezes here
I don't know what 'listener' is, you haven't provided enough code to be useful.
Re: [C#]TcpClient Problem...
Solved.
I created a thread and it works like a charm now. :D
Re: [C#]TcpClient Problem...
This is why you should use the Socket class, because TcpClient is synchronous and Socket is both asynchronous and synchronous.