@@ -43,7 +43,7 @@ public partial class MewtocolInterface : INotifyPropertyChanged, IDisposable {
43
43
/// </summary>
44
44
public event PropertyChangedEventHandler PropertyChanged ;
45
45
46
- private int connectTimeout = 1000 ;
46
+ private int connectTimeout = 3000 ;
47
47
/// <summary>
48
48
/// The initial connection timeout in milliseconds
49
49
/// </summary>
@@ -277,31 +277,40 @@ private async Task ConnectTCP () {
277
277
try {
278
278
279
279
if ( HostEndpoint != null ) {
280
+
280
281
client = new TcpClient ( HostEndpoint ) {
281
282
ReceiveBufferSize = RecBufferSize ,
282
283
NoDelay = false ,
283
- ExclusiveAddressUse = true ,
284
284
} ;
285
+ var ep = ( IPEndPoint ) client . Client . LocalEndPoint ;
286
+ Logger . Log ( $ "Connecting [MAN] endpoint: { ep . Address } :{ ep . Port } ", LogLevel . Verbose , this ) ;
287
+
285
288
} else {
289
+
286
290
client = new TcpClient ( ) {
287
291
ReceiveBufferSize = RecBufferSize ,
288
292
NoDelay = false ,
289
293
ExclusiveAddressUse = true ,
290
294
} ;
295
+
291
296
}
292
297
293
298
var result = client . BeginConnect ( targetIP , port , null , null ) ;
294
299
var success = result . AsyncWaitHandle . WaitOne ( TimeSpan . FromMilliseconds ( ConnectTimeout ) ) ;
295
300
296
- if ( ! success ) {
301
+ if ( ! success || ! client . Connected ) {
297
302
OnMajorSocketExceptionWhileConnecting ( ) ;
298
303
return ;
299
304
}
300
305
306
+ if ( HostEndpoint == null ) {
307
+ var ep = ( IPEndPoint ) client . Client . LocalEndPoint ;
308
+ Logger . Log ( $ "Connecting [AUTO] endpoint: { ep . Address . MapToIPv4 ( ) } :{ ep . Port } ", LogLevel . Verbose , this ) ;
309
+ }
310
+
301
311
stream = client . GetStream ( ) ;
302
312
stream . ReadTimeout = 1000 ;
303
313
304
- Console . WriteLine ( $ "Connected { client . Connected } ") ;
305
314
await Task . CompletedTask ;
306
315
307
316
} catch ( SocketException ) {
@@ -720,10 +729,11 @@ private async Task<string> SendSingleBlock (string _blockString) {
720
729
721
730
if ( client == null || ! client . Connected ) {
722
731
await ConnectTCP ( ) ;
723
- if ( ! client . Connected )
724
- return null ;
725
732
}
726
733
734
+ if ( client == null || ! client . Connected )
735
+ return null ;
736
+
727
737
var message = _blockString . ToHexASCIIBytes ( ) ;
728
738
729
739
//send request
@@ -759,7 +769,7 @@ private async Task<string> SendSingleBlock (string _blockString) {
759
769
}
760
770
761
771
} catch ( IOException ) {
762
- Logger . Log ( $ "Critical IO exception on receive" , LogLevel . Critical , this ) ;
772
+ OnMajorSocketExceptionWhileConnected ( ) ;
763
773
return null ;
764
774
} catch ( SocketException ) {
765
775
OnMajorSocketExceptionWhileConnected ( ) ;
0 commit comments