multithreading - Connecting to Multiple TCP Servers From Client C# -



multithreading - Connecting to Multiple TCP Servers From Client C# -

making properties tcpclient , ipendpoint appear have fixed issue! if explain why case appreciate it. declare class objects static don't exclusively understand why works way.

i'd start saying usual, i've googled , googled haven't found answering question please point me if there reply question.

i have written tcp server , client in c#, client able connect multiple servers. clear not server multiple clients connected it, had no issues configuring that. here little image explaining mean:

pretty, know. in seriousness can't work. met error: a connect request made on connected socket have class called client, tcpclient , ipendpoint:

public client(ipendpoint ip) { client = new tcpclient(); this.ip = ip; }

this class has methods connect, send, receive etc. issue comes when this:

client host = new client(hosts.elementat(0)); ipendpoint ipe = hosts.elementat(0);

edit: contructor occurs in different method method "host" constructor client client = new client(ipe); client.connectasync(); host.connectasync(); tried utilize new async methods , await feature, worked fine when 1 host on sec began error. thought perhaps becuase using same method , attempting connect before first await had completed, seek connect 1 time again on first ip, no thought if makes sense thought, create new thread each connect effort so:

public void connectasync() { threadpool.queueuserworkitem(delegate { connectasyncmethod(); }); } private void connectasyncmethod() { thread connectthread = new thread(() => { seek { client.connect(ip.address, ip.port); this.clientstream = client.getstream(); receiveasync(); } grab (socketexception se) { } grab (notsupportedexception ns) { } grab (exception e) { } }); connectthread.start(); }

even though connect run on new thread, still same error, why? point me towards solution , explain flaws in thinking lie? thinking perhaps in way sockets handled i'm not sure. appreciate help, give thanks everyone.

you need multiple client objects found multiple connections different addresses (or same in fact). example, have client clienta connect server , have client clientb connect server b. cannot have same client object connect 2 times diffrent or same address.

c# multithreading sockets tcp client

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -