iMonitor desktop application using dotnet 4.8
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.8 KiB

using System;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace iMonitorApp
{
// Token: 0x0200001F RID: 31
public class AsynchronousSocketListener
{
// Token: 0x1700001F RID: 31
// (get) Token: 0x060000E5 RID: 229 RVA: 0x0000A24C File Offset: 0x0000844C
// (set) Token: 0x060000E6 RID: 230 RVA: 0x0000A253 File Offset: 0x00008453
public static int Port { get; set; }
// Token: 0x17000020 RID: 32
// (get) Token: 0x060000E7 RID: 231 RVA: 0x0000A25B File Offset: 0x0000845B
// (set) Token: 0x060000E8 RID: 232 RVA: 0x0000A262 File Offset: 0x00008462
public static string IPAddress { get; set; }
// Token: 0x14000003 RID: 3
// (add) Token: 0x060000E9 RID: 233 RVA: 0x0000A26C File Offset: 0x0000846C
// (remove) Token: 0x060000EA RID: 234 RVA: 0x0000A2A0 File Offset: 0x000084A0
// [DebuggerBrowsable(DebuggerBrowsableState.Never)]
public static event EventHandler Received;
// Token: 0x060000EB RID: 235 RVA: 0x0000A2D3 File Offset: 0x000084D3
public AsynchronousSocketListener(string ipaddress, int port)
{
AsynchronousSocketListener.IPAddress = ipaddress;
AsynchronousSocketListener.Port = port;
}
// Token: 0x060000EC RID: 236 RVA: 0x0000A2EC File Offset: 0x000084EC
protected static void OnReceived(string s, EventArgs e)
{
bool flag = AsynchronousSocketListener.Received != null;
if (flag)
{
AsynchronousSocketListener.Received(s, e);
}
}
// Token: 0x060000ED RID: 237 RVA: 0x0000A314 File Offset: 0x00008514
public static void StartListening()
{
byte[] array = new byte[150000000];
string hostName = Dns.GetHostName();
Debug.WriteLine("Server socket IP is: " + AsynchronousSocketListener.IPAddress.ToString());
IPHostEntry iphostEntry = Dns.Resolve(AsynchronousSocketListener.IPAddress.ToString());
IPAddress address = iphostEntry.AddressList[0];
IPEndPoint localEP = new IPEndPoint(address, AsynchronousSocketListener.Port);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
socket.Bind(localEP);
socket.Listen(10);
for (;;)
{
AsynchronousSocketListener.allDone.Reset();
Debug.WriteLine("Waiting for Clients...");
socket.BeginAccept(new AsyncCallback(AsynchronousSocketListener.AcceptCallback), socket);
AsynchronousSocketListener.allDone.WaitOne();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine("\nPress ENTER to continue...");
Console.Read();
}
// Token: 0x060000EE RID: 238 RVA: 0x0000A408 File Offset: 0x00008608
public static void AcceptCallback(IAsyncResult ar)
{
AsynchronousSocketListener.allDone.Set();
Socket socket = (Socket)ar.AsyncState;
Socket socket2 = socket.EndAccept(ar);
StateObject stateObject = new StateObject();
stateObject.workSocket = socket2;
socket2.BeginReceive(stateObject.buffer, 0, 20480, SocketFlags.None, new AsyncCallback(AsynchronousSocketListener.ReadCallback), stateObject);
}
// Token: 0x060000EF RID: 239 RVA: 0x0000A464 File Offset: 0x00008664
public static void ReadCallback(IAsyncResult ar)
{
string text = string.Empty;
StateObject stateObject = (StateObject)ar.AsyncState;
Socket workSocket = stateObject.workSocket;
int num = workSocket.EndReceive(ar);
bool flag = num > 0;
if (flag)
{
stateObject.sb.Append(Encoding.ASCII.GetString(stateObject.buffer, 0, num));
text = stateObject.sb.ToString();
bool flag2 = text.IndexOf("<EOF>") > -1;
if (flag2)
{
Console.WriteLine("Read {0} bytes from socket (sender:" + workSocket.RemoteEndPoint.ToString() + "). \n Data : {1}", text.Length, text);
Debug.WriteLine(text);
AsynchronousSocketListener.OnReceived(text, EventArgs.Empty);
}
else
{
workSocket.BeginReceive(stateObject.buffer, 0, 20480, SocketFlags.None, new AsyncCallback(AsynchronousSocketListener.ReadCallback), stateObject);
}
}
}
// Token: 0x060000F0 RID: 240 RVA: 0x0000A548 File Offset: 0x00008748
private static void Send(Socket handler, string data)
{
byte[] bytes = Encoding.ASCII.GetBytes(data);
handler.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, new AsyncCallback(AsynchronousSocketListener.SendCallback), handler);
}
// Token: 0x060000F1 RID: 241 RVA: 0x0000A57C File Offset: 0x0000877C
private static void SendCallback(IAsyncResult ar)
{
try
{
Socket socket = (Socket)ar.AsyncState;
int num = socket.EndSend(ar);
Console.WriteLine("Sent {0} bytes to client.", num);
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
// Token: 0x040000B2 RID: 178
public static ManualResetEvent allDone = new ManualResetEvent(false);
}
}