public void NoConnectionMessage() { var responseStream = new MemoryStream(); var stream = new TestStream(new MemoryStream(), responseStream); // Create mock byte server and client var mockByteServer = new Mock <IServer <byte, byte> > (); var byteServer = mockByteServer.Object; var mockByteClient = new Mock <IClient <byte, byte> > (); mockByteClient.Setup(x => x.Stream).Returns(stream); var byteClient = mockByteClient.Object; var server = new StreamServer(byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow(); server.Start(); // Fire a client connection event var eventArgs = new ClientRequestingConnectionEventArgs <byte, byte> (byteClient); mockByteServer.Raise(m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsFalse(eventArgs.Request.ShouldAllow); Assert.IsFalse(eventArgs.Request.ShouldDeny); Assert.AreEqual(responseStream.ToArray().Length, 0); }
public void InvalidConnectionMessageIdentifier() { var connectionMessage = TestingTools.CreateConnectionRequest(Type.Stream, "123456".ToBytes()); var responseStream = new MemoryStream(); var stream = new TestStream(new MemoryStream(connectionMessage), responseStream); // Create mock byte server and client var mockByteServer = new Mock <IServer <byte, byte> > (); var byteServer = mockByteServer.Object; var mockByteClient = new Mock <IClient <byte, byte> > (); mockByteClient.Setup(x => x.Stream).Returns(stream); var byteClient = mockByteClient.Object; var server = new StreamServer(byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow(); server.Start(); // Fire a client connection event var eventArgs = new ClientRequestingConnectionEventArgs <byte, byte> (byteClient); mockByteServer.Raise(m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsFalse(eventArgs.Request.ShouldAllow); Assert.IsTrue(eventArgs.Request.ShouldDeny); TestingTools.CheckConnectionResponse(responseStream.ToArray(), 40, Status.MalformedMessage, "Client identifier must be 16 bytes.", 0); }
public void ShortHelloMessageHeader() { var shortHelloMessage = new byte[5]; Array.Copy(helloMessage, shortHelloMessage, shortHelloMessage.Length); var responseStream = new MemoryStream(); var stream = new TestStream(new MemoryStream(shortHelloMessage), responseStream); // Create mock byte server and client var mockByteServer = new Mock <IServer <byte, byte> > (); var byteServer = mockByteServer.Object; var mockByteClient = new Mock <IClient <byte, byte> > (); mockByteClient.Setup(x => x.Stream).Returns(stream); var byteClient = mockByteClient.Object; var server = new StreamServer(byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow(); server.Start(); // Fire a client connection event var eventArgs = new ClientRequestingConnectionArgs <byte, byte> (byteClient); mockByteServer.Raise(m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsFalse(eventArgs.Request.ShouldAllow); Assert.IsTrue(eventArgs.Request.ShouldDeny); Assert.AreEqual(0, responseStream.Length); }
public void NoHelloMessage() { var responseStream = new MemoryStream (); var stream = new TestStream (new MemoryStream (), responseStream); // Create mock byte server and client var mockByteServer = new Mock<IServer<byte,byte>> (); var byteServer = mockByteServer.Object; var mockByteClient = new Mock<IClient<byte,byte>> (); mockByteClient.Setup (x => x.Stream).Returns (stream); var byteClient = mockByteClient.Object; var server = new StreamServer (byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow (); server.Start (); // Fire a client connection event var eventArgs = new ClientRequestingConnectionArgs<byte,byte> (byteClient); mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsFalse (eventArgs.Request.ShouldAllow); Assert.IsTrue (eventArgs.Request.ShouldDeny); Assert.AreEqual (0, responseStream.Length); }
public void ValidHelloMessage() { var responseStream = new MemoryStream(); var stream = new TestStream(new MemoryStream(helloMessage), responseStream); // Create mock byte server and client var mockByteServer = new Mock <IServer <byte, byte> > (); var byteServer = mockByteServer.Object; var byteClient = new TestClient(stream); var server = new StreamServer(byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow(); server.Start(); // Fire a client connection event var eventArgs = new ClientRequestingConnectionArgs <byte, byte> (byteClient); mockByteServer.Raise(m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsTrue(eventArgs.Request.ShouldAllow); Assert.IsFalse(eventArgs.Request.ShouldDeny); server.Update(); Assert.AreEqual(1, server.Clients.Count()); Assert.AreEqual(clientGuid, server.Clients.First().Guid); byte[] bytes = responseStream.ToArray(); byte[] expectedBytes = { 0x4F, 0x4B }; Assert.IsTrue(expectedBytes.SequenceEqual(bytes)); }
public void WrongConnectionType() { var responseStream = new MemoryStream(); var connectionMessage = TestingTools.CreateConnectionRequest(Type.Rpc, clientId.ToByteArray()); var stream = new TestStream(new MemoryStream(connectionMessage), responseStream); // Create mock byte server and client var mockByteServer = new Mock <IServer <byte, byte> > (); var byteServer = mockByteServer.Object; var mockByteClient = new Mock <IClient <byte, byte> > (); mockByteClient.Setup(x => x.Stream).Returns(stream); var byteClient = mockByteClient.Object; var server = new StreamServer(byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow(); server.Start(); // Fire a client connection event var eventArgs = new ClientRequestingConnectionEventArgs <byte, byte> (byteClient); mockByteServer.Raise(m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsFalse(eventArgs.Request.ShouldAllow); Assert.IsTrue(eventArgs.Request.ShouldDeny); TestingTools.CheckConnectionResponse(responseStream.ToArray(), 120, Status.WrongType, "Connection request was for the rpc server, but this is the stream server. " + "Did you connect to the wrong port number?", 0); }
public void ValidConnectionMessage() { var responseStream = new MemoryStream(); var stream = new TestStream(new MemoryStream(TestingTools.CreateConnectionRequest(Type.Stream, clientId.ToByteArray())), responseStream); // Create mock byte server and client var mockByteServer = new Mock <IServer <byte, byte> > (); var byteServer = mockByteServer.Object; var byteClient = new TestClient(stream); var server = new StreamServer(byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow(); server.Start(); // Fire a client connection event var eventArgs = new ClientRequestingConnectionEventArgs <byte, byte> (byteClient); mockByteServer.Raise(m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsTrue(eventArgs.Request.ShouldAllow); Assert.IsFalse(eventArgs.Request.ShouldDeny); server.Update(); Assert.AreEqual(1, server.Clients.Count()); Assert.AreEqual(clientId, server.Clients.First().Guid); TestingTools.CheckConnectionResponse(responseStream.ToArray(), 19, Status.Ok, string.Empty, 16); }
void GameConnection_DisconnectedEvent(object sender, EventArgs e) { Logger.Trace("Client IP: {0} disconnected", m_CurrentInfo != null ? m_CurrentInfo.Id.ToString() : this.ToString()); Dispose(); //StreamServerController.DisconnecteStreamServer(m_CurrentInfo != null ? m_CurrentInfo.Id : this.CurrentInfo.Id); m_CurrentInfo = null; //Offline the game server's status }
private async Task ConnectAsync(StreamServer ss) { await WebSocketClient .ConnectAsync(new System.Uri( $"wss://{ss.Fmp4.Host}/ws.app/stream/{ss.Movie.Id}/fmp4/bd/1/1500?mode=source")) .ConfigureAwait(false); IsRecording = true; }
internal KRPCServer(IPAddress address, ushort rpcPort, ushort streamPort, bool oneRPCPerUpdate = false, uint maxTimePerUpdate = 5000, bool adaptiveRateControl = true, bool blockingRecv = true, uint recvTimeout = 1000) { rpcTcpServer = new TCPServer ("RPCServer", address, rpcPort); streamTcpServer = new TCPServer ("StreamServer", address, streamPort); rpcServer = new RPCServer (rpcTcpServer); streamServer = new StreamServer (streamTcpServer); clientScheduler = new RoundRobinScheduler<IClient<Request,Response>> (); continuations = new List<RequestContinuation> (); streamRequests = new Dictionary<IClient<byte,StreamMessage>,IList<StreamRequest>> (); OneRPCPerUpdate = oneRPCPerUpdate; MaxTimePerUpdate = maxTimePerUpdate; AdaptiveRateControl = adaptiveRateControl; BlockingRecv = blockingRecv; RecvTimeout = recvTimeout; // Tie events to underlying server rpcServer.OnStarted += (s, e) => { if (OnStarted != null) OnStarted (this, EventArgs.Empty); }; rpcServer.OnStopped += (s, e) => { if (OnStopped != null) OnStopped (this, EventArgs.Empty); }; rpcServer.OnClientRequestingConnection += (s, e) => { if (OnClientRequestingConnection != null) OnClientRequestingConnection (s, e); }; rpcServer.OnClientConnected += (s, e) => { if (OnClientConnected != null) OnClientConnected (s, e); }; rpcServer.OnClientDisconnected += (s, e) => { if (OnClientDisconnected != null) OnClientDisconnected (s, e); }; // Add/remove clients from the scheduler rpcServer.OnClientConnected += (s, e) => clientScheduler.Add (e.Client); rpcServer.OnClientDisconnected += (s, e) => clientScheduler.Remove (e.Client); // Add/remove clients from the list of stream requests streamServer.OnClientConnected += (s, e) => streamRequests [e.Client] = new List<StreamRequest> (); streamServer.OnClientDisconnected += (s, e) => streamRequests.Remove (e.Client); // Validate stream client identifiers streamServer.OnClientRequestingConnection += (s, e) => { if (rpcServer.Clients.Where (c => c.Guid == e.Client.Guid).Any ()) e.Request.Allow (); else e.Request.Deny (); }; }
static void Main(string[] args) { WebServer ws = new WebServer("http://*:8080/"); GitController c = new GitController(); ws.Add(c); StreamServer d = new StreamServer(); while (true) { } }
public void ValidConnectionRequest() { var clientGuid = new Guid("1234567890abcdef1234567890abcdef".ToBytes()); var clientGuidBase64 = Convert.ToBase64String(clientGuid.ToByteArray()); var request = Encoding.ASCII.GetBytes( "GET /?id=" + clientGuidBase64 + " HTTP/1.1\r\n" + "Host: localhost\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Version: 13\r\n\r\n" ); var responseStream = new MemoryStream(); var stream = new TestStream(new MemoryStream(request), responseStream); // Create mock byte server and client var mockByteServer = new Mock <IServer <byte, byte> > (); var byteServer = mockByteServer.Object; var byteClient = new TestClient(stream); var server = new StreamServer(byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow(); server.Start(); // Fire a client connection event var eventArgs = new ClientRequestingConnectionEventArgs <byte, byte> (byteClient); mockByteServer.Raise(m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsTrue(eventArgs.Request.ShouldAllow); Assert.IsFalse(eventArgs.Request.ShouldDeny); server.Update(); Assert.AreEqual(1, server.Clients.Count()); Assert.AreEqual(clientGuid, server.Clients.First().Guid); var response = Encoding.ASCII.GetString(responseStream.ToArray()); Assert.AreEqual( "HTTP/1.1 101 Switching Protocols\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n", response ); }
internal KRPCServer(IPAddress address, ushort rpcPort, ushort streamPort) { rpcTcpServer = new TCPServer ("RPCServer", address, rpcPort); streamTcpServer = new TCPServer ("StreamServer", address, streamPort); rpcServer = new RPCServer (rpcTcpServer); streamServer = new StreamServer (streamTcpServer); clientScheduler = new RoundRobinScheduler<IClient<Request,Response>> (); continuations = new List<RequestContinuation> (); streamRequests = new Dictionary<IClient<byte,StreamMessage>,IList<StreamRequest>> (); // Tie events to underlying server rpcServer.OnStarted += (s, e) => { if (OnStarted != null) OnStarted (this, EventArgs.Empty); }; rpcServer.OnStopped += (s, e) => { if (OnStopped != null) OnStopped (this, EventArgs.Empty); }; rpcServer.OnClientRequestingConnection += (s, e) => { if (OnClientRequestingConnection != null) OnClientRequestingConnection (s, e); }; rpcServer.OnClientConnected += (s, e) => { if (OnClientConnected != null) OnClientConnected (s, e); }; rpcServer.OnClientDisconnected += (s, e) => { if (OnClientDisconnected != null) OnClientDisconnected (s, e); }; // Add/remove clients from the scheduler rpcServer.OnClientConnected += (s, e) => clientScheduler.Add (e.Client); rpcServer.OnClientDisconnected += (s, e) => clientScheduler.Remove (e.Client); // Add/remove clients from the list of stream requests streamServer.OnClientConnected += (s, e) => streamRequests [e.Client] = new List<StreamRequest> (); streamServer.OnClientDisconnected += (s, e) => streamRequests.Remove (e.Client); // Validate stream client identifiers streamServer.OnClientRequestingConnection += (s, e) => { if (rpcServer.Clients.Where (c => c.Guid == e.Client.Guid).Any ()) e.Request.Allow (); else e.Request.Deny (); }; }
public bool CreateRoom(string room_name) { string groupName; int newport; if (RoomSet.Contains(room_name)) { return(false); } RoomSet.Add(room_name); while (true) { groupName = RandomString(12); if (!GroupSet.Contains(groupName)) { break; } } sessions[room_name] = groupName; Console.WriteLine(groupName); GroupSet.Add(groupName); while (true) { newport = random.Next(1000, 65000); if (!PortSet.Contains(newport) && !PortInUse(newport)) { break; } } PortSet.Add(newport); ports.Add(groupName, newport); try { LastScreen.Add(groupName, new Part[10, 10]); messages.Add(groupName, new List <Message>()); } catch { } StreamServer streamServer = new StreamServer(newport); servers.Add(groupName, streamServer); streamServer.Init(); streamServer.ConnectToServer(); return(true); }
public void InvalidConnectionRequestNoGuid() { var ascii = Encoding.ASCII; var request = ascii.GetBytes( "GET / HTTP/1.1\r\n" + "Host: localhost\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Version: 13\r\n\r\n" ); var responseStream = new MemoryStream(); var stream = new TestStream(new MemoryStream(request), responseStream); // Create mock byte server and client var mockByteServer = new Mock <IServer <byte, byte> > (); var byteServer = mockByteServer.Object; var byteClient = new TestClient(stream); var server = new StreamServer(byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow(); server.Start(); // Fire a client connection event var eventArgs = new ClientRequestingConnectionEventArgs <byte, byte> (byteClient); mockByteServer.Raise(m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsFalse(eventArgs.Request.ShouldAllow); Assert.IsTrue(eventArgs.Request.ShouldDeny); server.Update(); Assert.AreEqual(0, server.Clients.Count()); var response = ascii.GetString(responseStream.ToArray()); Assert.AreEqual( "HTTP/1.1 400 Bad Request\r\n\r\n", response ); }
public void InvalidConnectionMessageHeader() { var connectionMessage = TestingTools.CreateConnectionRequest(Type.Stream, clientId.ToByteArray()); connectionMessage [2] ^= 0x42; connectionMessage [3] ^= 0x42; connectionMessage [4] ^= 0x42; connectionMessage [5] ^= 0x42; var responseStream = new MemoryStream(); var stream = new TestStream(new MemoryStream(connectionMessage), responseStream); // Create mock byte server and client var mockByteServer = new Mock <IServer <byte, byte> > (); var byteServer = mockByteServer.Object; var mockByteClient = new Mock <IClient <byte, byte> > (); mockByteClient.Setup(x => x.Stream).Returns(stream); var byteClient = mockByteClient.Object; var server = new StreamServer(byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow(); server.Start(); // Fire a client connection event var eventArgs = new ClientRequestingConnectionEventArgs <byte, byte> (byteClient); mockByteServer.Raise(m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsFalse(eventArgs.Request.ShouldAllow); Assert.IsTrue(eventArgs.Request.ShouldDeny); TestingTools.CheckConnectionResponse(responseStream.ToArray(), 209, Status.MalformedMessage, "While parsing a protocol message, the input ended unexpectedly in the middle of a field. " + "This could mean either that the input has been truncated or that an embedded message misreported its own length.", 0); }
/// <summary> /// Clear the server statistics. /// </summary> public void ClearStats() { RPCServer.ClearStats(); StreamServer.ClearStats(); }
public DebuggerServer() : base(UDP_SERVER_PORT) { audioStreamer = new StreamServer(this, OP_AUDIO_DATA); screenStreamer = new StreamServer(this, OP_SCREENCAP_DATA); }
public override void Run() { Logger.Info("GameServer Run! listening hostIP:{0}, port:{1}", ConfData.HostIp, ConfData.HostPort); serverImp = new StreamServer(this, ConfData.HostIp, Convert.ToInt32(ConfData.HostPort)); serverImp.Run(); }
public void ValidHelloMessage() { var responseStream = new MemoryStream (); var stream = new TestStream (new MemoryStream (helloMessage), responseStream); // Create mock byte server and client var mockByteServer = new Mock<IServer<byte,byte>> (); var byteServer = mockByteServer.Object; var byteClient = new TestClient (stream); var server = new StreamServer (byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow (); server.Start (); // Fire a client connection event var eventArgs = new ClientRequestingConnectionArgs<byte,byte> (byteClient); mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsTrue (eventArgs.Request.ShouldAllow); Assert.IsFalse (eventArgs.Request.ShouldDeny); server.Update (); Assert.AreEqual (1, server.Clients.Count ()); Assert.AreEqual (clientGuid, server.Clients.First ().Guid); byte[] bytes = responseStream.ToArray (); byte[] expectedBytes = { 0x4F, 0x4B }; Assert.IsTrue (expectedBytes.SequenceEqual (bytes)); }
internal KRPCServer(IPAddress address, ushort rpcPort, ushort streamPort, bool oneRPCPerUpdate = false, uint maxTimePerUpdate = 5000, bool adaptiveRateControl = true, bool blockingRecv = true, uint recvTimeout = 1000) { rpcTcpServer = new TCPServer("RPCServer", address, rpcPort); streamTcpServer = new TCPServer("StreamServer", address, streamPort); rpcServer = new RPCServer(rpcTcpServer); streamServer = new StreamServer(streamTcpServer); clientScheduler = new RoundRobinScheduler <IClient <Request, Response> > (); continuations = new List <RequestContinuation> (); streamRequests = new Dictionary <IClient <byte, StreamMessage>, IList <StreamRequest> > (); OneRPCPerUpdate = oneRPCPerUpdate; MaxTimePerUpdate = maxTimePerUpdate; AdaptiveRateControl = adaptiveRateControl; BlockingRecv = blockingRecv; RecvTimeout = recvTimeout; // Tie events to underlying server rpcServer.OnStarted += (s, e) => { if (OnStarted != null) { OnStarted(this, EventArgs.Empty); } }; rpcServer.OnStopped += (s, e) => { if (OnStopped != null) { OnStopped(this, EventArgs.Empty); } }; rpcServer.OnClientRequestingConnection += (s, e) => { if (OnClientRequestingConnection != null) { OnClientRequestingConnection(s, e); } }; rpcServer.OnClientConnected += (s, e) => { if (OnClientConnected != null) { OnClientConnected(s, e); } }; rpcServer.OnClientDisconnected += (s, e) => { if (OnClientDisconnected != null) { OnClientDisconnected(s, e); } }; // Add/remove clients from the scheduler rpcServer.OnClientConnected += (s, e) => clientScheduler.Add(e.Client); rpcServer.OnClientDisconnected += (s, e) => clientScheduler.Remove(e.Client); // Add/remove clients from the list of stream requests streamServer.OnClientConnected += (s, e) => streamRequests [e.Client] = new List <StreamRequest> (); streamServer.OnClientDisconnected += (s, e) => streamRequests.Remove(e.Client); // Validate stream client identifiers streamServer.OnClientRequestingConnection += (s, e) => { if (rpcServer.Clients.Where(c => c.Guid == e.Client.Guid).Any()) { e.Request.Allow(); } else { e.Request.Deny(); } }; }