private static Send ( Socket client, String data ) : void | ||
client | Socket | |
data | String | |
Результат | void |
private void Window_Closing(object sender, CancelEventArgs e) { if (server.isConnected == true) { String data = "Closing client<EOF>"; server.Send(data); server.StopClient(); } }
private void DataReceiveServerCallback(AsynchronousServer.State state, int bytesRead) { if (!m_Stopped) { m_DebugConsole?.WriteLineAsString(state.m_Buffer, bytesRead, Brushes.Green); m_Client.Send(state.m_Buffer, bytesRead); } }
public static void HandleRequest(StepRequest curr) { string toSend = JsonUtility.ToJson(curr); AsynchronousClient.Send(AsynchronousClient.client, toSend); Debug.Log("We sent a request for step " + curr.stepNum); }
/// <summary> /// 订阅 /// </summary> /// <param name="asynchronousClient"></param> private static void Subscribe(AsynchronousClient asynchronousClient) { SubscribeObject subscribeObject = new SubscribeObject(); subscribeObject.topic = "test"; Console.WriteLine($"我订阅了主题[{subscribeObject.topic}]"); asynchronousClient.Send(subscribeObject, MsgOperation.订阅消息Socket方式); }
public static void HandleRequest(SuppressActorRequest curr) { if (CheckAndResetRequestPossibility()) { string toSend = JsonUtility.ToJson(curr); AsynchronousClient.Send(AsynchronousClient.client, toSend); } }
/// <summary> /// 发布 /// </summary> /// <param name="asynchronousClient"></param> private static void Publish(AsynchronousClient asynchronousClient) { PublishObject publishObject = new PublishObject(); publishObject.topic = "test"; publishObject.content = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + new Random().Next(999).ToString(); Console.WriteLine($"我在主题[{publishObject.topic}]发布了一条消息:{publishObject.content}"); asynchronousClient.Send(publishObject, MsgOperation.发布广播); }
/// <summary> /// Отправляет сообщение /// </summary> public virtual void SendMessage(IMessage message) { if (IsDisposed) { return; } Client.Send(message.Serialize()); }
/// <summary> /// 登录 /// </summary> /// <param name="asynchronousClient"></param> private static void login(AsynchronousClient asynchronousClient) { AccessObject accessObject = new AccessObject(); accessObject.AccessKeyId = "user1"; accessObject.CurrentTimeSpan = Parse.DT2TS(DateTime.Now); accessObject.Sign = MD5Helper.Sign(accessObject.AccessKeyId + accessObject.CurrentTimeSpan + "password1"); Console.WriteLine($"我准备登录"); asynchronousClient.Send(accessObject, MsgOperation.登录校验); }
public static void HandleTagUntagRequestToBeSent(bool toggle, string actorId) { if (CheckAndResetRequestPossibility()) { TagActorRequest curr = new TagActorRequest(actorId, toggle); string toSend = JsonUtility.ToJson(curr); AsynchronousClient.Send(AsynchronousClient.client, toSend); Debug.Log("We sent a tag actor request"); } }
/// <summary> /// Отправляет ответ на полченное сообщение с картинкой с широкоугольной камерой /// </summary> private static void ResponseOnWideFieldImage(AsynchronousClient client, ImageMessage message) { File.WriteAllBytes($"C:\\tmp\\serverImage{_receivedImageNumber++}.jpg", message.Image.EncodeToJPG()); var newMessage = new WideFieldPositionMessage { Position = new Vector2Int(Random.Range(0, 255), Random.Range(0, 255)) }; client.Send(newMessage.Serialize()); Debug.Log($"[Server] WideField: send position \"{newMessage.Position}\""); }
private void DataReceiveCallback(byte[] result, int bytesRead) { m_DebugConsole.WriteLineAsString(result, bytesRead); byte[] response = m_GDBRSP.DataReceiveCallback(result, bytesRead); if (response != null) { m_DebugConsole.WriteLineAsString(response); m_Client.Send(response, bytesRead); } }
}//LoginPage for insert Username and Password public IActionResult Index(User user) { if (LogInControl(user)) { string json = JsonConvert.SerializeObject(user); AsynchronousClient.Send(AsynchronousClient.StartClient(), json); return(View()); } else { return(View("LogIn", user)); } }//Index Page who call LogInControl
private async void Button_Click(object sender, RoutedEventArgs e) { var serverSocket = AsynchronousSocketListener.GetInstance(); // サーバーが実行中の場合 if (serverSocket.IsEnabled) { // スレッドを停止 await serverSocket.StopListeningThread(); } // サーバーの起動 serverSocket.StartListeningThread(); // 自分のPC名を取得 string myPC = Environment.MachineName; clients.DataReceiveCallback = Non; clients.Connect(myPC, 11000); clients.Receive(); clients.Send("CPU<EOF>"); PN number = new PN() { playernumber = PlayerNumber }; Application.Current.Properties["Number"] = number; play_page = new Play_page(); play_page.clients = clients; // プレイページへ移動 this.NavigationService.Navigate(play_page); }
private async void Page_Loaded(object sender, RoutedEventArgs e) { clients.DataReceiveCallback = DataReceiveCallback; await Task.Run(() => { do { Thread.Sleep(100); } while (!Application.Current.Dispatcher.Invoke(() => { return(IsLoaded); })); }); try { clients.Receive(); clients.receiveDone.Reset(); clients.Send("VS<EOF>"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public Play_page() { InitializeComponent(); //プレイヤー名の設定 PlayerNumber = ((PN)Application.Current.Properties["Number"]).playernumber; //if (PlayerNumber == 1) this.DataContext = new { Name1 = "プレイヤー1", Name2 = "プレイヤー2", Score1 = count1, Score2 = count2 }; //else if (PlayerNumber == 2) this.DataContext = new { Name1 = "プレイヤー2", Name2 = "プレイヤー1", Score1 = count1, Score2 = count2 }; playPageViewModel = new PlayPageViewModel() { Name1 = (PlayerNumber == 1 ? "プレイヤー1" : "プレイヤー2"), Name2 = (PlayerNumber == 1 ? "プレイヤー2" : "プレイヤー1"), Score1 = 0, Score2 = 0 }; this.DataContext = playPageViewModel; //モグラをRandomで出すタイマー RandomTimer = new DispatcherTimer(DispatcherPriority.Normal); RandomTimer.Interval = TimeSpan.FromMilliseconds(RS); RandomTimer.IsEnabled = false; RandomTimer.Tick += RandomTimerEventHandler; //モグラをRandomで出すタイマー2 Random2Timer = new DispatcherTimer(DispatcherPriority.Normal); Random2Timer.Interval = TimeSpan.FromMilliseconds(RS2); Random2Timer.IsEnabled = false; Random2Timer.Tick += Random2TimerEventHandler; //制限時間のタイマー timeup2Timer = new DispatcherTimer(DispatcherPriority.Normal); timeup2Timer.Interval = TimeSpan.FromMilliseconds(stop2); timeup2Timer.IsEnabled = false; timeup2Timer.Tick += timeup2TimerEventHandler; //制限時間前のタイマー timeupTimer = new DispatcherTimer(DispatcherPriority.Normal); timeupTimer.Interval = TimeSpan.FromMilliseconds(stop); timeupTimer.IsEnabled = false; timeupTimer.Tick += timeupTimerEventHandler; //ラグをなくすタイマー tienTimer = new DispatcherTimer(DispatcherPriority.Normal); tienTimer.Interval = TimeSpan.FromMilliseconds(tien); tienTimer.IsEnabled = false; tienTimer.Tick += tienTimerEventHandler; // 制限時間のタイマーを開始 timeupTimer.IsEnabled = true; timeupTimer.Start(); // 制限時間前のタイマーを開始 timeup2Timer.IsEnabled = true; timeup2Timer.Start(); // ランダムタイマーを開始 RandomTimer.IsEnabled = true; RandomTimer.Start(); // リストに各モグラを追加 MoguraList = new List <mogurahole>(); MoguraList.Add(Mogura1_1); MoguraList.Add(Mogura1_2); MoguraList.Add(Mogura1_3); MoguraList.Add(Mogura1_4); MoguraList.Add(Mogura1_5); MoguraList.Add(Mogura1_6); MoguraList.Add(Mogura2_1); MoguraList.Add(Mogura2_2); MoguraList.Add(Mogura2_3); MoguraList.Add(Mogura2_4); MoguraList.Add(Mogura2_5); MoguraList.Add(Mogura2_6); MoguraList.Add(Mogura3_1); MoguraList.Add(Mogura3_2); MoguraList.Add(Mogura3_3); MoguraList.Add(Mogura3_4); MoguraList.Add(Mogura3_5); MoguraList.Add(Mogura3_6); MoguraList.Add(Mogura4_1); MoguraList.Add(Mogura4_2); MoguraList.Add(Mogura4_3); MoguraList.Add(Mogura4_4); MoguraList.Add(Mogura4_5); MoguraList.Add(Mogura4_6); // 全てのボタンにクリックイベントを設定しておく foreach (var targetbutton in MoguraList) { // クリック時のイベントを設定 targetbutton.AttackEvent = () => { Mogura_Click(); count1++; //clients.DataReceiveCallback = Doscore; if (PlayerNumber == 1) { try { clients.receiveDone.Reset(); clients.Send("<p1>" + count1.ToString() + "<score><EOF>"); //clients.receiveDone.WaitOne(); // Receive the clients.response from the remote device. if (clients.response.IndexOf("<score>") > -1) //score送信の部分 { clients.response = (clients.response.Replace("<score>", "")); var score = clients.response.Split(','); count2 = int.Parse(score[1].Replace("<EOF>", "")); } } catch (Exception e) { Console.WriteLine(e.ToString()); } } else if (PlayerNumber == 2) { try { clients.receiveDone.Reset(); clients.Send("<p2>" + count1.ToString() + "<score><EOF>"); //clients.receiveDone.WaitOne(); // Receive the clients.response from the remote device. if (clients.response.IndexOf("<score>") > -1) //score送信の部分 { clients.response = (clients.response.Replace("<score>", "")); var score = clients.response.Split(','); count2 = int.Parse(score[0].Replace("<EOF>", "")); } } catch (Exception e) { Console.WriteLine(e.ToString()); } } // Application.Propertiesに設定しておく。 PN number = new PN() { playernumber = PlayerNumber }; PN C1 = new PN() { c1 = count1 }; PN C2 = new PN() { c2 = count2 }; Application.Current.Properties["Number"] = number; Application.Current.Properties["C1"] = C1; Application.Current.Properties["C2"] = C2; }; } }
public static void SendMessage(byte[] message) { AsynchronousClient.Send(AsynchronousClient.sockXML, message); AsynchronousClient.sendDone.WaitOne(); }