client exception handle

main
syneffort 2 years ago
parent 73bf983604
commit 8182f4b3ba
  1. 10
      SocketStudy/PComm/PClient.cs

@ -62,6 +62,8 @@ namespace PComm
if (socket == null || !socket.Connected) if (socket == null || !socket.Connected)
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
socket.Connect(this.EndPoint); socket.Connect(this.EndPoint);
// send ID // send ID
@ -69,6 +71,14 @@ namespace PComm
socket.BeginReceive(new byte[] { 0 }, 0, 0, 0, AcceptCallback, null); socket.BeginReceive(new byte[] { 0 }, 0, 0, 0, AcceptCallback, null);
} }
catch(Exception ex)
{
Debug.WriteLine($"[ERROR] Socket connect fail({this.EndPoint.ToString()}): {ex.Message}");
PFileManager.Instance.WriteLog($"[ERROR] Socket connect fail({this.EndPoint.ToString()}): {ex.Message}");
Connect();
}
}
private int SendToSocket(byte[] buffer) private int SendToSocket(byte[] buffer)
{ {

Loading…
Cancel
Save