add ws open ip info (local and remote)

This commit is contained in:
zhangyazhou 2022-02-25 19:42:56 +08:00
parent ba5ccfcd10
commit 493a7d7a40
4 changed files with 29 additions and 3 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@ Backup*
_UpgradeReport_Files
bin
obj
.idea
*.mdb
*.pdb

View File

@ -0,0 +1,15 @@
using System;
namespace WebSocketSharp
{
public class OpenEventArgs : EventArgs
{
public string LocalIP { get; private set; }
public string RemoteIP { get; private set; }
public OpenEventArgs(string localIp, string remoteIp)
{
LocalIP = localIp;
RemoteIP = remoteIp;
}
}
}

View File

@ -45,6 +45,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Cryptography;
@ -52,6 +53,11 @@ using System.Text;
using System.Threading;
using WebSocketSharp.Net;
using WebSocketSharp.Net.WebSockets;
using AuthenticationSchemes = WebSocketSharp.Net.AuthenticationSchemes;
using Cookie = WebSocketSharp.Net.Cookie;
using CookieCollection = WebSocketSharp.Net.CookieCollection;
using HttpStatusCode = WebSocketSharp.Net.HttpStatusCode;
using NetworkCredential = WebSocketSharp.Net.NetworkCredential;
namespace WebSocketSharp
{
@ -796,7 +802,7 @@ namespace WebSocketSharp
/// <summary>
/// Occurs when the WebSocket connection has been established.
/// </summary>
public event EventHandler OnOpen;
public event EventHandler<OpenEventArgs> OnOpen;
#endregion
@ -1533,8 +1539,11 @@ namespace WebSocketSharp
{
_inMessage = true;
startReceiving ();
try {
OnOpen.Emit (this, EventArgs.Empty);
try
{
var local = (IPEndPoint) _tcpClient.Client.LocalEndPoint;
var remote = (IPEndPoint) _tcpClient.Client.RemoteEndPoint;
OnOpen.Emit (this, new OpenEventArgs(local.Address.ToString(), remote.Address.ToString()));
}
catch (Exception ex) {
_logger.Error (ex.ToString ());

View File

@ -67,6 +67,7 @@
<Compile Include="CloseEventArgs.cs" />
<Compile Include="ByteOrder.cs" />
<Compile Include="ErrorEventArgs.cs" />
<Compile Include="OpenEventArgs.cs" />
<Compile Include="WebSocket.cs" />
<Compile Include="Server\WebSocketServer.cs" />
<Compile Include="Net\AuthenticationSchemes.cs" />