Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dingsongjie committed Mar 8, 2019
1 parent 6bec589 commit 417082a
Show file tree
Hide file tree
Showing 5 changed files with 558 additions and 425 deletions.
93 changes: 56 additions & 37 deletions sampleapp/ClientApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,75 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WebSocket4Net.AspNetCore.SignalR.Client;
using WebSocket4Net.AspNetCore.SignalRClient.Connection;

namespace ClientApp {
public class Program {
static void Main(string[] args) {
var header = new Dictionary<string, string>();
header.Add("Sample", "Token");
namespace ClientApp
{
public class Program
{
static void Main(string[] args)
{
var header = new Dictionary<string, string>();
header.Add("Sample", "Token");

var connection = new HubConnectionBuilder()
.WithUrl("http://127.0.0.1:5000/chatHub", option => {
option.Headers = header;
var connection = new HubConnectionBuilder()
.WithUrl("http://127.0.0.1:5000/chatHub", option =>
{
option.Headers = header;

})
.ConfigService(service => {
service.AddLogging(config => {
config.AddConsole();
})
.ConfigService(service =>
{
service.AddLogging(config =>
{
config.AddConsole();
});
})
.Build();
connection.StartAsync().GetAwaiter().GetResult();

connection.On<UserAndMessage>("ReceiveMessage", model =>
{
Console.WriteLine($"user:{model.User},mes:{model.Message}");
});
})
.Build();
connection.StartAsync().GetAwaiter().GetResult();

connection.On<UserAndMessage>("ReceiveMessage", model => {
Console.WriteLine($"user:{model.User},mes:{model.Message}");
});
connection.Closed += async (ex) =>
{
//重试几次

connection.Closed += async (ex) => {
Console.WriteLine(ex.Message);
//重试几次
await connection.RestartAsync();
};
connection.Send("SendMessage", new object[] { "user1", "message1" }).GetAwaiter().GetResult();
Timer timer = new Timer(obj => {
connection.Invoke<UserAndMessage>("SendMessage", new object[] { "user1", "message1" }, (result, exception) => {
Console.WriteLine($"result:{result}");
try
{
Console.WriteLine("开始尝试连接");
await connection.RestartAsync();
}
catch(Exception e)
{

}
};
connection.Send("SendMessage", new object[] { "user1", "message1" }).GetAwaiter().GetResult();
Timer timer = new Timer(obj =>
{
connection.Invoke<UserAndMessage>("SendMessage", new object[] { "user1", "message1" }, (result, exception) =>
{
Console.WriteLine($"result:{result}");


}).GetAwaiter().GetResult();
}, "", 0, 5 * 60 * 1000);

Console.ReadKey();
}
}).GetAwaiter().GetResult();
}, "", 0, 5 * 60 * 1000);

Console.ReadKey();
}

public class UserAndMessage {
public string User { get; set; }
public string Message { get; set; }
public class UserAndMessage
{
public string User { get; set; }
public string Message { get; set; }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<Version>1.1.2</Version>
<Version>1.1.3</Version>
<Authors>dingsongjie</Authors>
</PropertyGroup>

Expand Down
Loading

0 comments on commit 417082a

Please sign in to comment.