TCP Listen port with multiple connections

G

Guest

Hello everyone,


I have this code for TCPListenPort. The code works fine, but my manager is
asking me to establish multiple connections to the same port. How can i
acheive that

below is my code

Int32 port = Int32.Parse(ConfigurationManager.AppSettings["port"]);

IPAddress localAddr =
IPAddress.Parse(ConfigurationManager.AppSettings["IpAddress"]);
TcpListener server = new TcpListener(localAddr, port);
server.Start();
Byte[] bytes = new Byte[256];
String data = null;

// Enter the listening loop.


while (true)
{
// Perform a blocking call to accept requests.
TcpClient client = server.AcceptTcpClient();
remotePoint = client.Client.RemoteEndPoint.ToString();
data = null;
NetworkStream stream = client.GetStream();
int i;

// Loop to receive all the data sent by the clie nt.
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
// Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes,
0, i);
// Process the data sent by the client.
data = data.ToUpper();


byte[] msg =
System.Text.Encoding.ASCII.GetBytes(data);
if (msg.Length > 5)
{

byte[] msgClone =
writeClassLibrary.getReturnBytes.ReturnData(_sessionDisplay, msg);
stream.Write(msgClone, 0, msgClone.Length);
}

}
// Shutdown and end connection
client.Close();


}
 
P

Peter Duniho

Vinki said:
I have this code for TCPListenPort. The code works fine, but my manager is
asking me to establish multiple connections to the same port. How can i
acheive that

IMHO, the most straightforward way would be to use the async methods for
the TcpClient, so that you don't have to do the processing in the loop.
It's that processing that prevents you from dealing with a new client
until you're completely done with the current one.

If you wanted to make the code really nice, you could make the
TcpListener use the async methods as well. Then none of this code would
have to exist in a specific thread.

Pete
 
G

Guest

Hi Peter,

Do you have any example for this to do both TCListener and IO stream part.
I will really appreacite if you can email me or paste an example.

Thanks.
email: (e-mail address removed)
 
G

Guest

I wrote this after following that microsoft code. This complies succesfully.
I was wondering where in this code will I get the data coming from client. In
my earlier code, I had this

data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);

below is the new code

private void Form1_Load(object sender, EventArgs e)
{
Int32 port = 9007;
IPAddress localAddr = IPAddress.Parse(IPAddress);
TcpListener server = null;
server = new TcpListener(localAddr, port);
server.Start();
DoBeginAcceptSocket(server);
}

// Thread signal.
public static ManualResetEvent clientConnected =
new ManualResetEvent(false);

// Accept one client connection asynchronously.
public static void DoBeginAcceptSocket(TcpListener listener)
{
// Set the event to nonsignaled state.
clientConnected.Reset();

// Start to listen for connections from a client.
Console.WriteLine("Waiting for a connection...");

// Accept the connection.
// BeginAcceptSocket() creates the accepted socket.
listener.BeginAcceptSocket(
new AsyncCallback(DoAcceptSocketCallback), listener);
// Wait until a connection is made and processed before
// continuing.
clientConnected.WaitOne();
}

// Process the client connection.
public static void DoAcceptSocketCallback(IAsyncResult ar)
{
// Get the listener that handles the client request.
TcpListener listener = (TcpListener)ar.AsyncState;

// End the operation and display the received data on the
//console.
Socket clientSocket = listener.EndAcceptSocket(ar);

// Process the connection here. (Add the client to a
// server table, read data, etc.)
Console.WriteLine("Client connected completed");

// Signal the calling thread to continue.
clientConnected.Set();
}
}
 
P

Peter Duniho

Vinki said:
I wrote this after following that microsoft code. This complies succesfully.
I was wondering where in this code will I get the data coming from client.

In your DoAcceptSocketCallback() method, you would get the Stream from
the TcpClient and use the Stream.BeginRead() method on that. Then in
the callback for that, you'll do the Encoder.GetString() from the bytes
that are received.

Personally, I would use TcpListener.BeginAcceptTcpClient() instead of
BeginAcceptSocket(), since your original code was based on the TcpClient
rather than the Socket.

If you do plan on using the Socket, I would not bother using TcpListener
and TcpClient at all; the Socket API isn't actually all that complicated
and if that's what you're going to use for i/o in the end anyway, you
might as well only use that class. But IMHO your previous code using
TcpClient should be fine, and there's nothing wrong with sticking with that.

