没有这样的主机是已知的套接字连接 [英] No such host is known socket connection

查看:89
本文介绍了没有这样的主机是已知的套接字连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此库进行telnet连接。我已经正确调用了该函数,并且该函数执行了以下代码,但未能给出以下错误:

I'm trying to work with this library for telnet connections. I have called the function correctly and it executes the code below but fails giving the following error:

System.Net.Sockets.SocketException was unhandled
  HResult=-2147467259
  Message=No such host is known
  Source=System
  ErrorCode=11001
  NativeErrorCode=11001
  StackTrace:
       at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)
       at MinimalisticTelnet.TelnetConnection..ctor(String Hostname, Int32 Port) in c:\users\kylec\documents\visual studio 2010\Projects\Mail Server Capture\Mail Server Capture\TelnetInterface.cs:line 36
       at Mail_Server_Capture.Form1.btn_MailGet_Click(Object sender, EventArgs e) in c:\users\kylec\documents\visual studio 2010\Projects\Mail Server Capture\Mail Server Capture\Form1.cs:line 55
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Mail_Server_Capture.Program.Main() in c:\users\kylec\documents\visual studio 2010\Projects\Mail Server Capture\Mail Server Capture\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

代码:

public TelnetConnection(string Hostname, int Port)
        {
            tcpSocket = new TcpClient(Hostname, Port);

        }

我在这里搜索了这个问题,看起来很漂亮共同。有人说主机确实是无法访问的(不是这种情况),它是Microsoft .NET问题,或者只是可以忽略的异常。尽管它可以忽略,但似乎无法让程序通过它。对于修复它,我似乎也找不到任何解决方案。我对这件事很迷失,将不胜感激。

I have searched here looking for this problem and it seems pretty common. Some people are saying the host truly is unreachable (this is not the case), its a Microsoft .NET problem or its just an exception that can be ignored. I can't seem to get the program to pass it though if it is something that can be ignored. I also can't seem to find any solutions as to fixing it. I'm pretty lost on this one, any help would be appreciated.

推荐答案

解决方案非常简单,却被忽略了。首先,我注意到tcpclient更喜欢ip地址而不是名称。然后我还意识到,有时域名的两边都有多余的空格。因此,我使用下面的代码剥离字符并将其更改为ip。

The solution was something quite easy and overlooked. First I noticed that the tcpclient prefers an ip address and not a name. Then I also realized that sometimes there were extra spaces on either side of the domain name. So I used the below code to strip the characters and change it to an ip.

string.Trim();
//Telnet Start
IPHostEntry hostInfo = Dns.Resolve(hostnamehere);

这篇关于没有这样的主机是已知的套接字连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