-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.cs
52 lines (46 loc) · 1.41 KB
/
listener.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Andreas Hansson 2013
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace locurl
{
public class HServer
{
public Form1 ff;
public string lastip, ip;
TcpListener listener;
volatile bool portchanged = false;
public HServer(Form1 f, string ip)
{
this.ip = ip;
this.ff = f;
}
public void listen()
{
while (true)
{
portchanged = false;
listener = new TcpListener(IPAddress.Any, Convert.ToInt32(settingsg.port));
listener.Start();
while (!portchanged)
{
TcpClient s = listener.AcceptTcpClient();
lastip = ((IPEndPoint)s.Client.RemoteEndPoint).Address.ToString();
//if (lastip.StartsWith("127") || lastip.StartsWith("192.168"))
{
hpr p = new hpr(s, this);
new Thread(new ThreadStart(p.process)).Start();
}
//else
{
//s.Close();
//ff.append(String.Format("{1}- Rejected external client {0}", lastip, DateTime.Now));
}
}
listener.Stop();
}
}
}
}