Pete
 
G

Guest

Hi Peter,

I want to stick with that code too, but I don't know how to use async
method for TCPClient. I tried to follow the link that you pasted here, but I
couldn't understand how to integrate that code with my code . I would
appreacite if you have some code written like this that uses async IO stream
and TCP Listener. I will follow that code.

Thanks.
 
G

Guest

Hi Peter,

I think you posted something, but I cannot see any message. It mentions
your name at the bottom of all the message, but I cannot see the message
itself.
 
P

Peter Duniho

Vinki said:
Hi Peter,

I think you posted something, but I cannot see any message. It mentions
your name at the bottom of all the message, but I cannot see the message
itself.

Well, as a start you may want to consider using a real newsreader to
access this newsgroup, rather than going through Microsoft's web
interface. I've never actually had problems with it myself, but it's
not hard to imagine it screwing up now and then and not displaying posts
correct.

That said, I didn't post any code (yet). I will type in something quick
and dirty, in reply to your other message. Sorry I don't have time for
anything more elaborate at the moment.

Pete
 
P

Peter Duniho

Vinki said:
Hi Peter,

I want to stick with that code too, but I don't know how to use async
method for TCPClient. I tried to follow the link that you pasted here, but I
couldn't understand how to integrate that code with my code . I would
appreacite if you have some code written like this that uses async IO stream
and TCP Listener. I will follow that code.

Here is the basic idea. I make no promises as to whether it actually
even compiles, never mind works, and I'm not going to bother putting in
any error checking/catching. But it should be enough to give you the
general idea.

By the way, I was looking at the docs for the NetworkStream.EndRead()
method, and the sample code there is awful (I'm not even convinced it
works). I haven't looked closely at the other stuff, but based on what
I did see I'd say definitely take their sample code with a grain of
salt. The sample code they have for the Socket class is much better;
the async methods aren't exactly the same, but they are similar enough
that the Socket sample code is still a pretty good place to look for
guidance as to general structure of the code.

Now, on to my sample code (which you should also take with a grain of
salt, but which I hope is better than MSDN's :) ):

class ClientState
{
public TcpClient client;
public byte[] buffer;
}

private void Form1_Load(object sender, EventArgs e)
{
Int32 port = 9007;
IPAddress localAddr = IPAddress.Parse(IPAddress);
TcpListener server = new TcpListener(localAddr, port);
server.Start();

// The above is pretty much what you had, cleaned up
// a bit. All you have to do at this point is start
// an accept operation:

server.BeginAcceptTcpClient(AcceptCallback, server);
}

private void AcceptCallback(IAsyncResult ar)
{
TcpListener server = (TcpListener)ar.AsyncState;
ClientState state = new ClientState();

// Once the accept operation completes, this callback will
// be called. In it, you can create a new TcpClient in much
// the same way you did it in the synchronous code you had:

state.client = server.EndAcceptTcpClient(ar);

// We're going to start reading from the client's stream, and
// we need a buffer for that:

state.buffer = new byte[4096];

// Note that the TcpClient and the byte[] are both put into
// this "ClientState" object. We're going to need an easy
// way to get at those values in the callback for the read
// operation.

// Next, start a new accept operation so that we can process
// another client connection:

server.BeginAcceptTcpClient(AcceptCallback, server);

// Finally, start a read operation on the client we just
// accepted. Note that you could do this before starting the
// accept operation; the order isn't really important.

state.client.GetStream().BeginRead(state.buffer, 0,
state.buffer.Length, ReadCallback, state);
}

private void ReadCallback(IAsyncResult ar)
{
ClientState state = (ClientState)ar.AsyncState;
int cbRead = state.client.GetStream().EndRead(ar);

if (cbRead == 0)
{
// The client has closed the connection
return;
}

// Your data is in state.buffer, and there are cbRead
// bytes to process in the buffer. This number may be
// anywhere from 1 up to the length of the buffer.
// The i/o completes when there is _any_ data to be read,
// not necessarily when the buffer is full.

// So, for example:

string strData = Encoding.ASCII.GetString(state.buffer, 0, cbRead);

// For ASCII you won't have to worry about partial characters
// but for pretty much any other common encoding you'll have to
// deal with that possibility, as there's no guarantee that an
// entire character will be transmitted in one piece.

// Of course, even with ASCII, you need to watch your string
// terminations. You'll have to either check the read buffer
// directly for a null terminator, or have some other means
// of detecting the actual end of a string. By the time the
// string goes through the decoding process, you'll have lost
// that information.

// As with the accept operation, we need to start a new read
// operation on this client, so that we can process the next
// bit of data that's sent:

state.client.GetStream().BeginRead(state.buffer, 0,
state.buffer.Length, ReadCallback, state);
}
 
G

Guest

Hi Peter,

Thanks for writing a sample code. I did exactly you mentioned. Below is
the code. I guess I am doing something wrong. The code terminates at this
point

server.BeginAcceptTcpClient(AcceptCallback, server);

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Net.Sockets;
using System.Net;
namespace asyncStream
{
class ClientState
{
public TcpClient client;
public byte[] buffer;
}
class Program
{
static void Main(string[] args)
{
Int32 port = 9887;
IPAddress localAddr = IPAddress.Parse("10.210.244.174");
TcpListener server = new TcpListener(localAddr, port);
server.Start();
// code terminates here
server.BeginAcceptTcpClient(AcceptCallback, server);
}

private static void AcceptCallback(IAsyncResult ar)
{
TcpListener server = (TcpListener)ar.AsyncState;
ClientState state = new ClientState();
TcpClient client = server.AcceptTcpClient();
state.client = server.EndAcceptTcpClient(ar);
state.buffer = new byte[4096];
server.BeginAcceptTcpClient(AcceptCallback, server);

state.client.GetStream().BeginRead(state.buffer, 0,
state.buffer.Length, ReadCallback, state);

}
private static void ReadCallback(IAsyncResult ar)
{
ClientState state = (ClientState)ar.AsyncState;
int cbRead = state.client.GetStream().EndRead(ar);

if (cbRead == 0)
{
// The client has closed the connection
return;
}
else
{
state.client.GetStream().BeginRead(state.buffer,
0,state.buffer.Length, ReadCallback, state);

}
}
}
}



Peter Duniho said:
Vinki said:
Hi Peter,

I want to stick with that code too, but I don't know how to use async
method for TCPClient. I tried to follow the link that you pasted here, but I
couldn't understand how to integrate that code with my code . I would
appreacite if you have some code written like this that uses async IO stream
and TCP Listener. I will follow that code.

Here is the basic idea. I make no promises as to whether it actually
even compiles, never mind works, and I'm not going to bother putting in
any error checking/catching. But it should be enough to give you the
general idea.

By the way, I was looking at the docs for the NetworkStream.EndRead()
method, and the sample code there is awful (I'm not even convinced it
works). I haven't looked closely at the other stuff, but based on what
I did see I'd say definitely take their sample code with a grain of
salt. The sample code they have for the Socket class is much better;
the async methods aren't exactly the same, but they are similar enough
that the Socket sample code is still a pretty good place to look for
guidance as to general structure of the code.

Now, on to my sample code (which you should also take with a grain of
salt, but which I hope is better than MSDN's :) ):

class ClientState
{
public TcpClient client;
public byte[] buffer;
}

private void Form1_Load(object sender, EventArgs e)
{
Int32 port = 9007;
IPAddress localAddr = IPAddress.Parse(IPAddress);
TcpListener server = new TcpListener(localAddr, port);
server.Start();

// The above is pretty much what you had, cleaned up
// a bit. All you have to do at this point is start
// an accept operation:

server.BeginAcceptTcpClient(AcceptCallback, server);
}

private void AcceptCallback(IAsyncResult ar)
{
TcpListener server = (TcpListener)ar.AsyncState;
ClientState state = new ClientState();

// Once the accept operation completes, this callback will
// be called. In it, you can create a new TcpClient in much
// the same way you did it in the synchronous code you had:

state.client = server.EndAcceptTcpClient(ar);

// We're going to start reading from the client's stream, and
// we need a buffer for that:

state.buffer = new byte[4096];

// Note that the TcpClient and the byte[] are both put into
// this "ClientState" object. We're going to need an easy
// way to get at those values in the callback for the read
// operation.

// Next, start a new accept operation so that we can process
// another client connection:

server.BeginAcceptTcpClient(AcceptCallback, server);

// Finally, start a read operation on the client we just
// accepted. Note that you could do this before starting the
// accept operation; the order isn't really important.

state.client.GetStream().BeginRead(state.buffer, 0,
state.buffer.Length, ReadCallback, state);
}

private void ReadCallback(IAsyncResult ar)
{
ClientState state = (ClientState)ar.AsyncState;
int cbRead = state.client.GetStream().EndRead(ar);

if (cbRead == 0)
{
// The client has closed the connection
return;
}

// Your data is in state.buffer, and there are cbRead
// bytes to process in the buffer. This number may be
// anywhere from 1 up to the length of the buffer.
// The i/o completes when there is _any_ data to be read,
// not necessarily when the buffer is full.

// So, for example:

string strData = Encoding.ASCII.GetString(state.buffer, 0, cbRead);

// For ASCII you won't have to worry about partial characters
// but for pretty much any other common encoding you'll have to
// deal with that possibility, as there's no guarantee that an
// entire character will be transmitted in one piece.

// Of course, even with ASCII, you need to watch your string
// terminations. You'll have to either check the read buffer
// directly for a null terminator, or have some other means
// of detecting the actual end of a string. By the time the
// string goes through the decoding process, you'll have lost
// that information.

// As with the accept operation, we need to start a new read
// operation on this client, so that we can process the next
// bit of data that's sent:

state.client.GetStream().BeginRead(state.buffer, 0,
state.buffer.Length, ReadCallback, state);
}
 
G

Guest

Hi Peter,

My old program keeps running and whenever any bytes come in it stops right
there. The new program that you helped me to write terminates after
server.BeginAcceptTcpClient(AcceptCallback, server);

Please let me know if I am doing anything wrong.

Thanks.

Peter Duniho said:
Vinki said:
Hi Peter,

I want to stick with that code too, but I don't know how to use async
method for TCPClient. I tried to follow the link that you pasted here, but I
couldn't understand how to integrate that code with my code . I would
appreacite if you have some code written like this that uses async IO stream
and TCP Listener. I will follow that code.

Here is the basic idea. I make no promises as to whether it actually
even compiles, never mind works, and I'm not going to bother putting in
any error checking/catching. But it should be enough to give you the
general idea.

By the way, I was looking at the docs for the NetworkStream.EndRead()
method, and the sample code there is awful (I'm not even convinced it
works). I haven't looked closely at the other stuff, but based on what
I did see I'd say definitely take their sample code with a grain of
salt. The sample code they have for the Socket class is much better;
the async methods aren't exactly the same, but they are similar enough
that the Socket sample code is still a pretty good place to look for
guidance as to general structure of the code.

Now, on to my sample code (which you should also take with a grain of
salt, but which I hope is better than MSDN's :) ):

class ClientState
{
public TcpClient client;
public byte[] buffer;
}

private void Form1_Load(object sender, EventArgs e)
{
Int32 port = 9007;
IPAddress localAddr = IPAddress.Parse(IPAddress);
TcpListener server = new TcpListener(localAddr, port);
server.Start();

// The above is pretty much what you had, cleaned up
// a bit. All you have to do at this point is start
// an accept operation:

server.BeginAcceptTcpClient(AcceptCallback, server);
}

private void AcceptCallback(IAsyncResult ar)
{
TcpListener server = (TcpListener)ar.AsyncState;
ClientState state = new ClientState();

// Once the accept operation completes, this callback will
// be called. In it, you can create a new TcpClient in much
// the same way you did it in the synchronous code you had:

state.client = server.EndAcceptTcpClient(ar);

// We're going to start reading from the client's stream, and
// we need a buffer for that:

state.buffer = new byte[4096];

// Note that the TcpClient and the byte[] are both put into
// this "ClientState" object. We're going to need an easy
// way to get at those values in the callback for the read
// operation.

// Next, start a new accept operation so that we can process
// another client connection:

server.BeginAcceptTcpClient(AcceptCallback, server);

// Finally, start a read operation on the client we just
// accepted. Note that you could do this before starting the
// accept operation; the order isn't really important.

state.client.GetStream().BeginRead(state.buffer, 0,
state.buffer.Length, ReadCallback, state);
}

private void ReadCallback(IAsyncResult ar)
{
ClientState state = (ClientState)ar.AsyncState;
int cbRead = state.client.GetStream().EndRead(ar);

if (cbRead == 0)
{
// The client has closed the connection
return;
}

// Your data is in state.buffer, and there are cbRead
// bytes to process in the buffer. This number may be
// anywhere from 1 up to the length of the buffer.
// The i/o completes when there is _any_ data to be read,
// not necessarily when the buffer is full.

// So, for example:

string strData = Encoding.ASCII.GetString(state.buffer, 0, cbRead);

// For ASCII you won't have to worry about partial characters
// but for pretty much any other common encoding you'll have to
// deal with that possibility, as there's no guarantee that an
// entire character will be transmitted in one piece.

// Of course, even with ASCII, you need to watch your string
// terminations. You'll have to either check the read buffer
// directly for a null terminator, or have some other means
// of detecting the actual end of a string. By the time the
// string goes through the decoding process, you'll have lost
// that information.

// As with the accept operation, we need to start a new read
// operation on this client, so that we can process the next
// bit of data that's sent:

state.client.GetStream().BeginRead(state.buffer, 0,
state.buffer.Length, ReadCallback, state);
}
 
G

Guest

Hi Peter,

My old program keeps running and whenever any bytes come in it stops right
there so that I can process those bytes. The new program that you helped me
to write terminates after
server.BeginAcceptTcpClient(AcceptCallback, server);
I want it to keep running so that I can see the heart beats and also any
incoming bytes that I need to process.

Please let me know if I am doing anything wrong.

Thanks.

Peter Duniho said:
Vinki said:
Hi Peter,

I want to stick with that code too, but I don't know how to use async
method for TCPClient. I tried to follow the link that you pasted here, but I
couldn't understand how to integrate that code with my code . I would
appreacite if you have some code written like this that uses async IO stream
and TCP Listener. I will follow that code.

Here is the basic idea. I make no promises as to whether it actually
even compiles, never mind works, and I'm not going to bother putting in
any error checking/catching. But it should be enough to give you the
general idea.

By the way, I was looking at the docs for the NetworkStream.EndRead()
method, and the sample code there is awful (I'm not even convinced it
works). I haven't looked closely at the other stuff, but based on what
I did see I'd say definitely take their sample code with a grain of
salt. The sample code they have for the Socket class is much better;
the async methods aren't exactly the same, but they are similar enough
that the Socket sample code is still a pretty good place to look for
guidance as to general structure of the code.

Now, on to my sample code (which you should also take with a grain of
salt, but which I hope is better than MSDN's :) ):

class ClientState
{
public TcpClient client;
public byte[] buffer;
}

private void Form1_Load(object sender, EventArgs e)
{
Int32 port = 9007;
IPAddress localAddr = IPAddress.Parse(IPAddress);
TcpListener server = new TcpListener(localAddr, port);
server.Start();

// The above is pretty much what you had, cleaned up
// a bit. All you have to do at this point is start
// an accept operation:

server.BeginAcceptTcpClient(AcceptCallback, server);
}

private void AcceptCallback(IAsyncResult ar)
{
TcpListener server = (TcpListener)ar.AsyncState;
ClientState state = new ClientState();

// Once the accept operation completes, this callback will
// be called. In it, you can create a new TcpClient in much
// the same way you did it in the synchronous code you had:

state.client = server.EndAcceptTcpClient(ar);

// We're going to start reading from the client's stream, and
// we need a buffer for that:

state.buffer = new byte[4096];

// Note that the TcpClient and the byte[] are both put into
// this "ClientState" object. We're going to need an easy
// way to get at those values in the callback for the read
// operation.

// Next, start a new accept operation so that we can process
// another client connection:

server.BeginAcceptTcpClient(AcceptCallback, server);

// Finally, start a read operation on the client we just
// accepted. Note that you could do this before starting the
// accept operation; the order isn't really important.

state.client.GetStream().BeginRead(state.buffer, 0,
state.buffer.Length, ReadCallback, state);
}

private void ReadCallback(IAsyncResult ar)
{
ClientState state = (ClientState)ar.AsyncState;
int cbRead = state.client.GetStream().EndRead(ar);

if (cbRead == 0)
{
// The client has closed the connection
return;
}

// Your data is in state.buffer, and there are cbRead
// bytes to process in the buffer. This number may be
// anywhere from 1 up to the length of the buffer.
// The i/o completes when there is _any_ data to be read,
// not necessarily when the buffer is full.

// So, for example:

string strData = Encoding.ASCII.GetString(state.buffer, 0, cbRead);

// For ASCII you won't have to worry about partial characters
// but for pretty much any other common encoding you'll have to
// deal with that possibility, as there's no guarantee that an
// entire character will be transmitted in one piece.

// Of course, even with ASCII, you need to watch your string
// terminations. You'll have to either check the read buffer
// directly for a null terminator, or have some other means
// of detecting the actual end of a string. By the time the
// string goes through the decoding process, you'll have lost
// that information.

// As with the accept operation, we need to start a new read
// operation on this client, so that we can process the next
// bit of data that's sent:

state.client.GetStream().BeginRead(state.buffer, 0,
state.buffer.Length, ReadCallback, state);
}
 
P

Peter Duniho

Vinki said:
Hi Peter,

Thanks for writing a sample code. I did exactly you mentioned. Below is
the code. I guess I am doing something wrong. The code terminates at this
point

server.BeginAcceptTcpClient(AcceptCallback, server);

Yes, of course it does. You don't have anything to prevent it from
exiting the Main() method, which is what defines exiting a console
application.

Note that the code you posted previously specified that you were
starting the server in a form's Load event handler. Had you used my
code in that context, there wouldn't be a problem.

If you want to do a console application, you'll need to make the Main()
method wait until it's time to exit. How you will define that, I don't
know. It's up to you. One possibility would be to have a WaitHandle
that the Main() method waits on. Then your application would take input
from somewhere else (maybe from one of the client's connected to it, by
having the client send a special command, but there are lots of other
alternatives), and when that input indicated the application should
exit, it could set the WaitHandle.

That's the simple description. In reality, when it's time to shut down
the application, you'd want to shutdown and close the open clients and
the server before exiting. But first things first. :)

Pete
 
G

Guest

Hi Peter,

I will write this code inside a window service. In on start event of the
window service. I haven't created the service yet, but I was wondering will
window service be OK fo this code. Can you please advice on that. I already
took lot of your time, but just one more question the code that you helped me
to write. Does this part looks fine to you because I was little bit confused
in the last part. Below is the code. I also pasted the whole code in my last
post.

if (cbRead == 0)
{
// The client has closed the connection
return;
}
else
{
state.client.GetStream().BeginRead(state.buffer,
0,state.buffer.Length, ReadCallback, state);

}
}
 
P

Peter Duniho

Vinki said:
Hi Peter,

I will write this code inside a window service. In on start event of the
window service. I haven't created the service yet, but I was wondering will
window service be OK fo this code. Can you please advice on that.

There's nothing special about a service that would prevent the same i/o
code from working. You still have to keep your process from exiting,
but that's true for _any_ application that you want to continue running.
It's not unique to network i/o.
I already
took lot of your time, but just one more question the code that you helped me
to write. Does this part looks fine to you because I was little bit confused
in the last part. Below is the code. I also pasted the whole code in my last
post.

if (cbRead == 0)
{
// The client has closed the connection
return;
}
else
{
state.client.GetStream().BeginRead(state.buffer,
0,state.buffer.Length, ReadCallback, state);

}
}

I would either make the "true" block of the if() statement return
directly, or I would have the "else" statement. I wouldn't have both;
it's not harmful to have both, but it would be redundant.

Either:

if(...)
{
// do something
return;
}

// do something else

Or:

if(...)
{
// do something
}
else
{
// do something else
}

Which one you'd use just depends on your personal preference. Me, I
tend to prefer _not_ to have more than one point of return in my
methods, and I prefer not to have any gotos. However, this is balanced
by my preference to not have my code repeatedly indented. So where
there's a very simple flow of logic like the above, I don't mind
sticking an extra return statement in, as in the first example.

But if you do that, you don't need the "else" statement. You can just
put the "else" code after the whole if() statement; having the return
statement in the "true" block of the if() statement ensures that you
will only execute the code that follows if the condition in the if()
statement is false. Thus, the "else" statement in that case is superfluous.

Pete
 
G

Guest

Vinki said:
I have this code for TCPListenPort. The code works fine, but my manager is
asking me to establish multiple connections to the same port. How can i
acheive that

If the number of concurrent connections are not too big, then the
simple one thread per connection approach will work fine.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top