c# – 没有这样的主机是已知的套接字连接
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 没有这样的主机是已知的套接字连接,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3394字,纯文字阅读大概需要5分钟。
内容图文
![c# – 没有这样的主机是已知的套接字连接](/upload/InfoBanner/zyjiaocheng/794/4ba95fdd1f4342a7bfe90ba297d93e2a.jpg)
我正在尝试使用此库进行telnet连接.我已正确调用该函数并执行下面的代码但未能给出以下错误:
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问题或者只是一个可以忽略的例外.如果它是可以忽略的东西,我似乎无法让程序通过它.我似乎也无法找到解决它的任何解决方案.我很遗憾这一点,任何帮助将不胜感激.
解决方法:
解决方案很容易被忽视.首先我注意到tcpclient更喜欢ip地址而不是名字.然后我也意识到有时在域名的两边都有额外的空格.所以我使用下面的代码去除字符并将其更改为ip.
string.Trim();
//Telnet Start
IPHostEntry hostInfo = Dns.Resolve(hostnamehere);
内容总结
以上是互联网集市为您收集整理的c# – 没有这样的主机是已知的套接字连接全部内容,希望文章能够帮你解决c# – 没有这样的主机是已知的套接字连接所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。