我们重新开发“NET”CF 3.5应用程序,用于“Windows Embedded CE 6 plattform”。 我们重新努力使用一个小型网络服务器(HTTP 1.0)。 该网络应提供网络应用,并回应简单的教育、科学和技术要求。
Our implementation follows the pattern shown in this MSDN article: http://msdn.microsoft.com/en-us/library/aa446537.aspx. We use a TCP listening socket, async-callbacks in combination with BeginAccept, EndAccept, BeginRecieve and EndReceive.
An incoming connection on the listening port is handled by an asynchronous accept callback. (see http://msdn.microsoft.com/en-us/library/5bb431f9.aspx). By calling the EndAccept method, within this asynchronous accept callback, we tell the listening port to hand the connection to a new socket and free the port, so that new incoming connection requests can be accepted by the listening port. The already accepted request is processed in an own thread with (because it is processed in the async callback).
我们已经尝试尽量减少从BeginAccept到En Accept之间的时间。 由于在呼吁BeginAccept和EnAccept这段时期,即将提出的联系请求被列入积压的听众名单。 可以通过所谓的积压参数对电梯长度进行配置,而这一参数的配对率最高。 如果积压的询问已经用尽,新的电离线要求将在三维线之间被拒绝(Client/Browser作为回应收到一份区域数据表)。
现在,我们把这个问题推向了结,大多数现代浏览器,如:Edre、Acre、Sato,例如,使用最多15(或更多)的并行连接,把数据从服务器上载。 每一条同时连接的数量 东道方可在以下几个方面配置:组合——和;网络。 当装上一页时,浏览器根据需要装上的资源数量(如图像、javascript或cs文档)确定必要时可连接15条。
The .NET CF socket.listen method (see http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.listen.aspx) allows the definition of a backlog number.
From our understanding we should have a backlog greater then 15 e.g. 20 or so, because all connection requests are triggered at the same time by the browser, so our small webserver got hit by 15 simultaneous connections requests. A too small backlog queue size, results in aborted TCP connections, because not all incoming connections can be queue until the listening socket can accept them all. In Firebug or Chrome, these requests are shown as "aborted".
So we increased the backlog in our case by socket.listen(20) to 20 and hoped that everything would be fine and ready to withstand even the greediest browsers.
问题在于,单列车上的积压参数(名单上的)只字未提给SOMAXXCON(就我们而言,最多是5条连接)。 之后再设定一定数量,没有效果。 当浏览器建立16个同时的袖珍连接点时,有些会丢失,因为有些袖珍材料根本不适于5个积压点,而TCP连接则从网络服务器获得TCP-RST,有些资源在网页上缺失。
Is there any way to change the SOMAXXCON in Windows Embedded CE 6.0? (We re able to change the plattform image - utilize plattform builder). Or is there an error in our understanding of that matter?
We ve attached the source code that we re currently using:
public class StateObject
{
// Client socket.
public Socket workSocket = null;
// Size of receive buffer.
public const int BufferSize = 1024;
// Receive buffer.
public byte[] buffer = new byte[BufferSize];
// Received data string.
public StringBuilder sb = new StringBuilder();
}
public void StartListening()
{
logger.Debug("Started Listening at : " + this.listeninghostIp + ":" + this.listeningport);
IPEndPoint localEP = new IPEndPoint(IPAddress.Parse(this.listeninghostIp), Convert.ToInt32(this.listeningport));
listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
listener.Bind(localEP);
listener.Listen(10);
ThreadPool.QueueUserWorkItem(new WaitCallback(CheckForConnections) );
}
public void CheckForConnections()
{
try
{
logger.Debug("listening successfully started! Waiting for incoming connections...");
listener.BeginAccept(new AsyncCallback(acceptCallback), listener);
}
catch (Exception ex)
{
logger.Error("Exception Occured while starting Listening : " + ex.Message.ToString());
}
}
private void acceptCallback(IAsyncResult ar)
{
try
{
Socket listener = (Socket)ar.AsyncState;
listener.BeginAccept(new AsyncCallback(acceptCallback), listener);
Socket handler = listener.EndAccept(ar);
StateObject state = new StateObject();
state.workSocket = handler;
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReadCallback), state);
logger.Debug("listening socket accepted connection...");
}
catch (Exception ex)
{
logger.Error("Error on acceptCallback. Error: " + ex.Message);
}
public void ReadCallback(IAsyncResult ar)
{
String content = String.Empty;
StateObject state = (StateObject)ar.AsyncState;
Socket handler = state.workSocket;
int bytesRead = handler.EndReceive(ar);
if (bytesRead > 0)
{
state.sb.Append(Encoding.ASCII.GetString(
state.buffer, 0, bytesRead));
}
ClientConnectionFactory.createConnection(ar.AsyncState);
}