I came across this example of a chat app here...

http://www.daniweb.com/forums/thread59565.html

and am having trouble creating the multiple client part that is mentioned at the bottom...

If you want it to support multiple clients then put the TcpListener into an infinite loop in another thread etc.

I was wondering if you could tell me how to achieve this. I have a rough idea I would lay it out like this..

for (; ; )
{
TcpListener server = new TcpListener(IPAddress.Parse("127.0.0.1"), 8100);
//server.Start();
new Thread(new ThreadStart(server.Start));
}

But as of yet Its not working.

Any help would be appreciated.

Recommended Answers

All 6 Replies

No that would just call server.start

For future reference you should say in what way it doesnt work. What debugging showsd you, what else you tried...

The arguably best way to do it is to make your own server class, where it runs a thread, it has events to say to the rest of the app something happened, and to take input and send it when it can..

theres quite a few threaded server side examples on the net, just make sure you create and maniuplate your server object within the thread.

commented: Thanks anyway. +0

No that would just call server.start

For future reference you should say in what way it doesnt work. What debugging showsd you, what else you tried...

The arguably best way to do it is to make your own server class, where it runs a thread, it has events to say to the rest of the app something happened, and to take input and send it when it can..

theres quite a few threaded server side examples on the net, just make sure you create and maniuplate your server object within the thread.

Theres no flaw with the overall code, its just my attempts at threading are wrong. The error im achieving is simply that I cant get more than one client to connect to the server.

In reference to your suggestion searching for server examples online, do you honestly think I hadnt tried that before coming here?

Thanks anyway.

Well if you read so many of the other threads, next to no one seems to bother reading they just want answeres on a plate - you mention nothing of what else you tried we cant mind read, so, how are we to know?

So, your symptom is you can only connect once, this is useful to know.

Chances are then you dont have a loop listening for connections. We'd need more code to show that. Which would explain only the 1 connection.

That whole section should be in your thread, the whole listen and connect parts.

Well if you read so many of the other threads, next to no one seems to bother reading they just want answeres on a plate - you mention nothing of what else you tried we cant mind read, so, how are we to know?

So, your symptom is you can only connect once, this is useful to know.

Chances are then you dont have a loop listening for connections. We'd need more code to show that. Which would explain only the 1 connection.

That whole section should be in your thread, the whole listen and connect parts.

I dont want answers on a plate, only direction.

Your reply helps more now, thank-you.

So the direction I just gave was missd.

commented: Absolutely clueless!!!!! +0

So the direction I just gave was missd.

missed? How so?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.