Exemple #1
0
        private void SckSReceiveProc()
        {
            try
            {
                int IntAcceptData;

                byte[] clientData = new byte[RDataLen];

                while (true)
                {
                    if (!SckSPort.Connected)
                    {
                        logger.Error(Desc + " (" + RmIp + ":" + SPort + ") is disconnected.");
                        break;
                    }
                    // 程式會被 hand 在此, 等待接收來自 Server 端傳來的資料

                    IntAcceptData = SckSPort.Receive(clientData);

                    // 往下就自己寫接收到來自Server端的資料後要做什麼事唄~^^”

                    string S = Encoding.Default.GetString(clientData, 0, IntAcceptData);
                    //Console.WriteLine(S);
                    logger.Info("[Rev<--]" + S.Replace("\n", "") + "(From " + Desc + " " + RmIp + ":" + SPort + ")");
                    tObj.OnSocketMessage(S);
                }
            }

            catch (Exception e)
            {
                logger.Error("(From " + Desc + " " + RmIp + ":" + SPort + ")" + e.Message + "\n" + e.StackTrace);
                tObj.OnError();
            }
        }