Advertisement
Guest User

darkserver2

a guest
Jul 13th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. try
  2. {
  3.     $clientList = New-Object System.Collections.ArrayList
  4.     $server = [System.Net.Sockets.TcpListener]12345
  5.     $Server.Start()
  6.  
  7.     while ($server.Active -eq $True)
  8.     {
  9.         if($server.Pending() -eq $False)
  10.             {
  11.                 Update_ClientList($clientList)
  12.             }
  13.             else
  14.             {
  15.                 $client = $server.AcceptTcpClient()
  16.             $clientList.Add($client)
  17.             }
  18.     }
  19. }
  20. catch
  21. {
  22.     # Code to handle errors here
  23. }
  24.  
  25. function Update_ClientList
  26. {
  27.     param ([System.Collections.ArrayList] $ClientList)
  28.  
  29.     foreach ($client in $ClientList)
  30.     {
  31.         if ($client.Available -gt 0)
  32.         {
  33.             # Data is available on this client
  34.             # Code to read/process the data goes here
  35.         }  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement