TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ivan Climov
1.1k
692
22.4k
How to transfer data from the third-level class ?
Jul 9 2019 3:44 AM
I need to transfer the data from HTTPServer toWinForm. I use HTTPServer (https://github.com/jeske/SimpleHttpServer)
I transferred the project SimpleHttpServer (https://github.com/jeske/SimpleHttpServer/tree/master/SimpleHttpServer) in your project WinForm. I run HTTPServer with the following code. Code.
private
void
Form1_Load(
object
sender, EventArgs e)
{
StartHttpServer();
}
static
void
StartHttpServer()
{
try
{
var route_config =
new
List
();
HttpServer httpServer =
new
HttpServer(8080, route_config);
Thread thread =
new
Thread(
new
ThreadStart(httpServer.Listen));
thread.Start();
}
catch
(Exception ex)
{
string
s = ex.Message;
string
t = ex.StackTrace;
// throw;
MessageBox.Show(s +
" \r\n "
+
t);
}
}
If the server receives a POST request with JSON, then the request comes in the class HttpProcessor.cs method HandleClient.
Code
public
void
HandleClient(TcpClient tcpClient)
{
Stream inputStream = GetInputStream(tcpClient);
Stream outputStream = GetOutputStream(tcpClient);
HttpRequest request = GetRequest(inputStream, outputStream);
#region ??? ?????????.
// string s = request.
RequestContent?.Invoke(request);
#endregion
// ????????? ? ?????????? ??????... (route and handle the request...)
HttpResponse response = RouteRequest(inputStream, outputStream, request);
// *
// Console.WriteLine("{0} {1}",response.StatusCode,request.Url);
// ????????? ????? ?? ????????? ??? ?????? (build a default response for errors)
if
(response.Content ==
null
)
{
if
(response.StatusCode !=
"200"
)
{
response.ContentAsUTF8 =
string
.Format(
"{0} {1}
{2}"
, response.StatusCode, request.Url, response.ReasonPhrase);
}
}
WriteResponse(outputStream, response);
outputStream.Flush();
outputStream.Close();
outputStream =
null
;
inputStream.Close();
inputStream =
null
;
}
To get JSON from the HttpProcessor.cs class method HandleClient.
I plan to use the public event Action RequestContent;.
Code
public
event
Action
RequestContent;
public
void
HandleClient(TcpClient tcpClient)
{
// ....
RequestContent?.Invoke(request);
// ....
}
Question
1. How to transfer data from the third-level class (the HttpProcessor.cs class) to the first-level class (the WinForm class)?
2. How are there other solutions to replace using the public event Action RequestContent;?
Reply
Answers (
1
)
ArcObject using #c integrated with Network ericssion (NE)
how can i Export Gridview to pdf form with use Enable paging