public Service() { InitializeComponent(); ch = new ServerHandler(); this.DataContext = ch; lst.ItemsSource = ch.cService.conectedUsers; }
static async Task RunServerAsync(int port) { var bossGroup = new MultithreadEventLoopGroup(1); var workerGroup = new MultithreadEventLoopGroup(); var stringEncoder = new StringEncoder(); var stringDecoder = new StringDecoder(); var serverHandler = new ServerHandler(GameCore); try { var bootstrap = new ServerBootstrap(); bootstrap .Group(bossGroup, workerGroup) .Channel <TcpServerSocketChannel>() .Option(ChannelOption.SoBacklog, 100) .Handler(new LoggingHandler(LogLevel.INFO)) .ChildHandler(new ActionChannelInitializer <ISocketChannel>(channel => { var pipeline = channel.Pipeline; pipeline.AddLast(new DelimiterBasedFrameDecoder(8192, Delimiters.LineDelimiter())); pipeline.AddLast(stringEncoder, stringDecoder, serverHandler); })); var bootstrapChannel = await bootstrap.BindAsync(port); GameCore.RunContainers(); await bootstrapChannel.CloseAsync(); } finally { Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), workerGroup.ShutdownGracefullyAsync()); } }
public AcceptedClient(TcpClient xClient, ServerHandler xServer) { _client = xClient; _server = xServer; var stream = _client.GetStream(); _reader = new StreamReader(stream); _writer = new StreamWriter(stream); }
private void sendRequestToAllClients(String request) { lock (_lock) { for (int index = 0; index < Server.connections.Count; index++) { ServerHandler sc = Server.connections[index]; sc.sendRequestToClient(request); Console.WriteLine(sc); } } }
static void Main(string[] args) { Console.WriteLine("Project Chat - Server"); Console.WriteLine("---------------------"); Console.WriteLine("Port is set to " + PORT); ServerHandler handler = new ServerHandler(PORT); handler.StartServer(); Console.ReadLine(); }
private void serveButton_Click(object sender, EventArgs e) { if (serveButton.Text == "Serve") { int port = int.Parse(portTextBox.Text); server = new ServerHandler(port, mainServerController); server.handle(); serveButton.Text = "Stop"; } else { server.stop(); serveButton.Text = "Serve"; } }
public ClientHandler(Socket clientSocket, ServerHandler connectedServer) { ConnectedServer = connectedServer; ClientThread = new Thread(ClientListening); ClientThread.IsBackground = true; ClientSocket = clientSocket; ClientIep = (IPEndPoint)clientSocket.RemoteEndPoint; ClientStream = new NetworkStream(ClientSocket); ClientReader = new StreamReader(ClientStream); ClientWriter = new StreamWriter(ClientStream); ClientConnected = true; ClientThread.Start(); }
public Server() { try { server = new TcpListener(IPAddress.Loopback, 7088); server.Start(); Console.WriteLine("Game Server Started ............."); Console.WriteLine("Waiting For Player ............."); counter = 0; while (true) { counter++; connection = server.AcceptTcpClient(); Console.WriteLine("New player ID: " + counter + " has joined the game."); ServerHandler playerthread = new ServerHandler(connection, server, counter); new Thread(playerthread.run).Start(); connections.Add(playerthread); } } catch (IOException e) { Console.WriteLine(e); } }
public LaunchedServer() { InitializeComponent(); //Starts server config modal, if everything is OK then it instantiates the server //and sets click event for server message send button. ServerLoadForm slf = new ServerLoadForm(); startRes = slf.ShowDialog(); if (startRes == DialogResult.OK) { server = new ServerHandler(false, slf.welcomeTxt.Text, Convert.ToInt32(slf.portNumeric.Value), Convert.ToInt32(slf.clientsNumeric.Value), chatTxt, msgTxt, clientsLView, ipTxt, portTxt, nameTxt, this); btnSend.Click += new EventHandler(server.BtnSend_Click); slf.Dispose(); slf = null; //Sets ListView properties ImageList imgList = new ImageList(); imgList.Images.Add(Properties.Resources.Client); clientsLView.LargeImageList = imgList; clientsLView.SmallImageList = imgList; clientsLView.StateImageList = imgList; chatTxt.ScrollBars = ScrollBars.Vertical; //Set events for buttons clientsLView.SelectedIndexChanged += new EventHandler(server.ClientsLView_SelectedIndexChanged); btnClose.Click += new EventHandler(server.BtnClose_Click); btnKickAll.Click += new EventHandler(server.BtnKickAll_Click); btnKick.Click += new EventHandler(server.BtnKick_Click); } }
private void serverConfigurationToolStripMenuItem_Click(object sender, EventArgs e) { ServerHandler serverHandler = new ServerHandler(); serverHandler.Show(); }