Skip to content

Commit 1582926

Browse files
committed
chore: recover Program.cs
1 parent b3a0534 commit 1582926

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SocketIOClient.Sample
8+
{
9+
10+
class Program
11+
{
12+
static async Task Main(string[] args)
13+
{
14+
Console.OutputEncoding = Encoding.UTF8;
15+
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
16+
17+
var uri = new Uri("http://localhost:11003");
18+
19+
var socket = new SocketIO(uri, new SocketIOOptions
20+
{
21+
Query = new Dictionary<string, string>
22+
{
23+
{"token", "V3" }
24+
}
25+
});
26+
27+
28+
//var client = socket.Socket as ClientWebSocket;
29+
//client.Config = options =>
30+
//{
31+
// options.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
32+
// {
33+
// Console.WriteLine("SslPolicyErrors: " + sslPolicyErrors);
34+
// if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
35+
// {
36+
// return true;
37+
// }
38+
// return false;
39+
// };
40+
//};
41+
42+
socket.OnConnected += Socket_OnConnected;
43+
socket.OnPing += Socket_OnPing;
44+
socket.OnPong += Socket_OnPong;
45+
socket.OnDisconnected += Socket_OnDisconnected;
46+
socket.OnReconnecting += Socket_OnReconnecting;
47+
48+
//Console.WriteLine("Press any key to continue");
49+
//Console.ReadLine();
50+
51+
await socket.ConnectAsync();
52+
53+
Console.ReadLine();
54+
}
55+
56+
private static void Socket_OnReconnecting(object sender, int e)
57+
{
58+
Console.WriteLine($"{DateTime.Now} Reconnecting: attempt = {e}");
59+
}
60+
61+
private static void Socket_OnDisconnected(object sender, string e)
62+
{
63+
Console.WriteLine("disconnect: " + e);
64+
}
65+
66+
private static async void Socket_OnConnected(object sender, EventArgs e)
67+
{
68+
Console.WriteLine("Socket_OnConnected");
69+
var socket = sender as SocketIO;
70+
Console.WriteLine("Socket.Id:" + socket.Id);
71+
72+
await socket.EmitAsync("hi", "SocketIOClient.Sample");
73+
}
74+
75+
private static void Socket_OnPing(object sender, EventArgs e)
76+
{
77+
Console.WriteLine("Ping");
78+
}
79+
80+
private static void Socket_OnPong(object sender, TimeSpan e)
81+
{
82+
Console.WriteLine("Pong: " + e.TotalMilliseconds);
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)