@@ -174,11 +174,11 @@ private void Loop()
174174 int length ;
175175 while ( Running && Connected )
176176 {
177- if ( Socket . Poll ( - 1 , SelectMode . SelectRead ) )
177+ try
178178 {
179- try
179+ if ( Socket . Poll ( - 1 , SelectMode . SelectRead ) )
180180 {
181- data = new byte [ 1024 ] ;
181+ data = new byte [ Socket . ReceiveBufferSize ] ;
182182 length = - 1 ;
183183 length = Socket . Receive ( data ) ;
184184
@@ -192,43 +192,43 @@ private void Loop()
192192
193193 parent . OnData ? . Invoke ( Sender , tmp ) ;
194194 }
195- catch ( SocketException ex )
196- {
195+ }
196+ catch ( SocketException ex )
197+ {
197198#if DEBUG
198- Console . WriteLine ( ex . Message ) ;
199+ Console . WriteLine ( ex . Message ) ;
199200#endif
200- if ( ex . SocketErrorCode == SocketError . ConnectionReset || ex . SocketErrorCode == SocketError . ConnectionAborted )
201- {
201+ if ( ex . SocketErrorCode == SocketError . ConnectionReset || ex . SocketErrorCode == SocketError . ConnectionAborted )
202+ {
202203#if DEBUG
203- Console . WriteLine ( $ "Server { RemoteEndPoint } offline by { ( SocketError ) ex . SocketErrorCode } .") ;
204+ Console . WriteLine ( $ "Server { RemoteEndPoint } offline by { ( SocketError ) ex . SocketErrorCode } .") ;
204205#endif
205- break ;
206- }
207- else
208- {
209- parent . OnException ? . Invoke ( Sender , ex ) ;
210- }
206+ break ;
211207 }
212- catch ( Exception ex )
208+ else
213209 {
214- #if DEBUG
215- Console . WriteLine ( ex . Message ) ;
216- #endif
217210 parent . OnException ? . Invoke ( Sender , ex ) ;
218- continue ;
219211 }
220-
221- Thread . Sleep ( 10 ) ;
222212 }
213+ catch ( Exception ex )
214+ {
215+ #if DEBUG
216+ Console . WriteLine ( ex . Message ) ;
217+ #endif
218+ parent . OnException ? . Invoke ( Sender , ex ) ;
219+ continue ;
220+ }
221+
222+ Thread . Sleep ( 10 ) ;
223223 }
224224
225225 Running = false ;
226226
227- if ( Socket ? . Connected == true )
227+ if ( Socket ? . Connected == true )
228228 {
229229 Socket . Shutdown ( SocketShutdown . Both ) ;
230230 Socket . Disconnect ( true ) ;
231- Socket . Close ( ) ;
231+ Socket . Close ( ) ;
232232 }
233233
234234#if DEBUG
0 commit comments