2

I am having trouble with sockets connecting from an external source

See below my constructor.

//Using UDP sockets

clientSocket = new Socket(AddressFamily.InterNetwork,
                          SocketType.Dgram, ProtocolType.Udp);
EndPoint ourEP = new IPEndPoint(IPAddress.Any, 1450);
//Listen asynchronously on port 1450 for coming messages (Invite, Bye, etc).
clientSocket.Bind(ourEP);

//Receive data from any IP.
EndPoint remoteEP = (EndPoint)(new IPEndPoint(IPAddress.Any, 0));

byteData = new byte[1024];
//Receive data asynchornously.
clientSocket.BeginReceiveFrom(byteData,
                           0, byteData.Length,
                           SocketFlags.None,
                           ref remoteEP,
                           new AsyncCallback(OnReceive),
                           null);

this is connect button function:

private void btnCall_Click(object sender, EventArgs e)
{
    //Get the IP we want to connect.
    otherPartyIP = new IPEndPoint(IPAddress.Parse(txtCallToIP.Text), 1450);
    otherPartyEP = (EndPoint)otherPartyIP;
}

I make chat application peer to peer over internet. i opened port 1450 firewall and add port forward but it's not connecting. Please can you help?

4

1 回答 1

0

使用 UDP 时,您必须确保正确设置数据包可以传输的 HOPS 数量。

我不确定,但我认为默认值是 0 或 1。

使用套接字上的 Ttl 属性进行试验。如果您在很短的路径上进行测试,请尝试将其设置为 10。

或者将其设置为更高的字节,因为数据报的 ttl 属性表示数据包可以通过到达其目的地的点/路由器(实际上是跃点)的数量。

取值范围可以是 0 到 255。

希望这可以帮助

于 2012-10-02T11:42:59.150 回答