sakiir

Test Client/Server

Oct 14th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Threading;
  7. using System.Net;
  8. using System.Net.Sockets;
  9.  
  10. namespace server
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             TcpListener s = new TcpListener(5555);
  17.             TcpClient[] c = new TcpClient[50];
  18.                  
  19.             int i = 0;
  20.             s.Start();
  21.             Console.WriteLine("Serveur Started !..");
  22.             while (true)
  23.             {
  24.                 if (i == 50) i = 0;
  25.                 c[i] = s.AcceptTcpClient();
  26.                 Console.WriteLine("[ "+((IPEndPoint)c[i].Client.RemoteEndPoint).Address.ToString()+" ] Connected !");
  27.                 ThreadStart startter = () => g_client(c[i], c);
  28.                 Thread t = new Thread(startter);
  29.                 t.Start();
  30.                 i++;
  31.             }
  32.  
  33.         }
  34.  
  35.         public static void g_client(TcpClient client,TcpClient[] tclient)
  36.         {
  37.             NetworkStream ns = client.GetStream();
  38.             NetworkStream ns2;
  39.             byte[] data = new byte[1024];
  40.             while (true)
  41.             {
  42.                 data = new byte[1024];
  43.                 if (ns.Read(data, 0, data.Length) != 0)
  44.                 {
  45.                     for (int i = 0; i != 50; i++)
  46.                     {
  47.                         ns2 = tclient[i].GetStream();
  48.                         ns2.Write(data, 0, data.Length);
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment