Advertisement
Guest User

C# -> SmileNet Bridge

a guest
Oct 7th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 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.Net;
  7. using System.Net.Sockets;
  8.  
  9. namespace TCPIP_TEST
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             byte[] ip = { 192, 168, 0, 16 };
  16.             IPAddress addr = new IPAddress(ip);
  17.             IPEndPoint point = new IPEndPoint(addr, (4950));
  18.             byte[] dataarray = { 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  19.             Send(dataarray, point);
  20.             System.Threading.Thread.Sleep(10000);
  21.         }
  22.  
  23.  
  24.         public static void Send(byte[] rawData, IPEndPoint target)
  25.         {
  26.             // change what you pass to this constructor to your needs
  27.             Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  28.  
  29.             try
  30.             {
  31.                 s.SendBufferSize = 20;
  32.                 s.Connect(target);
  33.                 s.Send(rawData);
  34.                
  35.                 if (s.Connected) { Console.WriteLine("Connected succesfully"); }else
  36.                 {
  37.                     Console.WriteLine("Could not connect to target address");
  38.                 }
  39.  
  40.                 for (int i =0; i<1000; i++)
  41.                 {
  42.                     s.Send(rawData);
  43.  
  44.  
  45.                 }
  46.             }
  47.             catch (Exception ex)
  48.             {
  49.                 Console.WriteLine("An exception of type " + ex.ToString() + " has occured");
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement