Example #1
0
 void ReadData(ClientInfo ci, String text)
 {
     Console.WriteLine("Received from " + ci.ID + ": " + text);
     if (text[0] == '!')
         server.Broadcast(Encoding.UTF8.GetBytes(text));
     else ci.Send(text);
 }
Example #2
0
 void SendResponse(ClientInfo ci, HttpRequest req, HttpResponse resp, bool close)
 {
     #if DEBUG
     Console.WriteLine("Response: "+resp.ReturnCode + Responses[resp.ReturnCode]);
     #endif
     ByteBuilder bb = new ByteBuilder();
     bb.Add(Encoding.UTF8.GetBytes("HTTP/1.1 " + resp.ReturnCode + " " + Responses[resp.ReturnCode] +
             "\r\nDate: "+DateTime.Now.ToString("R")+
             "\r\nServer: RedCoronaEmbedded/1.0"+
             "\r\nConnection: "+(close ? "close" : "Keep-Alive")));
     bb.Add(Encoding.UTF8.GetBytes("\r\nContent-Encoding: " + (resp.Encoding == null ? "utf-8" : resp.Encoding)));
     if (resp.RawContent == null)
         bb.Add(Encoding.UTF8.GetBytes("\r\nContent-Length: " + resp.Content.Length));
     else
         bb.Add(Encoding.UTF8.GetBytes("\r\nContent-Length: " + resp.RawContent.Length));
     if(resp.ContentType != null)
         bb.Add(Encoding.UTF8.GetBytes("\r\nContent-Type: "+resp.ContentType));
     if(req.Session != null) bb.Add(Encoding.UTF8.GetBytes("\r\nSet-Cookie: _sessid="+req.Session.ID+"; path=/"));
     foreach(KeyValuePair<string, string> de in resp.Header) bb.Add(Encoding.UTF8.GetBytes("\r\n" + de.Key + ": " + de.Value));
     bb.Add(Encoding.UTF8.GetBytes("\r\n\r\n")); // End of header
     if(resp.RawContent != null) bb.Add(resp.RawContent);
     else bb.Add(Encoding.UTF8.GetBytes(resp.Content));
     ci.Send(bb.Read(0, bb.Length));
     #if DEBUG
     Console.WriteLine("** SENDING\n"+resp.Content);
     #endif
     if(close) ci.Close();
 }