tags:

views:

201

answers:

2

What I'm currently trying to do is make a very basic webchat for irc using silverlight.

Basically how I'm trying to do it is have a tcp server listening for connections from silverlight. When a client connects it creates a new connection to irc and data is passed to/from the client/irc via the server application.

I've gotten it to work fine for one client connection, but as soon as two (or more) clients connect multiple connections are made to irc but all data passed from the clients just goes through the latest irc connection (if that makes sense).

For example Client1, Client2 and Client3 are all connected to irc, but no matter who sends data it all comes through Client3.

Between the client and server app it recognizes the data coming in from different clients so i believe the problems lies within the way I've connected to the irc. When the TCP server accepts a new client a new thread is made to listen to incoming data, and from there a new thread is made to connect to irc. I'm sure thats where the problem exists, but I've confused myself a lot now and am wondering if anyone can help me figure out a solution.

EDIT: What I think is the problem, is that it can't distinguish which thread the specific client is using, so it just sends it via the latest one. Can this even be done?

A: 

It seems that the server is opening sockets only to the last connection made. Maybe if you try and process the message on the server and open a socket to the client it might work.

npinti
I don't think there is a problem with that part. It's sending data from the client --> server --> irc that is the problem. Client enters data, it goes to the server (this part is fine), it then goes to the irc (this is where its all coming out from the latest connection)
Jamie
A: 

I think your problem in the thread model and the way you manage your Connection Pool. Read this article Simple Threaded TCP Server.

Daniel Bern