2012-12-14 54 views
0

我正在尝试在使用C#的网络中与远程系统建立连接。然后程序抛出以下异常使用TCP客户端进行连接时出错

无连接可以作出,因为目标机器积极地拒绝它192.168.1.42:8000

private void Start_Sending_Video_Conference(string remote_IP,int port_number) 
{ 
    try 
    { 
     ms = new MemoryStream();// Store it in Binary Array as 
     pictureBox1.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg); 
     byte[] arrImage = ms.GetBuffer(); 
     myclient = new TcpClient (remote_IP,port_number);//Connecting with server 
     myns = myclient.GetStream(); 
     mysw = new BinaryWriter (myns); 
     mysw.Write(arrImage);//send the stream to above address 
     ms.Flush(); 
     mysw.Flush(); 
     myns.Flush(); 
     ms.Close(); 
     mysw.Close(); 
     myns.Close(); 
     myclient.Close(); 
    } 
    catch (Exception ex) 
    { 
     Capturing.Enabled = false; 
     MessageBox.Show(ex.Message, "Video Conference Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); 
    } 
} 
+0

看起来像防火墙 – 0lukasz0

回答

0

确定的东西是在另一端监听?在这种情况下,看起来您的本地服务器实际上拒绝了该请求。请确认服务器正在运行,TCPServer正在监听,并且服务器正在运行的计算机(如果它在本地,这应该不是问题)设置为允许来自LAN的传入数据包。

1

请检查秋后算账:

  1. 是服务器应用程序确实运行
  2. 它是否真的监听8000端口?
  3. 客户端计算机上的防火墙是否允许端口8000上的传出通信?
  4. 服务器计算机上的防火墙是否允许端口8000上的传入流量?
0

如果上述解决方案不起作用,那么问题可能出现在Server代码中。 您可能使用过TcpListener的实例来侦听指定的端口,但您将哪个IpAddress传递给构造函数? 如果你写了下面的代码:

mylistener = new TcpListener(IPAddress.Loopback, 8000); 

这将导致错误。 发生这种情况是因为Loopback不会让侦听器监听所有网络接口,而只监听来自本地主机(127.0.0.1)的请求。

使用此代码,而不是

mylistener = new TcpListener(IPAddress.Any, 8000);