Beispiel #1
0
        public static void Main(string[] args)
        {
            ClientDelegate clientDelegate = new ClientDelegate(Main2);

            clientDelegate.BeginInvoke(null, null, null);

            //ローカルのIPアドレスを作成
            IPAddress local = IPAddress.Parse("192.168.0.9");
            //ポート番号11111でリスナー作成
            TcpListener listener = new TcpListener(local, 11111);

            //リッスン開始
            listener.Start();
            //TCPクライアントを取得
            TcpClient client = listener.AcceptTcpClient();

            //通信用のストリームを取得
            NetworkStream stream = client.GetStream();

            //書き込むデータ。Helloのバイト配列
            byte[] data = { 0x48, 0x65, 0x6c, 0x6c, 0x6f };
            //TCPクライアントにメッセージを出力
            stream.Write(data, 0, data.Length);
            stream.Close();
            client.Close();
            listener.Stop();
            Console.ReadKey();
        }
Beispiel #2
0
        private void AsyncCallClient(ClientDelegate caller, string clientId, string URL, string[] script,
                                     IEnumerable <string> serverUrls)
        {
            Stopwatch sw = new Stopwatch();

            timer.Add(clientId, sw);
            sw.Start();

            caller.BeginInvoke(clientId, URL, script, serverUrls, asyncResult =>
            {
                timer[clientId].Stop();

                TimeSpan elapsed   = sw.Elapsed;
                string elapsedTime = String.Format("{0}",
                                                   elapsed.Minutes * 60 + elapsed.Seconds + elapsed.Milliseconds / 1000.0);
                Console.WriteLine("\n[TIMER ALERT] Finished script for client {0}. Elapsed time={1}s\n",
                                  clientId, elapsedTime);

                AsyncResult ar           = (AsyncResult)asyncResult;
                ClientDelegate remoteDel = (ClientDelegate)ar.AsyncDelegate;
                remoteDel.EndInvoke(asyncResult);
            }, null);
        }
Beispiel #3
0
 public IAsyncResult Client(string fields, string username, string url, string serverUrl)
 {
     _nodesCreated++;
     return(_clientDelegate.BeginInvoke(fields, username, url, serverUrl, null, null));
 }