Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix zero connect #551

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions neo/Network/TcpRemoteNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public TcpRemoteNode(LocalNode localNode, Socket socket)
: base(localNode)
{
this.socket = socket;
OnConnected();
OnConnectedListener();//別人連我
}

public async Task<bool> ConnectAsync()
Expand All @@ -37,9 +37,9 @@ public async Task<bool> ConnectAsync()
try
{
await socket.ConnectAsync(address, ListenerEndpoint.Port);
OnConnected();
OnConnected();//我連別人
}
catch (SocketException)
catch (SocketException e)
{
Disconnect(false);
return false;
Expand All @@ -58,9 +58,19 @@ public override void Disconnect(bool error)
}

private void OnConnected()
{
//发现在我的电脑上 socket.RemoteEndPoint 会抛出异常
//IPEndPoint remoteEndpoint = (IPEndPoint)socket.RemoteEndPoint;
//RemoteEndpoint = new IPEndPoint(remoteEndpoint.Address.MapToIPv6(), remoteEndpoint.Port);
this.RemoteEndpoint = new IPEndPoint(ListenerEndpoint.Address.MapToIPv6(), ListenerEndpoint.Port);
stream = new NetworkStream(socket);
connected = true;
}
private void OnConnectedListener()
{
IPEndPoint remoteEndpoint = (IPEndPoint)socket.RemoteEndPoint;
RemoteEndpoint = new IPEndPoint(remoteEndpoint.Address.MapToIPv6(), remoteEndpoint.Port);
this.RemoteEndpoint = new IPEndPoint(RemoteEndpoint.Address.MapToIPv6(), RemoteEndpoint.Port);
stream = new NetworkStream(socket);
connected = true;
}
Expand Down