Thread Safe

Mar 26, 2012 at 6:50 PM

Hi 

Is this library thread safe?

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

e.g 

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

        void test()
        {

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


                });

        }

        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 

_comm_ConnectionEstablished
Besides how to ensure there is no cross connection between the 4 instances?
Regards
Ajay
Coordinator
Mar 27, 2012 at 2: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.

John

Coordinator
Apr 16, 2012 at 9: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 "192.168.0.2:80".

May 17, 2012 at 6:12 AM

Yes

Ended up using that

Besides,

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

Is it possible at all

Ajay

Coordinator
May 17, 2012 at 4: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 3:24 AM

Thanks

I used netsockets (http://netsockets.codeplex.com/) 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)

http://www.serverframework.com/asynchronousevents/wasp-tutorial/

 http://www.serverframework.com/WASP/Examples/SChannelEchoServerTest.zip

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

where could the problem be?

Ajay

Coordinator
May 21, 2012 at 4: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 9: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.....