public void D_client() { try { using (DdeClient client = new DdeClient("asirc", "command")) { client.Disconnected += OnDisconnected; client.Connect(); while (true) { //send_cmd = Console.ReadLine(); //send_cmd = "/msg #openssm 잘되네유"; if (!send_cmd.Equals(null)) { bytecode = Encoding.GetEncoding("utf-8").GetBytes(send_cmd + "\0"); } client.BeginPoke("command", bytecode, 1, OnPokeComplete, client); send_cmd = null; bytecode = null; } } } catch (Exception) { Environment.Exit(0); } }
public void Run2() { try { using (DdeClient client = new DdeClient("asirc", "command")) { client.Disconnected += OnDisconnected; client.Connect(); while (true) { byte[] bytecode = null; if (Properties.Settings.Default.gcm_msg != null) { if (Properties.Settings.Default.gcm_msg == "auth_success") // 인증 성공 { bytecode = Encoding.GetEncoding("utf-8").GetBytes("/smart_auth " + "\0"); client.BeginPoke("command", bytecode, 1, OnPokeComplete, client); } else if (Properties.Settings.Default.gcm_msg == "auth_fail") // 인증 실패 { bytecode = Encoding.GetEncoding("utf-8").GetBytes("/echo -a $erlogo 인증 실패!" + "\0"); client.BeginPoke("command", bytecode, 1, OnPokeComplete, client); } else if (Properties.Settings.Default.gcm_msg == "auth_cancel") // 인증 취소 { bytecode = Encoding.GetEncoding("utf-8").GetBytes("/smart_auth_cancel" + "\0"); client.BeginPoke("command", bytecode, 1, OnPokeComplete, client); } else if (Properties.Settings.Default.gcm_msg == "dde_state") // 인증 취소 { bytecode = Encoding.GetEncoding("utf-8").GetBytes("/dde_alive" + "\0"); client.BeginPoke("command", bytecode, 1, OnPokeComplete, client); } Properties.Settings.Default.gcm_msg = null; Properties.Settings.Default.Save(); } } } } catch (Exception e) { Console.WriteLine(e); Console.WriteLine("IRC 실행 요망"); Environment.Exit(0); } }
public void Test_BeginPoke_Before_Connect() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); Assert.Throws<InvalidOperationException>(() => client.BeginPoke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, null, null)); }
public static void RunDdeClient() { // Wait for the user to press ENTER before proceding. Console.WriteLine("The Server sample must be running before the client can connect."); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); try { // Create a client that connects to 'myapp|mytopic'. using (DdeClient client = new DdeClient("EXCEL", "[Book1.xlsx]2011-06-22")) { //[stock.xls]Sheet1!'r2c2' // Subscribe to the Disconnected event. This event will notify the application when a conversation has been terminated. client.Disconnected += OnDisconnected; // Connect to the server. It must be running or an exception will be thrown. client.Connect(); // Synchronous Execute Operation // client.Execute("mycommand", 60000); // Synchronous Poke Operation //client.Poke("myitem", DateTime.Now.ToString(), 60000); //client.Poke("A3", DateTime.Now.ToString(), 60000); // Syncronous Request Operation //Console.WriteLine("Request: " + client.Request("myitem", 60000)); Console.WriteLine("Request: " + client.Request("'r1c1'", 60000)); // Asynchronous Execute Operation //client.BeginExecute("mycommand", OnExecuteComplete, client); // Asynchronous Poke Operation //client.BeginPoke("myitem", Encoding.ASCII.GetBytes(DateTime.Now.ToString() + "\0"), 1, OnPokeComplete, client); client.BeginPoke("A2", Encoding.ASCII.GetBytes(DateTime.Now.ToString() + "\0"), 1, OnPokeComplete, client); // Asynchronous Request Operation //client.BeginRequest("myitem", 1, OnRequestComplete, client); client.BeginRequest("A4", 1, OnRequestComplete, client); // Advise Loop client.StartAdvise("myitem", 1, true, 60000); client.Advise += OnAdvise; // Wait for the user to press ENTER before proceding. Console.WriteLine("Press ENTER to quit..."); Console.ReadLine(); } } catch (Exception e) { Console.WriteLine(e.GetType().ToString()); Console.WriteLine(e.Message); Console.WriteLine(e.InnerException); Console.WriteLine("Press ENTER to quit..."); Console.ReadLine(); } }
public void Test_BeginPoke() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); client.Connect(); var ar = client.BeginPoke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, null, null); Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(Timeout, false)); }
public void Test_BeginPoke_After_Dispose() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); client.Connect(); client.Dispose(); Assert.Throws<ObjectDisposedException>(() => client.BeginPoke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, null, null)); }
public void Test_BeginPoke_Before_Connect() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { IAsyncResult ar = client.BeginPoke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, null, null); } } }
public void Test_EndPoke_After_Dispose() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); client.Connect(); var ar = client.BeginPoke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, null, null); Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(Timeout, false)); client.Dispose(); Assert.Throws<ObjectDisposedException>(() => client.EndPoke(ar)); }
public void Test_EndPoke_After_Dispose() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); IAsyncResult ar = client.BeginPoke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, null, null); Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(Timeout, false)); client.Dispose(); client.EndPoke(ar); } } }
public void Test_EndPoke() { using (var server = new TestServer(ServiceName)) { server.Register(); using (var client = new DdeClient(ServiceName, TopicName)) { client.Connect(); var ar = client.BeginPoke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, null, null); Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(Timeout, false)); client.EndPoke(ar); Assert.AreEqual(TestData, Encoding.ASCII.GetString(server.GetData(TopicName, ItemName, 1))); } } }
public void Run() { try { using (DdeClient client = new DdeClient("asirc", "command")) { client.Disconnected += OnDisconnected; client.Connect(); while (true) { logger(); if (ClientHandler.clientSocket.Connected) { try { receiveData = new byte[2048]; if (ClientHandler.clientSocket.Receive(receiveData, 0, receiveData.Length, SocketFlags.None) == 0) { throw new SocketException(); } str = Encoding.UTF8.GetString(receiveData); if (str != String.Empty) { int getValueLength = 0; byte[] newByte = new byte[receiveData.Length]; getValueLength = ClientHandler.byteArrayDefrag(receiveData); str = Encoding.UTF8.GetString(receiveData, 0, getValueLength + 1); if (str.Contains("{\"message\":\"[HEARTBEAT]\"}")) { continue; // 하트비트 이그노어 } if (str.Contains("{\"message\":\"Bye Bye\"}")) { continue; // 바이바이 이그노어 } send_cmd = JsonConvert.DeserializeObject <jData>(str); receiveData = new byte[2048]; } } catch (SocketException se) { if (se.ErrorCode == 10035) { continue; // 논블로킹 예외 처리 } else { Console.WriteLine("클라이언트 연결 해제"); ClientHandler.clientSocket.Shutdown(SocketShutdown.Both); ClientHandler.clientSocket.Close(); break; } } } byte[] bytecode = null; if (send_cmd != null) { bytecode = Encoding.UTF8.GetBytes(send_cmd.message + "\0"); Console.WriteLine("[수신] " + send_cmd.message); // MONITOR client.BeginPoke("command", bytecode, 1, OnPokeComplete, client); send_cmd.message = null; } bytecode = null; } } } catch (Exception e) { Console.WriteLine(e); Console.WriteLine("IRC 실행 요망"); Environment.Exit(0); } }