diff --git a/SocketStudy/PComm/PClient.cs b/SocketStudy/PComm/PClient.cs index 62bff9f..af0c83a 100644 --- a/SocketStudy/PComm/PClient.cs +++ b/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)