File tree Expand file tree Collapse file tree 2 files changed +7
-20
lines changed
src/BootstrapBlazor.Server/Components/Samples/Tutorials Expand file tree Collapse file tree 2 files changed +7
-20
lines changed Original file line number Diff line number Diff line change 11@page " /socket"
22
33<div >
4- <p >由于是示例演示,不提供选择 <code >IP 地址</code > 与 <code >端口</code > 功能。点击 <b >连接</b > <b >断开</b > 测试功能</p >
4+ <ul class =" ul-demo" >
5+ <li >点击 <b >连接</b > 按钮后通过 <code >ITcpSocketFactory</code > 服务实例创建的 <code >ITcpSocketClient</code > 对象连接到网站模拟 <code >TcpServer</code ></li >
6+ <li >点击 <b >断开</b > 按钮调用 <code >CloseAsync</code > 方法断开 Socket 连接</li >
7+ </ul >
58
6- <div class =" row forn-inline g-3" >
7- <div class =" col-12 col-sm-6 align-content-center" >
8- <Light Color =" @_connectColor" IsFlash =" _flash" ></Light >
9- </div >
9+ <div class =" row form-inline g-3" >
1010 <div class =" col-12 col-sm-6" >
1111 <Button Text =" 连接" Icon =" fa-solid fa-play"
1212 OnClick =" OnConnectAsync" IsDisabled =" @_client.IsConnected" ></Button >
13- <Button Text =" 断开" Icon =" fa-solid fa-stop"
13+ <Button Text =" 断开" Icon =" fa-solid fa-stop" class = " ms-2 "
1414 OnClick =" OnCloseAsync" IsDisabled =" @(!_client.IsConnected)" ></Button >
1515 </div >
1616 <div class =" col-12" >
17- <Console Items =" @_items" Height =" 500 " HeaderText =" 接收数据(间隔 10 秒)"
17+ <Console Items =" @_items" Height =" 496 " HeaderText =" 接收数据(间隔 10 秒)"
1818 ShowAutoScroll =" true" OnClear =" @OnClear" ></Console >
1919 </div >
2020 </div >
Original file line number Diff line number Diff line change @@ -12,10 +12,6 @@ public partial class SocketApp : ComponentBase, IDisposable
1212 [ Inject , NotNull ]
1313 private ITcpSocketFactory ? TcpSocketFactory { get ; set ; }
1414
15- private Color _connectColor = Color . None ;
16-
17- private bool _flash = false ;
18-
1915 private ITcpSocketClient _client = null ! ;
2016
2117 private List < ConsoleMessageItem > _items = [ ] ;
@@ -30,15 +26,13 @@ protected override void OnInitialized()
3026 // 从服务中获取 Socket 实例
3127 _client = TcpSocketFactory . GetOrCreate ( "bb" , key => new IPEndPoint ( IPAddress . Loopback , 0 ) ) ;
3228 _client . ReceivedCallBack += OnReceivedAsync ;
33- ResetLight ( ) ;
3429 }
3530
3631 private async Task OnConnectAsync ( )
3732 {
3833 if ( _client is { IsConnected : false } )
3934 {
4035 await _client . ConnectAsync ( "127.0.0.1" , 8800 , CancellationToken . None ) ;
41- ResetLight ( ) ;
4236 }
4337 }
4438
@@ -47,16 +41,9 @@ private async Task OnCloseAsync()
4741 if ( _client is { IsConnected : true } )
4842 {
4943 await _client . CloseAsync ( ) ;
50- ResetLight ( ) ;
5144 }
5245 }
5346
54- private void ResetLight ( )
55- {
56- _flash = _client . IsConnected ;
57- _connectColor = _client . IsConnected ? Color . Success : Color . None ;
58- }
59-
6047 private Task OnClear ( )
6148 {
6249 _items = [ ] ;
You can’t perform that action at this time.
0 commit comments