Skip to content

Commit

Permalink
fix: 连接tcp失败时有概率崩溃软件
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxuuu committed Oct 16, 2024
1 parent b5a7670 commit b1d1c2f
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions llcom/Pages/SocketClientPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void ConnectButton_Click(object sender, RoutedEventArgs e)
return;
}

if(so.isSSL)
if (so.isSSL)
{
var networkStream = new NetworkStream(s);
var ssl = new SslStream(
Expand All @@ -155,7 +155,7 @@ private void ConnectButton_Click(object sender, RoutedEventArgs e)
{
ssl.AuthenticateAsClient("llcom tcp ssl client");
}
catch(Exception ssle)
catch (Exception ssle)
{
ShowData($"❗ SSL error {ssle.Message}");
socketNow = null;
Expand All @@ -166,13 +166,41 @@ private void ConnectButton_Click(object sender, RoutedEventArgs e)
ShowData("❌ Server disconnected");
return;
}
socketNow = new SocketObj(ssl);
ssl.BeginRead(so.buffer, 0, StateObject.BUFFER_SIZE, new AsyncCallback(Read_Callback), so);
try
{
socketNow = new SocketObj(ssl);
ssl.BeginRead(so.buffer, 0, StateObject.BUFFER_SIZE, new AsyncCallback(Read_Callback), so);
}
catch (Exception ex)
{
ShowData($"❗ Server connect error {ex.Message}");
socketNow = null;
IsConnected = false;
Changeable = true;
s.Close();
s.Dispose();
ShowData("❌ Server disconnected");
return;
}
}
else
{
so.workSocket = s;
s.BeginReceive(so.buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(Read_Callback), so);
try
{
s.BeginReceive(so.buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(Read_Callback), so);
}
catch(Exception ex)
{
ShowData($"❗ Server connect error {ex.Message}");
socketNow = null;
IsConnected = false;
Changeable = true;
s.Close();
s.Dispose();
ShowData("❌ Server disconnected");
return;
}
}
}), s);
}
Expand Down

0 comments on commit b1d1c2f

Please sign in to comment.