使用telnet协议将asp.net C#连接到具有Linux O.S的服务器

时间:2013-04-28 18:28:44

标签: c# asp.net linux telnet

我正在尝试为Linux现金服务器设计一个界面本地网站,我正在使用带有c#的asp.net,起初我只是尝试建立测试连接,我用两个文本框创建一个底部 和一个标签,这是我的代码:

     public partial class _Default : System.Web.UI.Page
   {
     protected void Page_Load(object sender, EventArgs e)
   {

  }
      private Socket clientSocket;
      private IPAddress hostAddress;


  private void telnetSocketAsyncEventArgs_Completed(object sender, SocketAsyncEventArgs      e)
 {
try
{
    if (e.SocketError == SocketError.Success)
    {
        if (e.LastOperation == SocketAsyncOperation.Connect)
        {
            errorplace.Text="Service Is Running";
        }
    }
    else
    {
        errorplace.Text="Service Is not Running";
    }
}
catch (SocketException ex )
{

    errorplace.Text = ex.Message;
}
    }
  protected void Button1_Click1(object sender, EventArgs e)
   {
{

try
{
    if (string.IsNullOrEmpty(IPTextBox.Text))
        return;

    if (string.IsNullOrEmpty(PortTextBox.Text))
        return;

    int port;
    hostAddress = Dns.GetHostEntry(IPTextBox.Text).AddressList[0];
    int.TryParse(PortTextBox.Text, out port);

    if (hostAddress.AddressFamily == AddressFamily.InterNetwork)
        clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    else if (hostAddress.AddressFamily == AddressFamily.InterNetworkV6)
        clientSocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);

    SocketAsyncEventArgs telnetSocketAsyncEventArgs = new SocketAsyncEventArgs();
    telnetSocketAsyncEventArgs.RemoteEndPoint = new IPEndPoint(hostAddress, port);
    telnetSocketAsyncEventArgs.Completed += new
        EventHandler<SocketAsyncEventArgs>(telnetSocketAsyncEventArgs_Completed);

    clientSocket.ConnectAsync(telnetSocketAsyncEventArgs);
}
catch (SocketException )
{
   errorplace.Text="Service Is not Running";

}
finally
{
}

}


  }
    }

我对代码调试没有任何问题,但每当我尝试连接其说“服务未运行”时... 请我需要帮助,我只是想确定asp.net与linux服务器运行正常吗?所以我可以继续我的项目吗?

0 个答案:

没有答案