Exemplo n.º 1
0
Task w(){t++;if(t>p.Length-1){q();return;}var a=p[t];try{var b=new a6();M.o(
"Connecting to the handshake server "+a);var c=b.s(a,o);var d=await Task.WhenAny
(c,Task.Delay(500)).ContinueWith(f=>{if(f.Exception!=null){M.o(
"Handshake connection failed for "+a+" "+f.Exception.Message);return false;}if(f
.Result==null)return false;if(f.Result.Exception!=null){M.o(
"Handshake connection failed for "+a+" "+f.Result.Exception.Message);return
false;}if(f.Result!=c){M.o("Handshake connection timed out");return false;}
return true;});if(d){var g=b.Client;var h=false;var i=new
CancellationTokenSource();g.BeginReceive(s,0,s.Length,0,j=>{i.Cancel();if(!h)y(j
,g);},a);var k=Task.Delay(1000,i.Token).ContinueWith(f=>{if(f.Exception==null&&f
.Status!=TaskStatus.Canceled){h=true;v.Set();}});await x();try{if(g.Object is
IDisposable){var l=(IDisposable)g.Object;l.Dispose();}}catch{M.o(
"Failed to properly dispose a socket for "+a);}}if(string.IsNullOrWhiteSpace(u))
{M.WriteLine("Handshake server unreachable "+a);await w();}else{r(u);}}catch(
Exception e){M.o("Handshake failed for "+a);M.Exception(e);await w();}}private
Exemplo n.º 2
0
void z(string a){var b=new a6();try{M.o("Listener connecting to "+a);b.s(a,s).
Wait(20);M.o("Listener connected to "+a);v=b.Client;A(v,0);}catch(Exception e){M
.o("Listener failed to connect to "+a);M.Exception(e);}}private void A(a5 a,int