static void SigleProThread(){Console.WriteLine("線程開始");byte[] receiveByte = new byte[1024];string connip = "連接來自:[" + mysocket.RemoteEndPoint.ToString() + "]";tempcontentip = connip;CFG.mylog.Log(connip);while (true){if (mysocket.Connected){try{Array.Clear(receiveByte, 0, receiveByte.Length);int recvlen = mysocket.Receive(receiveByte, receiveByte.Length, 0);byte[] content = receiveByte.Take(recvlen).ToArray();string result = Encoding.UTF8.GetString(content);if (result.Length == 0){if (mysocket != null){mysocket.Close();mysocket = null;}Console.WriteLine("連接已斷開");CFG.mylog.Log("連接已斷開1");break;}else{CFG.mylog.Log("recv=" + result);temprecvstr = result;proData(result);}}catch (Exception ex){//遠(yuǎn)程主機(jī)強(qiáng)迫關(guān)閉了一個(gè)現(xiàn)有的連接if (mysocket != null){mysocket.Close();mysocket = null;CFG.mylog.Log("mysocket已經(jīng)設(shè)為null");}Console.WriteLine("異常:" + ex.Message);CFG.mylog.Log("異常:" + ex.Message);break;}}else{if (mysocket != null){mysocket.Close();mysocket = null;}Console.WriteLine("連接已斷開");CFG.mylog.Log("連接已斷開2");break;}}}
1 回答

米琪卡哇伊
TA貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個(gè)贊
Index and length ...
索引或者長度(參數(shù))必須引用字符串中的一個(gè)位置
可能是你調(diào)用了一些函數(shù),比如
mid , left , instr,right ...
然后參數(shù)不在字符串的長度范圍內(nèi)
不過也只能是猜測
- 1 回答
- 0 關(guān)注
- 127 瀏覽
添加回答
舉報(bào)
0/150
提交
取消