I am trying to creating a system that has the TCPListener running on a thread the problem is each time the thread is run it produces an error saying that the port is already being listened at, not sure how to resolve this, the code I am using for the server is:
try
{
// Step 1: create TcpListener
listener = new TcpListener( 3000 );
// Step 2: TcpListener waits for connection request
listener.Start();
// Step 3: establish connection upon client request
if (listener.Pending())
{
MessageBox.Show("Sorry, no connection requests have arrived"
}
else
{
while (Listening ==true )
{
server.Text = "Waiting for connection\r\n";
// accept an incoming connection
connection = listener.AcceptSocket();
// create NetworkStream object associated with socket
socketStream = new NetworkStream( connection );
// create objects for transferring data across stream
writer = new BinaryWriter( socketStream );
reader = new BinaryReader( socketStream );
server.Text += "Connection received.\r\n";
I error occurs with the connection = listener.AcceptSocket();
Any help with how this could be resolved would be excellent thanks
try
{
// Step 1: create TcpListener
listener = new TcpListener( 3000 );
// Step 2: TcpListener waits for connection request
listener.Start();
// Step 3: establish connection upon client request
if (listener.Pending())
{
MessageBox.Show("Sorry, no connection requests have arrived"
}
else
{
while (Listening ==true )
{
server.Text = "Waiting for connection\r\n";
// accept an incoming connection
connection = listener.AcceptSocket();
// create NetworkStream object associated with socket
socketStream = new NetworkStream( connection );
// create objects for transferring data across stream
writer = new BinaryWriter( socketStream );
reader = new BinaryReader( socketStream );
server.Text += "Connection received.\r\n";
I error occurs with the connection = listener.AcceptSocket();
Any help with how this could be resolved would be excellent thanks