C# Socket double connect? -
i wondering, if create socket in c# , connect server, if create thread in program try , annother connectino server, server see 2 connections same place or one?
the code (the socket double-connecting):
iphostentry iphostinfo = dns.gethostentry("127.0.0.1"); ipaddress ipaddress = iphostinfo.addresslist[0]; ipendpoint remoteep = new ipendpoint(ipaddress, 11000); socket sender = new socket(addressfamily.internetwork, sockettype.stream, protocoltype.tcp); sender.receivetimeout = 5000; sender.connect(remoteep);
and have below code:
thread thread = new thread(new threadstart(doubleconnect)); thread.start(); public static void doubleconnect() { try { sender.connect(remoteep); } catch (exception ex) { } }
i have question because, on first part of code connect server, dont close connection, creating thread , reconnecting think server see 2 connection same client.
so, server see , 2 connection or 1 connection?
short answer: no.
you calling connect
twice on same socket
. looked in documentation, says nothing behaviour if that, reckon 2 things can happen:
- you exception on second
connect
(probablysocketexception
) - nothing. socket connected, falls through second
connect
call.
but, why not try out , see happens?
Comments
Post a Comment