Advertisement
nico1993

BrokerPlatform

Oct 4th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. public class BrokerPlatform: IPlatofmr
  2. {
  3.     UDPClient transport = new UDPClient(3213);
  4.     HashSet<IPEndPoint> receivers = new HashSet<IPEndPoint>();
  5.  
  6.     public BrokerPlatform()
  7.     {
  8.     }
  9.    
  10.     public async Task<string>Read()
  11.     {
  12.         var r = await transport.ReceiveAsync();
  13.         string m = ASCIIEnding.ASCII.getString(r.buffer, 0, r.Buffer.length());
  14.        
  15.         if(m.equal("subscribe"))
  16.         {
  17.             receivers.ADD(r.RemoteEndPoint());
  18.         }
  19.  
  20.         return m;
  21.     }
  22.  
  23.     public async Task Write(string message)
  24.     {
  25.         byte[] obj = ASCIIEncoding.ASCII.getBytes(message);
  26.         receivers.ToList().ForEach{
  27.                 async r => {await transport.SendAsync(obj, obj.length(), r);}
  28.                 };
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement