Subversion Repositories HomeAutomation

Rev

Rev 452 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 452 Rev 460
Line 1... Line 1...
1
using System;
1
using System;
2
using System.Net;
2
using System.Net;
-
 
3
//using System.Net.;
3
using System.Net.Sockets;
4
using System.Net.Sockets;
4
using System.Text;
5
using System.Text;
5
using System.Threading;
6
using System.Threading;
6
using System.Collections;
7
using System.Collections;
7
using System.IO;
8
using System.IO;
Line 15... Line 16...
15
   
16
   
16
    private Queue tcpPackets = Queue.Synchronized(new Queue());
17
    private Queue tcpPackets = Queue.Synchronized(new Queue());
17
   
18
   
18
    public TcpServer(int port) {
19
    public TcpServer(int port) {
19
        running = true;
20
        running = true;
-
 
21
        listener = new TcpListener(IPAddress.Parse("127.0.0.1"),port);
20
        listener = new TcpListener(port);
22
        //listener = new TcpListener(port);
21
        listener.Start();
23
        listener.Start();
22
        this.port = port;
24
        this.port = port;
23
        clients = new ArrayList();
25
        clients = new ArrayList();
24
    }
26
    }
25
 
27
 
Line 62... Line 64...
62
                    break;
64
                    break;
63
                }
65
                }
64
            }
66
            }
65
           
67
           
66
            if (running && listener.Pending()) {
68
            if (running && listener.Pending()) {
67
                if (DEBUG_LEVEL>1) { Console.WriteLine("Client connected on port {0}", port); }
-
 
68
                TcpClient handler = listener.AcceptTcpClient();
69
                TcpClient handler = listener.AcceptTcpClient();
69
                Connection newconn = new Connection(handler);
70
                Connection newconn = new Connection(handler);
70
                clients.Add(newconn);
71
                clients.Add(newconn);
71
                Thread t = new Thread(newconn.thread);
72
                Thread t = new Thread(newconn.thread);
72
                t.Start();
73
                t.Start();
-
 
74
                EndPoint ipend = handler.Client.RemoteEndPoint;
-
 
75
                string sipend = ipend.ToString();
-
 
76
                //string sipend = IPAddress.Parse(handler.Client.RemoteEndPoint.Address.ToString());
-
 
77
                if (DEBUG_LEVEL>1) { Console.WriteLine("Client {0} connected on port {1}",sipend ,port); }
73
            }
78
            }
74
        }
79
        }
75
    }
80
    }
76
   
81
   
77
    public void stop() {
82
    public void stop() {