private void ProcessRequest() { if (curr_state == State.Ready) { curr_handshake = new HandShake(buffer.ToString()); if (curr_handshake.mode == 0) //read { Ack(); curr_state = State.Sending; SendData(curr_handshake.pos, curr_handshake.len); } else //write { Ack(); curr_state = State.Receiving; } } else if (curr_state == State.Receiving) { WriteReceivedData(); } else if (curr_state == State.Sending) { Console.WriteLine("ERROR: receve data while sending characters to WINIX"); } }
public override Task <HandShakeReply> CrossChainHandShake(HandShake request, ServerCallContext context) { Logger.LogTrace($"Received shake from chain {ChainHelper.ConvertChainIdToBase58(request.FromChainId)}."); _ = PublishCrossChainRequestReceivedEvent(request.Host, request.ListeningPort, request.FromChainId); return(Task.FromResult(new HandShakeReply { Success = true })); }
public void WriteReceivedData() { for (int i = curr_handshake.pos, j = 0; i < count && j < count; j++, i++) { buffer[i] = buffer[j]; } count = 0; curr_state = State.Ready; curr_handshake = null; }
public void SendData(int read_pos, int read_len) { for (int i = read_pos; i < read_pos + read_len; i++) { mserial.SendAsync(disk[i]); } mserial.SendAsync('\n'); curr_state = State.Ready; count = 0; //reset buffer; curr_handshake = null; }
public Worker(ILogger <Worker> logger, IConfiguration configuration, ConnectionProvider connectionProvider, AbstractTemplateSetupConnection templateSetupConnection, HandShake handShake) { _logger = logger; _configuration = configuration; _connectionProvider = connectionProvider; _handShake = handShake; templateSetupConnection.SetupConnection(); }
public void Save(XmlTextWriter xml) { xml.WriteStartElement("interface"); xml.WriteAttributeString("id", Id); xml.WriteAttributeString("portName", PortName); xml.WriteAttributeString("baudRate", BaudRate.ToString()); xml.WriteAttributeString("dataBits", DataBits.ToString()); xml.WriteAttributeString("handShake", HandShake.ToString()); xml.WriteAttributeString("parity", Parity.ToString()); xml.WriteAttributeString("stopBits", StopBits.ToString()); xml.WriteEndElement(); }
public async Task CrossChainIndexingShake_Test() { var request = new HandShake { ListeningPort = 2100, ChainId = ChainHelper.GetChainId(1) }; var context = BuildServerCallContext(); var indexingHandShakeReply = await BasicCrossChainRpcBase.CrossChainHandShake(request, context); Assert.NotNull(indexingHandShakeReply); Assert.True(indexingHandShakeReply.Status == HandShakeReply.Types.HandShakeStatus.Success); }
public override Task <HandShakeReply> CrossChainHandShake(HandShake request, ServerCallContext context) { Logger.LogDebug($"Received shake from chain {ChainHelper.ConvertChainIdToBase58(request.ChainId)}."); if (!GrpcUriHelper.TryParsePrefixedEndpoint(context.Peer, out IPEndPoint peerEndpoint)) { return(Task.FromResult(new HandShakeReply { Status = HandShakeReply.Types.HandShakeStatus.InvalidHandshakeRequest })); } _ = PublishCrossChainRequestReceivedEvent(peerEndpoint.Address.ToString(), request.ListeningPort, request.ChainId); return(Task.FromResult(new HandShakeReply { Status = HandShakeReply.Types.HandShakeStatus.Success })); }
public async Task ConnectAsync() { await _client.ConnectAsync(Constant.Endpoint.Address, Constant.Endpoint.Port); _stream = _client.GetStream(); var handshake = new HandShake(_username); await _stream.WriteAsync(handshake.Buffer); var awaiter = AwaitMessageAsync(); while (!_source.IsCancellationRequested) { Console.Write("#>"); var message = new Message(Console.ReadLine()); await _stream.WriteAsync(message.Buffer); } Task.WaitAll(awaiter); Console.WriteLine("Exited"); }
public async Task CrossChainIndexingShake_Test() { var request = new HandShake { ListeningPort = 2100, ChainId = ChainHelper.GetChainId(1) }; { // invalid peer format var context = BuildServerCallContext(null, "127.0.0.1"); var indexingHandShakeReply = await BasicCrossChainRpcBase.CrossChainHandShake(request, context); indexingHandShakeReply.Status.ShouldBe(HandShakeReply.Types.HandShakeStatus.InvalidHandshakeRequest); } { var context = BuildServerCallContext(); var indexingHandShakeReply = await BasicCrossChainRpcBase.CrossChainHandShake(request, context); Assert.NotNull(indexingHandShakeReply); Assert.True(indexingHandShakeReply.Status == HandShakeReply.Types.HandShakeStatus.Success); } }
private HandShake GetHandShake() { lock (_handShakeLock) { if (_handShake == null) { UserServicesSoapClient client = GetClient(); client.getTokenCompleted += (s, e) => { lock (_handShakeLock) { _handShake = e.Result; Monitor.Pulse(_handShakeLock); } }; client.getTokenAsync(Authentication, UserId); Monitor.Wait(_handShakeLock); } } return _handShake; }
private IEnumerator Start() { this.name = Name.text = IpAddr; RequestTaskQue = new Queue <IHttpRequester>(); LoginButton.onClick.AddListener(() => { System.Action handShakeSetup = () => { }; handShakeSetup = () => { var handShake = HandShake.Create(Requesters); handShake.PostAction = (res) => { LogDisplay.Instance.Push("[" + res.pushCode + "]"); if (res.pushCode == typeof(HandShake.ChangeBattlePhase).Name) { var changeBattlePhase = handShake.ConvertResponse <HandShake.ChangeBattlePhase>(); LogDisplay.Instance.Push(changeBattlePhase.phase); } if (res.pushCode == typeof(HandShake.Close).Name) { var close = handShake.ConvertResponse <HandShake.Close>(); LogDisplay.Instance.Push(close.pushCode + " : " + close.reason); return; } if (res.pushCode == typeof(HandShake.ExecCommand).Name) { var execCommand = handShake.ConvertResponse <HandShake.ExecCommand>(); LogDisplay.Instance.Push(execCommand.command); } if (res.pushCode == typeof(HandShake.MatchInfo).Name) { var matchInfo = handShake.ConvertResponse <HandShake.MatchInfo>(); LogDisplay.Instance.Push("matchId:" + matchInfo.matchId + "/matchType: " + matchInfo.matchType); } handShakeSetup(); }; StartCoroutine(handShake.RequestCoroutine(AuthToken)); }; var authLogin = AuthLogin.Create(Requesters); authLogin.PreAction = (req) => { req.account = Account; req.password = Password; return(null); }; authLogin.PostAction = (res) => { AuthToken = res.token; handShakeSetup(); }; RequestTaskQue.Enqueue(authLogin); }); LogoutButton.onClick.AddListener(() => { var authLogout = AuthLogout.Create(Requesters); RequestTaskQue.Enqueue(authLogout); }); MatchingEntryButton.onClick.AddListener(() => { var matchingEntry = MatchingEntryBattleServer.Create(Requesters); matchingEntry.PreAction = (req) => { req.ipAddr = IpAddr; req.port = 12345; req.rule = "PointCapture"; req.mapId = "Lv909"; req.label = "ビルドラベルゥ"; req.description = "おれサーバー"; req.autoMatchmakeTarget = true; req.serverName = "サバ太郎"; req.region = "ap-east-1"; req.owner = "yoshimura"; return(null); }; RequestTaskQue.Enqueue(matchingEntry); }); DisconnectPlayersButton.onClick.AddListener(() => { AcceptedPlayers.ForEach(playerId => { var reportDisconnectPlayer = ReportDisconnectPlayer.Create(Requesters); reportDisconnectPlayer.PreAction = (req) => { req.playerId = playerId; return(null); }; RequestTaskQue.Enqueue(reportDisconnectPlayer); }); AcceptedPlayers.Clear(); }); while (true) { while (RequestTaskQue.Count != 0) { var requester = RequestTaskQue.Dequeue(); yield return(requester.RequestCoroutine(AuthToken)); } yield return(new WaitForSeconds(1)); } }
protected virtual void HandleIncomingHandShake(PacketHeader header, Connection connection, HandShake incomingMessage) { if (Clients.Count() <= 2) { //IPEndPoint clientIPEndPoint = (IPEndPoint) connection.ExistingLocalListenEndPoints(ConnectionType.TCP).Last(); //NetworkComms.SendObject("Protocol", clientIPEndPoint.Address.ToString(), clientIPEndPoint.Port, "Connected"); lock (lastPeerMessageDict) { /* * if (lastPeerMessageDict.ContainsKey(incomingMessage.SourceIdentifier)) * { * if (lastPeerMessageDict[incomingMessage.SourceIdentifier].MessageIndex < incomingMessage.MessageIndex) * { * * lastPeerMessageDict[incomingMessage.SourceIdentifier] = incomingMessage; * } * } * else * { */ lastPeerMessageDict.Add(incomingMessage.SourceIdentifier, incomingMessage); Clients.Add(new InternalPlayer(new Player(0, incomingMessage.Name), connection)); connection.SendObject("Message", "Your are Connected to Powker! Wait Another Player..."); //} } } }
public UnidadeColetaTemplateSetupConnection(ILogger <UnidadeColetaTemplateSetupConnection> logger, IConfiguration configuration, ConnectionProvider connectionProvider, HandShake handShake, CommandDispatcher commandDispatcher) : base(logger, configuration, connectionProvider, commandDispatcher) { _handShake = handShake; }
private IEnumerator Start() { this.name = Name.text = Password; RequestTaskQue = new Queue <IHttpRequester>(); LoginButton.onClick.AddListener(() => { System.Action handShakeSetup = () => { }; handShakeSetup = () => { var handShake = HandShake.Create(Requesters); handShake.PostAction = (res) => { var masterDataVersion = ""; if (res.masterDataVersion != null) { if (0 < res.masterDataVersion.Length) { masterDataVersion += res.masterDataVersion[0] + "-"; } if (1 < res.masterDataVersion.Length) { masterDataVersion += "-" + res.masterDataVersion[1]; } if (2 < res.masterDataVersion.Length) { masterDataVersion += "-" + res.masterDataVersion[2]; } } var noticeCodes = ""; foreach (var code in res.opsNoticeCodes) { noticeCodes += "[" + code + "]"; } var disabledMS = ""; foreach (var ms in res.disabledMobileSuits) { disabledMS += "{" + ms + "}"; } LogDisplay.Instance.Push("[" + res.pushCode + "(" + masterDataVersion + ")" + " matchmake:" + res.enabledMatchmake + noticeCodes + disabledMS + "]"); if (res.pushCode == typeof(HandShake.JoinBattle).Name) { var joinBattle = handShake.ConvertResponse <HandShake.JoinBattle>(); var battleServer = GameObject.Find(joinBattle.ipAddr).GetComponent <BattleServer>(); battleServer.AcceptClient(PlayerId, joinBattle.ipAddr, joinBattle.port, joinBattle.joinPassword); LogDisplay.Instance.Push( joinBattle.ipAddr + ":" + joinBattle.port + ":" + joinBattle.joinPassword); Debug.Log("token:" + joinBattle.token); Debug.Log("encryptionKey:" + joinBattle.newEncryptionKey); } if (res.pushCode == typeof(HandShake.Close).Name) { var close = handShake.ConvertResponse <HandShake.Close>(); LogDisplay.Instance.Push(close.pushCode + " : " + close.reason); return; } if (res.pushCode == typeof(HandShake.Chat).Name) { var chat = handShake.ConvertResponse <HandShake.Chat>(); LogDisplay.Instance.Push(chat.playerId + ":" + chat.playerName + " : " + chat.text); } handShakeSetup(); }; StartCoroutine(handShake.RequestCoroutine(AuthToken)); }; var authLogin = AuthLogin.Create(Requesters); authLogin.PreAction = (req) => { req.account = Account; req.password = Password; req.packageVersion = new int[] { 1, 1, 1, 1, }; return(null); }; authLogin.PostAction = (res) => { AuthToken = res.token; PlayerId = res.playerId; LogDisplay.Instance.Push("initialLevel: " + res.initialLevel); handShakeSetup(); }; RequestTaskQue.Enqueue(authLogin); }); SetFirstOnetimeButton.onClick.AddListener(() => { var setFirstOnetime = SetFirstOnetime.Create(Requesters); setFirstOnetime.PreAction = (req) => { req.playerName = PlayerName; return(null); }; RequestTaskQue.Enqueue(setFirstOnetime); }); LogoutButton.onClick.AddListener(() => { var authLogout = AuthLogout.Create(Requesters); RequestTaskQue.Enqueue(authLogout); }); MatchingEntryButton.onClick.AddListener(() => { var matchingEntry = MatchingEntryPlayer.Create(Requesters); matchingEntry.PreAction = (req) => { req.matchType = (CasualMatch.isOn) ? 0 : 1; return(null); }; RequestTaskQue.Enqueue(matchingEntry); }); MatchingCancelButton.onClick.AddListener(() => { var matchingCancel = MatchingCancelPlayer.Create(Requesters); RequestTaskQue.Enqueue(matchingCancel); }); GetBattlesListButton.onClick.AddListener(() => { var getBattlesList = GetBattlesList.Create(Requesters); getBattlesList.PostAction = (res) => { var list = new List <string>(); res.battlesList.ForEach(bs => list.Add(bs.battleId)); BattlesListDropdown.ClearOptions(); BattlesListDropdown.AddOptions(list); }; RequestTaskQue.Enqueue(getBattlesList); }); RequestJoinBattleButton.onClick.AddListener(() => { var idx = BattlesListDropdown.value; var options = BattlesListDropdown.options; if (idx < options.Count) { var requestJoinBattle = RequestJoinBattle.Create(Requesters); requestJoinBattle.PreAction = (req) => { req.battleId = options[idx].text; return(null); }; RequestTaskQue.Enqueue(requestJoinBattle); } }); DioramaSaveButton.onClick.AddListener(() => { var dioramaSave = DioramaSave.Create(Requesters); dioramaSave.PreAction = (req) => { var fs = System.IO.File.Open("C:/Users/t-yoshimura/Desktop/img_2_m.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read); var bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); var form = new WWWForm(); form.AddBinaryData("sceneData", bytes, "filename1", "application/octet-stream"); form.AddField("index", 3); form.AddField("hashCode", Random.rotation.ToString("F4")); return(form); }; RequestTaskQue.Enqueue(dioramaSave); }); DioramaUploadButton.onClick.AddListener(() => { var dioramaUpload = DioramaUpload.Create(Requesters); dioramaUpload.PreAction = (req) => { var form = new WWWForm(); { var fs = System.IO.File.Open("C:/Users/t-yoshimura/Desktop/kinniku_ude.png", System.IO.FileMode.Open, System.IO.FileAccess.Read); var bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); form.AddBinaryData("sceneData", bytes, "filename1", "application/octet-stream"); } { var fs = System.IO.File.Open("C:/Users/t-yoshimura/Desktop/diet_before_man.png", System.IO.FileMode.Open, System.IO.FileAccess.Read); var bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); form.AddBinaryData("visual", bytes, "filename2", "application/octet-stream"); } form.AddField("hashCode", Random.rotation.ToString("F4")); return(form); }; RequestTaskQue.Enqueue(dioramaUpload); }); while (true) { while (RequestTaskQue.Count != 0) { var requester = RequestTaskQue.Dequeue(); yield return(requester.RequestCoroutine(AuthToken)); } yield return(new WaitForSeconds(1)); } }