This project is read-only.

Thread Safe

Mar 26, 2012 at 7:50 PM


Is this library thread safe?

Can I used multiple instances to transfer in parallel using .net 4 Task and Task Parallel library


   ICommunication[] _comm;//new TcpCommunication [3] ("",123);

        void test()

            Parallel.For(1, 4, (i) =>
                    _comm[i] = new TcpCommunication("", 1230 + i);
                    _comm[i].ConnectionEstablished += new EventHandler<EventArgs>(_comm_ConnectionEstablished);
                    _comm[i].ConnectionLost += new EventHandler<EventArgs>(_comm_ConnectionLost);



        public void _comm_ConnectionEstablished(object sender, EventArgs e)
            Console.WriteLine((sender as TcpCommunication).?????);

        public void _comm_ConnectionLost(object sender, EventArgs e)


How to get the host id and port of the client/server that has established the connection at the time of 

Besides how to ensure there is no cross connection between the 4 instances?
Mar 27, 2012 at 3:52 PM

You can instantiate many concurrent instances of all the communication classes (tcp, serial, etc).

The remote endpoint information is not currently exposed so you would need to create a super class with a unique identifier in it.

I'll update the class to support exposing the IP address and port.

Thanks for the suggestion.


Apr 16, 2012 at 10:02 PM

On second thought you can use the ConnectionDisplayText property to get the remote ip address and port once you are connected. It returns something like "".

May 17, 2012 at 7:12 AM


Ended up using that


How can I establish a TCP server based on this library?

Is it possible at all


May 17, 2012 at 5:00 PM

The library is for clients connecting to servers, which is fundamentally different than creating a tcp server. You will need to use another mean to create a tcp server.

May 21, 2012 at 4:24 AM


I used netsockets ( as server library.

I fired multiple clients using prophecy on to the server.

I cannot fire more than apx 200 clients? (200 is ok, 250 is not ok, 205 is ok,...)

I have tested netsockets with other clients, (WASP test tools)

I can fire 1000 clients and the server is able to accept all connections.

where could the problem be?


May 21, 2012 at 5:33 AM

What do you mean by you cannot fire more than aprox 200 clients...


Are you seeing errors?

Is the server rejecting the connection?

Are the connections successful but you can't transmit?

Are you running out of memory? etc.

May 24, 2012 at 10:59 AM

No Idea what was happening. 

The client could not establish connections.

However, it was likely related to UI updates (Winforms);

When I removed UI updates (list box) then things are better. It was getting stuck at the magic number of of 206;

My flow

establish connection to server -server sends some bytes (a new GUID) and client supposed to close connection.

(using parallel.for ( 0 to nnn))

All the while, the server side never crashed even with UI being updated on each connection ; the client used to crash after 205 connections; strange.. but when I removed UI update, I can establish 1000 parallel connections.....