public void GetRooms() { try { NetworkClient.Start(); Plugin.log.Debug($"Creating message..."); NetOutgoingMessage outMsg = NetworkClient.CreateMessage(); Version assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version; byte[] version = new byte[4] { (byte)assemblyVersion.Major, (byte)assemblyVersion.Minor, (byte)assemblyVersion.Build, (byte)assemblyVersion.Revision }; outMsg.Write(version); new PlayerInfo(GetUserInfo.GetUserName(), GetUserInfo.GetUserID()).AddToMessage(outMsg); Plugin.log.Debug($"Connecting to {channelInfos[0].ip}:{channelInfos[0].port}..."); NetworkClient.Connect(channelInfos[0].ip, channelInfos[0].port, outMsg); } catch (Exception e) { ChannelException?.Invoke(this, e); Abort(); } }
public override Task ConnectAsync(EndPoint remoteAddress, EndPoint localAddress) { if (Local._state == State.Connected) { var cause = new AlreadyConnectedException(); Local.Pipeline.FireExceptionCaught(cause); return(TaskEx.FromException(cause)); } if (Local._connectPromise != null) { throw new ConnectionPendingException(); } Local._connectPromise = new TaskCompletionSource(); if (Local._state != State.Bound) { // Not bound yet and no LocalAddress specified. Get one if (localAddress == null) { localAddress = new LocalAddress(Local); } } if (localAddress != null) { try { Local.DoBind(localAddress); } catch (Exception ex) { PromiseUtil.SafeSetFailure(Local._connectPromise, ex, Logger); return(CloseAsync()); } } var boundChannel = LocalChannelRegistry.Get(remoteAddress); if (!(boundChannel is LocalServerChannel)) { var cause = new ChannelException("connection refused"); PromiseUtil.SafeSetFailure(Local._connectPromise, cause, Logger); return(CloseAsync()); } var serverChannel = boundChannel as LocalServerChannel; Local._peer = serverChannel.Serve(Local); return(TaskEx.Completed); }
public async Task ConnectThenSubscribeChannelWithoutAuthorizerAsync() { // Arrange var pusher = PusherFactory.GetPusher(saveTo: _clients); ChannelException caughtException = null; // Act try { await ConnectThenSubscribeAsync(pusher : pusher).ConfigureAwait(false); } catch (ChannelException ex) { caughtException = ex; } // Assert Assert.IsNotNull(caughtException); StringAssert.Contains("An Authorizer needs to be provided when subscribing to the private or presence channel", caughtException.Message); }
public void GetRooms() { try { NetworkClient.Start(); Misc.Logger.Info($"Creating message..."); NetOutgoingMessage outMsg = NetworkClient.CreateMessage(); outMsg.Write(Plugin.pluginVersion); new PlayerInfo(GetUserInfo.GetUserName(), GetUserInfo.GetUserID()).AddToMessage(outMsg); Misc.Logger.Info($"Connecting to {channelInfos[0].ip}:{channelInfos[0].port}..."); NetworkClient.Connect(channelInfos[0].ip, channelInfos[0].port, outMsg); } catch (Exception e) { ChannelException?.Invoke(this, e); Abort(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private int listen(int minPort, int maxPort) throws org.jboss.netty.channel.ChannelException private int Listen(int minPort, int maxPort) { ChannelException ex = null; for (int checkPort = minPort; checkPort <= maxPort; checkPort++) { try { string address = _config.clusterServer().Host; InetSocketAddress localAddress; if (string.ReferenceEquals(address, null) || address.Equals(INADDR_ANY)) { localAddress = new InetSocketAddress(checkPort); } else { localAddress = new InetSocketAddress(address, checkPort); BindingDetected = true; } Channel listenChannel = _serverBootstrap.bind(localAddress); ListeningAt(GetURI(localAddress)); _channels.add(listenChannel); return(checkPort); } catch (ChannelException e) { ex = e; } } _nioChannelFactory.releaseExternalResources(); throw ex; }
public async Task PusherShouldThrowAnExceptionWhenSubscribePresenceIsCalledAfterSubscribeAsync() { // Arrange ChannelException caughtException = null; // Act var pusher = new Pusher("FakeAppKey", new PusherOptions { Authorizer = new FakeAuthoriser("test") }); await pusher.SubscribeAsync("presence-123").ConfigureAwait(false); try { await pusher.SubscribePresenceAsync <int>("presence-123").ConfigureAwait(false); } catch (ChannelException ex) { caughtException = ex; } // Assert Assert.IsNotNull(caughtException); StringAssert.Contains("The presence channel 'presence-123' has already been created as a PresenceChannel", caughtException.Message); }
public override Task ConnectAsync(EndPoint remoteAddress, EndPoint localAddress) { if (Local._state == State.Connected) { var cause = new AlreadyConnectedException(); Local.Pipeline.FireExceptionCaught(cause); return TaskEx.FromException(cause); } if (Local._connectPromise != null) { throw new ConnectionPendingException(); } Local._connectPromise = new TaskCompletionSource(); if (Local._state != State.Bound) { // Not bound yet and no LocalAddress specified. Get one if (localAddress == null) { localAddress = new LocalAddress(Local); } } if (localAddress != null) { try { Local.DoBind(localAddress); } catch (Exception ex) { PromiseUtil.SafeSetFailure(Local._connectPromise, ex, Logger); return CloseAsync(); } } var boundChannel = LocalChannelRegistry.Get(remoteAddress); if (!(boundChannel is LocalServerChannel)) { var cause = new ChannelException("connection refused"); PromiseUtil.SafeSetFailure(Local._connectPromise, cause, Logger); return CloseAsync(); } var serverChannel = boundChannel as LocalServerChannel; Local._peer = serverChannel.Serve(Local); return TaskEx.Completed; }
public void Update() { if (NetworkClient != null && NetworkClient.Status == NetPeerStatus.Running) { NetIncomingMessage msg; while ((msg = NetworkClient.ReadMessage()) != null) { switch (msg.MessageType) { case NetIncomingMessageType.StatusChanged: { NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); if (status == NetConnectionStatus.Connected) { NetOutgoingMessage outMsg = NetworkClient.CreateMessage(); outMsg.Write((byte)CommandType.GetChannelInfo); outMsg.Write(channelInfos[currentChannel].channelId); NetworkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0); } else if (status == NetConnectionStatus.Disconnected) { ChannelException?.Invoke(this, new Exception("Channel refused connection!")); Abort(); } }; break; case NetIncomingMessageType.Data: { if ((CommandType)msg.ReadByte() == CommandType.GetChannelInfo) { ChannelInfo received = new ChannelInfo(msg); if (received.channelId == -1) { ChannelException?.Invoke(this, new Exception($"Channel with ID {channelInfos[currentChannel].channelId} not found!")); Abort(); return; } received.ip = channelInfos[currentChannel].ip; received.port = channelInfos[currentChannel].port; ReceivedResponse?.Invoke(this, received); if (channelInfos.Count - 1 > currentChannel) { currentChannel++; NetOutgoingMessage outMsg = NetworkClient.CreateMessage(); outMsg.Write((byte)CommandType.GetChannelInfo); outMsg.Write(channelInfos[currentChannel].channelId); NetworkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0); } else { Abort(); } } }; break; case NetIncomingMessageType.WarningMessage: Misc.Logger.Warning(msg.ReadString()); break; case NetIncomingMessageType.ErrorMessage: Misc.Logger.Error(msg.ReadString()); break; case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: Misc.Logger.Info(msg.ReadString()); break; default: Console.WriteLine("Unhandled type: " + msg.MessageType); break; } } } }