-
December 15th, 2011, 02:23 AM
#1
TcpListener not accepting clients
I'll keep it short and simple. Take a look at my source.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
namespace EDOLOGGER_SERVER
{
public partial class Form1 : Form
{
TcpListener server;
int port = 8888;
IPAddress IP = IPAddress.Parse("192.168.1.114");
string n = Environment.NewLine;
public void start()
{
try
{
textBox1.Text += "in start()" + n;
server = new TcpListener(IP, port);
server.Start();
}
catch (System.Exception e)
{
textBox1.Text += "EXCEPTION: " + e + n;
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text += "Before start()" + n;
start();
textBox1.Text += "After start()" + n;
while (server.Pending() == true)
{
try
{
textBox1.Text += "Listening for request on " + IP + ":" + port;
TcpClient client = server.AcceptTcpClient();
textBox1.Text += "Connection accepted" + n;
}
catch (System.Exception ex)
{
textBox1.Text += ex + n;
}
}
}
}
}
The following code never runs (under "while (server.Pending == true)"):
"Listening for request on " + IP + ":" + port;
"Connection accepted" + n;
My best guess is that I'm using server.Pending incorrectly, but don't know how to correct that. Thanks in advance
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|