Skip to content

Commit

Permalink
新版ApiClient支持指定本地IP地址
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Apr 26, 2024
1 parent 356c3c4 commit 1d83f11
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
8 changes: 4 additions & 4 deletions XCoder/CrazyCoder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="NewLife.Map" Version="2.5.2024.410-beta1241" />
<PackageReference Include="NewLife.ModbusRTU" Version="1.8.2024.217" />
<PackageReference Include="NewLife.Remoting" Version="2.8.2024.419-beta0703" />
<PackageReference Include="NewLife.ModbusRTU" Version="1.8.2024.426-beta1011" />
<PackageReference Include="NewLife.Remoting" Version="2.8.2024.426-beta1006" />
<PackageReference Include="System.Speech" Version="8.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
<PackageReference Include="NewLife.Core">
<Version>10.10.2024.424-beta1020</Version>
<Version>10.10.2024.426-beta1001</Version>
</PackageReference>
<PackageReference Include="NewLife.MQTT">
<Version>2.0.2024.407</Version>
Expand All @@ -85,7 +85,7 @@
<Version>5.6.2024.420-beta0005</Version>
</PackageReference>
<PackageReference Include="NewLife.Stardust">
<Version>2.9.2024.425-beta0447</Version>
<Version>2.9.2024.426-beta1008</Version>
</PackageReference>
<PackageReference Include="NewLife.XCode">
<Version>11.11.2024.424-beta1026</Version>
Expand Down
20 changes: 2 additions & 18 deletions XCoder/XNet/FrmApiDiscover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,15 @@ private async void btnConnect_Click(Object sender, EventArgs e)
}
}

class MyClient : ApiClient
{
public IPAddress Local { get; set; }

public MyClient(String uri) : base(uri) { }

protected override ISocketClient OnCreate(String svr)
{
var client = base.OnCreate(svr);
if (Local != null)
client.Local = new NetUri { Address = Local };

return client;
}
}

async Task DiscoverUdp(IPAddress local, IPEndPoint ep)
{
XTrace.WriteLine("DiscoverUdp: {0} -> {1}", local, ep);

try
{
//var uri = new NetUri("udp://255.255.255.255:5500");
var client = new MyClient($"udp://{ep.Address}:{ep.Port}");
if (local != null) client.Local = local;
var client = new ApiClient($"udp://{ep.Address}:{ep.Port}");
if (local != null) client.Local = new NetUri { Address = local };
client.Received += Client_Received;

// 异步发送,但是不等待返回,因为可能会有多个返回,在事件里处理
Expand Down
4 changes: 2 additions & 2 deletions XCoderLinux/XCoderLinux.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@

<ItemGroup>
<PackageReference Include="GtkSharp" Version="3.24.24.95" />
<PackageReference Include="NewLife.Core" Version="10.10.2024.424-beta1020" />
<PackageReference Include="NewLife.Remoting" Version="2.8.2024.419-beta0703" />
<PackageReference Include="NewLife.Core" Version="10.10.2024.426-beta1001" />
<PackageReference Include="NewLife.Remoting" Version="2.8.2024.426-beta1006" />
<PackageReference Include="NewLife.XCode" Version="11.11.2024.424-beta1026" />
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
<PackageReference Include="System.Management" Version="8.0.0" />
Expand Down

0 comments on commit 1d83f11

Please sign in to comment.