client exception handle

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

@ -62,12 +62,22 @@ namespace PComm
if (socket == null || !socket.Connected)
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(this.EndPoint);
try
{
socket.Connect(this.EndPoint);
// send ID
this.Send(PDataType.ClientID, Encoding.UTF8.GetBytes(this.ID));
// send ID
this.Send(PDataType.ClientID, Encoding.UTF8.GetBytes(this.ID));
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)

Loading…
Cancel
Save