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.

140 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: 0x02000005 RID: 5
public class AsynchronousSocketListenerSMS
{
// Token: 0x17000007 RID: 7
// (get) Token: 0x0600000F RID: 15 RVA: 0x00002B4E File Offset: 0x00000D4E
// (set) Token: 0x06000010 RID: 16 RVA: 0x00002B55 File Offset: 0x00000D55
public static int Port { get; set; }
// Token: 0x17000008 RID: 8
// (get) Token: 0x06000011 RID: 17 RVA: 0x00002B5D File Offset: 0x00000D5D
// (set) Token: 0x06000012 RID: 18 RVA: 0x00002B64 File Offset: 0x00000D64
public static string IPAddress { get; set; }
// Token: 0x14000001 RID: 1
// (add) Token: 0x06000013 RID: 19 RVA: 0x00002B6C File Offset: 0x00000D6C
// (remove) Token: 0x06000014 RID: 20 RVA: 0x00002BA0 File Offset: 0x00000DA0
// [DebuggerBrowsable(DebuggerBrowsableState.Never)]
public static event EventHandler Received;
// Token: 0x06000015 RID: 21 RVA: 0x00002BD3 File Offset: 0x00000DD3
public AsynchronousSocketListenerSMS(string ipaddress, int port)
{
AsynchronousSocketListenerSMS.IPAddress = ipaddress;
AsynchronousSocketListenerSMS.Port = port;
}
// Token: 0x06000016 RID: 22 RVA: 0x00002BEC File Offset: 0x00000DEC
protected static void OnReceived(string s, EventArgs e)
{
bool flag = AsynchronousSocketListenerSMS.Received != null;
if (flag)
{
AsynchronousSocketListenerSMS.Received(s, e);
}
}
// Token: 0x06000017 RID: 23 RVA: 0x00002C14 File Offset: 0x00000E14
public static void StartListening()
{
byte[] array = new byte[150000000];
string hostName = Dns.GetHostName();
Debug.WriteLine("Server socket IP is: " + AsynchronousSocketListenerSMS.IPAddress.ToString());
IPHostEntry iphostEntry = Dns.Resolve(AsynchronousSocketListenerSMS.IPAddress.ToString());
IPAddress address = iphostEntry.AddressList[0];
IPEndPoint localEP = new IPEndPoint(address, AsynchronousSocketListenerSMS.Port);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
socket.Bind(localEP);
socket.Listen(10);
for (;;)
{
AsynchronousSocketListenerSMS.allDone.Reset();
Debug.WriteLine("Waiting for Clients...");
socket.BeginAccept(new AsyncCallback(AsynchronousSocketListenerSMS.AcceptCallback), socket);
AsynchronousSocketListenerSMS.allDone.WaitOne();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine("\nPress ENTER to continue...");
Console.Read();
}
// Token: 0x06000018 RID: 24 RVA: 0x00002D08 File Offset: 0x00000F08
public static void AcceptCallback(IAsyncResult ar)
{
AsynchronousSocketListenerSMS.allDone.Set();
Socket socket = (Socket)ar.AsyncState;
Socket socket2 = socket.EndAccept(ar);
StateObjectSMS stateObjectSMS = new StateObjectSMS();
stateObjectSMS.workSocket = socket2;
socket2.BeginReceive(stateObjectSMS.buffer, 0, 20480, SocketFlags.None, new AsyncCallback(AsynchronousSocketListenerSMS.ReadCallback), stateObjectSMS);
}
// Token: 0x06000019 RID: 25 RVA: 0x00002D64 File Offset: 0x00000F64
public static void ReadCallback(IAsyncResult ar)
{
string text = string.Empty;
StateObjectSMS stateObjectSMS = (StateObjectSMS)ar.AsyncState;
Socket workSocket = stateObjectSMS.workSocket;
int num = workSocket.EndReceive(ar);
bool flag = num > 0;
if (flag)
{
stateObjectSMS.sb.Append(Encoding.ASCII.GetString(stateObjectSMS.buffer, 0, num));
text = stateObjectSMS.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);
AsynchronousSocketListenerSMS.OnReceived(text, EventArgs.Empty);
}
else
{
workSocket.BeginReceive(stateObjectSMS.buffer, 0, 20480, SocketFlags.None, new AsyncCallback(AsynchronousSocketListenerSMS.ReadCallback), stateObjectSMS);
}
}
}
// Token: 0x0600001A RID: 26 RVA: 0x00002E48 File Offset: 0x00001048
private static void Send(Socket handler, string data)
{
byte[] bytes = Encoding.ASCII.GetBytes(data);
handler.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, new AsyncCallback(AsynchronousSocketListenerSMS.SendCallback), handler);
}
// Token: 0x0600001B RID: 27 RVA: 0x00002E7C File Offset: 0x0000107C
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: 0x0400000E RID: 14
public static ManualResetEvent allDone = new ManualResetEvent(false);
}
}