0
我正在嘗試偵聽網絡上的活動端口。我試過HttpListener,但我不確定這是否是正確的監聽者。任何想法或例子?c上的網絡端口偵聽器#
using (m_listener = new HttpListener())
{
m_listener.Prefixes.Add("http://*:8080/");
m_listener.Start();
while (m_listener.IsListening)
{
HttpListenerContext context = m_listener.GetContext();
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
textBox1.Text += request.RawUrl + "\r\n";
textBox1.Text += request.UserHostName + "\r\n"; }
m_listener.Stop();
}
顯示一些代碼,請...細說你真正想要使用,實現... – Yahia
(m_listener =新HttpListener()) \t \t \t { \t \t \t \t m_listener.Prefixes.Add(「HTTP: // *:8080 /「); \t \t \t \t m_listener.Start(); \t \t \t \t而(m_listener.IsListening) \t \t \t \t { \t \t \t \t HttpListenerContext上下文= m_listener.GetContext(); \t \t \t \t HttpListenerRequest request = context.Request; \t \t \t \t HttpListenerResponse response = context.Response; \t \t \t \t textBox1.Text + = request.RawUrl +「\ r \ n」; \t \t \t \t textBox1.Text + = request.UserHostName +「\ r \ n」; \t \t \t \t} \t \t \t \t m_listener.Stop(); \t \t \t} –
它是什麼,你想實現?建立一個Web服務器(這就是HttpListener的用途)?你看到什麼問題/錯誤消息/異常? – Yahia