- insomniaserver_src.zip
- insomniaserver_doc.zip
- Documentation.chm
- insomniaserver_demo.zip
- doc
- CollapseAll.gif
- Collapsed.gif
- ExpandAll.gif
- Expanded.gif
- html
- icons
- alert_caution.gif
- alert_note.gif
- alert_security.gif
- Caution.gif
- CFW.gif
- collall.gif
- collapse_all.gif
- copycode.gif
- copycodeHighlight.gif
- drpdown.gif
- drpdown_orange.gif
- exp.gif
- expall.gif
- expand_all.gif
- footer.gif
- LastChild.gif
- privclass.gif
- privdelicate.gif
- privenum.gif
- privevent.gif
- privfield.gif
- privinterface.gif
- privmethod.gif
- privproperty.gif
- privstructure.gif
- protclass.gif
- protdeligate.gif
- protenum.gif
- protevent.gif
- protfield.gif
- protinterface.gif
- protmethod.gif
- protoperator.gif
- protproperty.gif
- protstructure.gif
- pubclass.gif
- pubdelegate.gif
- pubenum.gif
- pubevent.gif
- pubfield.gif
- pubinterface.gif
- pubmethod.gif
- puboperator.gif
- pubproperty.gif
- pubstructure.gif
- security.gif
- static.gif
- Index.html
- InsomniaServer.jpg
- Item.gif
- LastBuild.log
- Licence.html
- scripts
- styles
- SyncTOC.gif
- TOC.css
- TOC.html
- TOC.js
- Tutorial 1.html
- Tutorial 2.html
- Tutorial 3.html
- Welcome.html
- examples
- MultiPaint
- SystemBrowser (using HtmlSource)
- SystemBrowser
- Tutorial 1 - InitializeIS
- Tutorial 2 - PopulateTheServer
- Tutorial 3 - SimpleLogin
|
//All code is copyright � 2007, InsomniaSoftware | Manuel Then, All rights reserved.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace InsomniaSoftware.Server
{
sealed class EndPointListener : IDisposable
{
#region Public variables
public IPEndPoint endPoint
{
get
{
return (IPEndPoint)socket.LocalEndPoint;
}
}
#endregion
#region Private variables
InsomniaServer server;
bool listening = false;
Thread listenThread;
Socket socket = null;
#endregion
public EndPointListener(InsomniaServer server, IPEndPoint localEndPoint)
{
if (server == null)
throw new Exception("No server handle passed to the constructor");
if (localEndPoint == null)
throw new Exception("No local end point passed to the constructor");
this.server = server;
try
{
socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
socket.Bind(localEndPoint);
}
catch
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
socket.Bind(localEndPoint);
}
socket.Listen(10);
}
public void Dispose()
{
Stop(500);
if (socket != null)
{
if (socket.Connected)
socket.Disconnect(false);
socket = null;
}
}
public void Start()
{
lock (this)
{
if (!listening)
{
listening = true;
listenThread = new Thread(ListenThread);
listenThread.Start();
}
}
}
public void Stop(int maxWaitTime)
{
try
{
lock(this)
listening = false;
listenThread.Join(maxWaitTime);
if (listenThread.ThreadState == ThreadState.Running)
listenThread.Abort();
}
catch { }
}
void ListenThread()
{
while (listening)
{
try
{
while (socket.Poll(0, SelectMode.SelectRead))
{
ExtendedSocket listenSocket = ExtendedSocket.FromSocket(socket.Accept());
HttpConnection httpConnection = new HttpConnection(server, listenSocket);
}
Thread.Sleep(20);
}
catch { }
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I was born in 1987. Unfortunately too late to experience the real rise of the PC. But fortunately late enough to enjoy things like MS's .net during my school time
From the time when some relative taught me a little BASIC under MS DOS, I loved to tell computers what to do - even though my real start in programming was around the age of 16.
At the moment, I am studying Software Engineering at University of Augsburg, always hoping to find time to design and program.
Besides, I like meeting friends, spent time with my girlfriend and enjoy life