// アクセプト private void acceptTcpConnection(object e) { // if (this.isAct) { TcpClient client = this.listener_.AcceptTcpClient(); // create tcp connecton NetWorkContoroller dataSender = new NetWorkContoroller(client); System.Threading.ThreadPool.QueueUserWorkItem(acceptTcpConnection); lock (((ICollection)this.dataSenderList).SyncRoot) { // 新規コネクションに対してキャッシュデータの送信 List <DataObject> cacheData = this.dataCache.getAllDataList(); foreach (DataObject data in cacheData) { // データの送信 dataSender.setSndMessage(data); } // 送信先リストに追加 this.dataSenderList.Add(dataSender); } } }
//int portCnt, string ip, int port, DataObject[] splitFileList) //this.portCnt = portCnt; //this.ip = ip; //this.port = port; // = "127.0.0.1"; //int port = 6001; /* * System.Threading.ThreadPool.QueueUserWorkItem(runServerConnectionThread); * } * * private void runServerConnectionThread(object e) * { * DataObject[] splitFileList = e as DataObject[]; * * this.isRuning = true; */ public bool run(int portCnt, string ip, int port, DataObject[] splitFileList) { bool status = true; // サーバへの接続 try { Console.WriteLine("conntect to " + ip + ":" + port); TcpClient tcp = new TcpClient(ip, port); NetWorkContoroller masterConnection = new NetWorkContoroller(tcp); Console.WriteLine("connected"); // コネクション用ポートの開始 this.opnPortList = new int[portCnt]; this.tcpList = new NetWorkContoroller[portCnt]; for (int i = 0; i < portCnt; i++) { System.Threading.ThreadPool.QueueUserWorkItem(startMultiConnection, i); } // 解放されたポートを取得 string portList = getStartPortList(portCnt); Console.WriteLine("port data list : " + portList); DataObject data = new DataObject(MessageTypeEnum.ConnectList, portList); masterConnection.setSndMessage(data); connectionStartCheck(portCnt); // データの送信 int num = 0; lock (((ICollection)this.opnPortList).SyncRoot) { foreach (DataObject sendData in splitFileList) { tcpList[num % portCnt].setSndMessage(sendData); num++; } } DataObject fileFinish = new DataObject(MessageTypeEnum.FileFinish, 0); //num++; tcpList[num % portCnt].setSndMessage(fileFinish); // 接続待ち(サーバから複数接続) disconnectionStartCheck(); // 終了まち・タイムアウト設定 Console.WriteLine("file transfer compleat"); } catch (Exception E) { Console.WriteLine("Error no connection " + E.ToString()); } return(status); //this.isRuning = false; }