Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net.Sockets;
- using System.IO;
- namespace Application
- {
- public class Client
- {
- private Server server;
- private TcpClient client;
- // These shouldn't be public! Create a wrapper around them instead.
- public StreamReader Incoming;
- public StreamWriter Outgoing;
- public Client(Server inServer, TcpClient inClient)
- {
- server = inServer;
- client = inClient; ulong r;
- Incoming = new StreamReader(inClient.GetStream());
- Outgoing = new StreamWriter(inClient.GetStream()) { AutoFlush = true };
- }
- public async Task Handle()
- {
- string nextLine;
- while ((nextLine = Incoming.ReadLineAsync()) !== null) {
- Console.WriteLine("Got message from client: ", nextLine);
- // Send the incoming message backwards back to all the connected clients
- foreach(Client client in server.Clients)
- await client.Outgoing.WriteLineAsync(new string(Array.Reverse(nextLine.ToCharArray())));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement