public FrmMainWindow() { _frmConnectionDetails = new FrmConnectionDetails(); _transportHandler = new TransportHandler(); InitializeComponent(); }
static CommunicationManager() { CommunicationObjects = new ConcurrentDictionary <string, CommunicationObject>(); // default currentTrHnd = TransportHandler.TCP; }
protected void HandleResponseAppServerAddress(LiteNetLibMessageHandler messageHandler) { TransportHandler transportHandler = messageHandler.transportHandler; ResponseAppServerAddressMessage message = messageHandler.ReadMessage <ResponseAppServerAddressMessage>(); transportHandler.TriggerAck(message.ackId, message.responseCode, message); }
private async Task ListenImplAsync(Func <WebSocketTransport, Task> socketConnectFunc, RequestHandler requestHandler, CancellationToken cancellationToken = default(CancellationToken)) { var duplexPipePair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default); // Create transport and application var transport = new WebSocketTransport(duplexPipePair.Application, _logger); var application = new TransportHandler(duplexPipePair.Transport, _logger); // Create session _session = new StreamingSession(requestHandler, application, _logger, cancellationToken); // Start transport and application var transportTask = socketConnectFunc(transport); var applicationTask = application.ListenAsync(cancellationToken); var tasks = new List <Task>() { transportTask, applicationTask }; // Signal that session is ready to be used _sessionInitializedTask.SetResult(true); // Let application and transport run await Task.WhenAll(tasks).ConfigureAwait(false); }
protected void HandleResponseUserLogout(LiteNetLibMessageHandler messageHandler) { TransportHandler transportHandler = messageHandler.transportHandler; BaseAckMessage message = messageHandler.ReadMessage <BaseAckMessage>(); transportHandler.ReadResponse(message.ackId, message.responseCode, message); }
private void UpdateMapUsers(TransportHandler transportHandler, UpdateUserCharacterMessage.UpdateType updateType) { foreach (var user in usersById.Values) { UpdateMapUser(transportHandler, updateType, user); } }
protected void HandleResponseValidateAccessToken(LiteNetLibMessageHandler messageHandler) { TransportHandler transportHandler = messageHandler.transportHandler; ResponseValidateAccessTokenMessage message = messageHandler.ReadMessage <ResponseValidateAccessTokenMessage>(); transportHandler.ReadResponse(message.ackId, message.responseCode, message); }
static void OnReadHeaderComplete(TransportAsyncCallbackArgs args) { TransportHandler thisPtr = (TransportHandler)args.UserToken; if (args.Exception != null) { thisPtr.parent.OnHandleTransportComplete(args); return; } ByteBuffer buffer = new ByteBuffer(thisPtr.buffer, 0, thisPtr.buffer.Length); try { thisPtr.OnProtocolHeader(buffer); } catch (Exception exp) { if (Fx.IsFatal(exp)) { throw; } AmqpTrace.Provider.AmqpLogError(thisPtr, "OnProtocolHeader", exp.Message); args.Exception = exp; thisPtr.parent.OnHandleTransportComplete(args); } }
static void OnTransportOpened(IAsyncResult result) { if (result.CompletedSynchronously) { return; } TransportHandler thisPtr = (TransportHandler)result.AsyncState; try { thisPtr.HandleTransportOpened(result); } catch (Exception exp) { if (Fx.IsFatal(exp)) { throw; } AmqpTrace.Provider.AmqpLogError(thisPtr, "HandleTransportOpened", exp.Message); thisPtr.args.Exception = exp; thisPtr.parent.OnHandleTransportComplete(thisPtr.args); } }
protected virtual void HandleResponseCashPackageBuyValidation(LiteNetLibMessageHandler messageHandler) { TransportHandler transportHandler = messageHandler.transportHandler; ResponseCashPackageBuyValidationMessage message = messageHandler.ReadMessage <ResponseCashPackageBuyValidationMessage>(); transportHandler.TriggerAck(message.ackId, message.responseCode, message); }
protected void HandleResponseSelectCharacter(LiteNetLibMessageHandler messageHandler) { TransportHandler transportHandler = messageHandler.transportHandler; ResponseSelectCharacterMessage message = messageHandler.ReadMessage <ResponseSelectCharacterMessage>(); transportHandler.TriggerAck(message.ackId, message.responseCode, message); }
public override async Task <ResponseMessage> ReadNextAsync(CancellationToken cancellationToken) { // This catches exception thrown by the pipeline and converts it to QueryResponse try { return(await this.ExecuteNextHelperAsync(cancellationToken)); } catch (DocumentClientException exception) { return(exception.ToCosmosResponseMessage(request: null)); } catch (CosmosException exception) { return(exception.ToCosmosResponseMessage(request: null)); } catch (AggregateException ae) { ResponseMessage errorMessage = TransportHandler.AggregateExceptionConverter(ae, null); if (errorMessage != null) { return(errorMessage); } throw; } }
protected virtual void HandleResponseCashShopInfo(LiteNetLibMessageHandler messageHandler) { TransportHandler transportHandler = messageHandler.transportHandler; ResponseCashShopInfoMessage message = messageHandler.ReadMessage <ResponseCashShopInfoMessage>(); transportHandler.TriggerAck(message.ackId, message.responseCode, message); }
/// <summary> /// Opens the <see cref="StreamingConnection"/> and listens for incoming requests, which will /// be assembled and sent to the provided <see cref="RequestHandler"/>. /// </summary> /// <param name="requestHandler"><see cref="RequestHandler"/> to which incoming requests will be sent.</param> /// <param name="cancellationToken"><see cref="CancellationToken"/> that signals the need to stop the connection. /// Once the token is cancelled, the connection will be gracefully shut down, finishing pending sends and receives.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public virtual async Task ListenAsync(RequestHandler requestHandler, CancellationToken cancellationToken = default) { if (requestHandler == null) { throw new ArgumentNullException(nameof(requestHandler)); } var duplexPipePair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default); // Create transport and application _transport = CreateStreamingTransport(duplexPipePair.Application); var application = new TransportHandler(duplexPipePair.Transport, Logger); // Create session _session = new StreamingSession(requestHandler, application, Logger, cancellationToken); // Start transport and application var transportTask = _transport.ConnectAsync(cancellationToken); var applicationTask = application.ListenAsync(cancellationToken); var tasks = new List <Task> { transportTask, applicationTask }; // Signal that session is ready to be used _sessionInitializedTask.SetResult(true); // Let application and transport run await Task.WhenAll(tasks).ConfigureAwait(false); }
/// <summary> /// This is function which read response from map spawn server /// </summary> /// <param name="messageHandler"></param> protected void HandleResponseSpawnMap(LiteNetLibMessageHandler messageHandler) { TransportHandler transportHandler = messageHandler.transportHandler; ResponseSpawnMapMessage message = messageHandler.ReadMessage <ResponseSpawnMapMessage>(); transportHandler.ReadResponse(message.ackId, message.responseCode, message); }
protected void HandleResponseAppServerRegister(LiteNetLibMessageHandler messageHandler) { TransportHandler transportHandler = messageHandler.transportHandler; ResponseAppServerRegisterMessage message = messageHandler.ReadMessage <ResponseAppServerRegisterMessage>(); transportHandler.ReadResponse(message.ackId, message.responseCode, message); }
private void HandleResponseAppServerRegister(LiteNetLibMessageHandler messageHandler) { TransportHandler peerHandler = messageHandler.transportHandler; ResponseAppServerRegisterMessage message = messageHandler.ReadMessage <ResponseAppServerRegisterMessage>(); peerHandler.TriggerAck(message.ackId, message.responseCode, message); }
public static void SendGuildTerminate(this TransportHandler transportHandler, long?connectionId, ushort msgType, int id) { var netMessage = new UpdateGuildMessage(); netMessage.type = UpdateGuildMessage.UpdateType.Terminate; netMessage.id = id; Send(transportHandler, connectionId, msgType, netMessage); }
/// <summary> /// Creates an instance of the Device Provisioning Client. /// </summary> /// <param name="globalDeviceEndpoint">The global device endpoint host-name.</param> /// <param name="idScope">The IDScope for the Device Provisioning Service.</param> /// <param name="securityClient">The security client instance.</param> /// <param name="transport">The type of transport (e.g. HTTP, AMQP, MQTT).</param> /// <returns>An instance of the DPSDeviceClient</returns> public static ProvisioningDeviceClient Create( string globalDeviceEndpoint, string idScope, SecurityClient securityClient, TransportHandler transport) { throw new System.NotImplementedException(); }
protected void HandleResponseCharacters(LiteNetLibMessageHandler messageHandler) { TransportHandler transportHandler = messageHandler.transportHandler; ResponseCharactersMessage message = messageHandler.ReadMessage <ResponseCharactersMessage>(); uint ackId = message.ackId; transportHandler.TriggerAck(ackId, message.responseCode, message); }
private void UpdateMapUser(TransportHandler transportHandler, UpdateUserCharacterMessage.UpdateType updateType, UserCharacterData userData) { var updateMapUserMessage = new UpdateUserCharacterMessage(); updateMapUserMessage.type = updateType; updateMapUserMessage.data = userData; transportHandler.ClientSendPacket(SendOptions.ReliableOrdered, MMOMessageTypes.UpdateMapUser, updateMapUserMessage.Serialize); }
internal async Task <ThroughputResponse> ReplaceThroughputPropertiesIfExistsAsync( string targetRID, ThroughputProperties throughputProperties, RequestOptions requestOptions, CancellationToken cancellationToken = default) { try { (ThroughputProperties currentProperty, double requestCharge) = await this.GetOfferV2Async <ThroughputProperties>(targetRID, failIfNotConfigured : false, cancellationToken : cancellationToken); if (currentProperty == null) { CosmosException notFound = CosmosExceptionFactory.CreateNotFoundException( $"Throughput is not configured for {targetRID}", headers: new Headers() { RequestCharge = requestCharge }); return(new ThroughputResponse( httpStatusCode: notFound.StatusCode, headers: notFound.Headers, throughputProperties: null, diagnostics: notFound.Diagnostics, requestMessage: null)); } currentProperty.Content = throughputProperties.Content; return(await this.GetThroughputResponseAsync( streamPayload : this.ClientContext.SerializerCore.ToStream(currentProperty), operationType : OperationType.Replace, linkUri : new Uri(currentProperty.SelfLink, UriKind.Relative), resourceType : ResourceType.Offer, currentRequestCharge : requestCharge, requestOptions : requestOptions, cancellationToken : cancellationToken)); } catch (DocumentClientException dce) { ResponseMessage responseMessage = dce.ToCosmosResponseMessage(null); return(new ThroughputResponse( responseMessage.StatusCode, headers: responseMessage.Headers, throughputProperties: null, diagnostics: responseMessage.Diagnostics, requestMessage: responseMessage.RequestMessage)); } catch (AggregateException ex) { ResponseMessage responseMessage = TransportHandler.AggregateExceptionConverter(ex, null); return(new ThroughputResponse( responseMessage.StatusCode, headers: responseMessage.Headers, throughputProperties: null, diagnostics: responseMessage.Diagnostics, requestMessage: responseMessage.RequestMessage)); } }
public static void SendRemoveSocialMember(this TransportHandler transportHandler, long?connectionId, ushort msgType, int id, string characterId) { var netMessage = new UpdateSocialMemberMessage(); netMessage.type = UpdateSocialMemberMessage.UpdateType.Remove; netMessage.id = id; netMessage.CharacterId = characterId; Send(transportHandler, connectionId, msgType, netMessage); }
public static void SendSetGuildGold(this TransportHandler transportHandler, long?connectionId, ushort msgType, int id, int gold) { UpdateGuildMessage netMessage = new UpdateGuildMessage(); netMessage.type = UpdateGuildMessage.UpdateType.SetGold; netMessage.id = id; netMessage.gold = gold; Send(transportHandler, connectionId, msgType, netMessage); }
public static void SendSetGuildMessage(this TransportHandler transportHandler, long?connectionId, ushort msgType, int id, string message) { var netMessage = new UpdateGuildMessage(); netMessage.type = UpdateGuildMessage.UpdateType.SetGuildMessage; netMessage.id = id; netMessage.guildMessage = message; Send(transportHandler, connectionId, msgType, netMessage); }
public StreamingSession(RequestHandler receiver, TransportHandler sender, ILogger logger, CancellationToken connectionCancellationToken = default) { _receiver = receiver ?? throw new ArgumentNullException(nameof(receiver)); _sender = sender ?? throw new ArgumentNullException(nameof(sender)); _sender.Subscribe(new ProtocolDispatcher(this)); _logger = logger ?? NullLogger.Instance; _connectionCancellationToken = connectionCancellationToken; }
public static void SendChangePartyLeader(this TransportHandler transportHandler, long?connectionId, ushort msgType, int id, string characterId) { var netMessage = new UpdatePartyMessage(); netMessage.type = UpdatePartyMessage.UpdateType.ChangeLeader; netMessage.id = id; netMessage.characterId = characterId; Send(transportHandler, connectionId, msgType, netMessage); }
public static void SendCreateGuild(this TransportHandler transportHandler, long?connectionId, ushort msgType, int id, string guildName, string characterId) { var netMessage = new UpdateGuildMessage(); netMessage.type = UpdateGuildMessage.UpdateType.Create; netMessage.id = id; netMessage.guildName = guildName; netMessage.characterId = characterId; Send(transportHandler, connectionId, msgType, netMessage); }
public static void SendSetGuildMemberRole(this TransportHandler transportHandler, long?connectionId, ushort msgType, int id, string characterId, byte guildRole) { var netMessage = new UpdateGuildMessage(); netMessage.type = UpdateGuildMessage.UpdateType.SetGuildMemberRole; netMessage.id = id; netMessage.characterId = characterId; netMessage.guildRole = guildRole; Send(transportHandler, connectionId, msgType, netMessage); }
public static void SendSetGuildSkillLevel(this TransportHandler transportHandler, long?connectionId, ushort msgType, int id, int dataId, short level) { var netMessage = new UpdateGuildMessage(); netMessage.type = UpdateGuildMessage.UpdateType.SetSkillLevel; netMessage.id = id; netMessage.dataId = dataId; netMessage.level = level; Send(transportHandler, connectionId, msgType, netMessage); }
public static void SpawnHandler(AmqpTransportListener parent, TransportAsyncCallbackArgs args) { TransportHandler handler = new TransportHandler(parent, args); ActionItem.Schedule(Start, handler); }