Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.Threading.Tasks;
  4. using System.Net.Sockets;
  5. using System.Timers;
  6. using System.Text;
  7.  
  8. namespace Roleplay_Flash_Server.assets.communication.client.events
  9. {
  10.     class pingIntervalEvent
  11.     {
  12.         private static string prefix = "[communication->client->events->pingIntervalEvent.cs] ";
  13.  
  14.         public static void init(TcpClient socket)
  15.         {
  16.             Byte[] replyData = System.Text.Encoding.ASCII.GetBytes("PingIntervalEvent{}");
  17.             socket.GetStream().Write(replyData, 0, replyData.Length);
  18.  
  19.             string clientIP = ((IPEndPoint)socket.Client.RemoteEndPoint).Address.ToString();
  20.             string clientPort = ((IPEndPoint)socket.Client.RemoteEndPoint).Port.ToString();
  21.  
  22.             Console.WriteLine(prefix + "Ping Interval Event was ran for {#" + "?" + "}, {" + clientIP + ":" + clientPort + "}.");
  23.             if (socket.Connected == false)
  24.             {
  25.                 Console.WriteLine(prefix + "Ping Interval Event has responded as a failure for {#" + "?" + "}, {" + clientIP + ":" + clientPort + "}; Aborting connection...");
  26.                 socket.Close();  
  27.             }
  28.            else
  29.                 Console.WriteLine(prefix + "Ping Interval Event has responded as a success for {#" + "?" + "}, {" + clientIP + ":" + clientPort + "}.");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement