-
Notifications
You must be signed in to change notification settings - Fork 0
/
RealTimeClient.cs
136 lines (120 loc) · 5.26 KB
/
RealTimeClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//using System;
//using System.Text;
//using Aws.GameLift.Realtime;
//using Aws.GameLift.Realtime.Event;
//using Aws.GameLift.Realtime.Types;
//namespace Example
//{
// /**
// * An example client that wraps the GameLift Realtime client SDK
// *
// * You can redirect logging from the SDK by setting up the LogHandler as such:
// * ClientLogger.LogHandler = (x) => Console.WriteLine(x);
// *
// */
// class RealTimeClient
// {
// public Aws.GameLift.Realtime.Client Client { get; private set; }
// // An opcode defined by client and your server script that represents a custom message type
// private const int MY_TEST_OP_CODE = 10;
// /// Initialize a client for GameLift Realtime and connect to a player session.
// /// <param name="endpoint">The DNS name that is assigned to Realtime server</param>
// /// <param name="remoteTcpPort">A TCP port for the Realtime server</param>
// /// <param name="listeningUdpPort">A local port for listening to UDP traffic</param>
// /// <param name="connectionType">Type of connection to establish between client and the Realtime server</param>
// /// <param name="playerSessionId">The player session ID that is assigned to the game client for a game session </param>
// /// <param name="connectionPayload">Developer-defined data to be used during client connection, such as for player authentication</param>
// public RealTimeClient(string endpoint, int remoteTcpPort, int listeningUdpPort, ConnectionType connectionType,
// string playerSessionId, byte[] connectionPayload)
// {
// // Create a client configuration to specify a secure or unsecure connection type
// // Best practice is to set up a secure connection using the connection type RT_OVER_WSS_DTLS_TLS12.
// ClientConfiguration clientConfiguration = new ClientConfiguration()
// {
// // C# notation to set the field ConnectionType in the new instance of ClientConfiguration
// ConnectionType = connectionType
// };
// // Create a Realtime client with the client configuration
// Client = new Client(clientConfiguration);
// // Initialize event handlers for the Realtime client
// Client.ConnectionOpen += OnOpenEvent;
// Client.ConnectionClose += OnCloseEvent;
// Client.GroupMembershipUpdated += OnGroupMembershipUpdate;
// Client.DataReceived += OnDataReceived;
// // Create a connection token to authenticate the client with the Realtime server
// // Player session IDs can be retrieved using AWS SDK for GameLift
// ConnectionToken connectionToken = new ConnectionToken(playerSessionId, connectionPayload);
// // Initiate a connection with the Realtime server with the given connection information
// Client.Connect(endpoint, remoteTcpPort, listeningUdpPort, connectionToken);
// }
// public void Disconnect()
// {
// if (Client.Connected)
// {
// Client.Disconnect();
// }
// }
// public bool IsConnected()
// {
// return Client.Connected;
// }
// /// <summary>
// /// Example of sending to a custom message to the server.
// ///
// /// Server could be replaced by known peer Id etc.
// /// </summary>
// /// <param name="intent">Choice of delivery intent ie Reliable, Fast etc. </param>
// /// <param name="payload">Custom payload to send with message</param>
// public void SendMessage(DeliveryIntent intent, string payload)
// {
// Client.SendMessage(Client.NewMessage(MY_TEST_OP_CODE)
// .WithDeliveryIntent(intent)
// .WithTargetPlayer(Constants.PLAYER_ID_SERVER)
// .WithPayload(StringToBytes(payload)));
// }
// /**
// * Handle connection open events
// */
// public void OnOpenEvent(object sender, EventArgs e)
// {
// }
// /**
// * Handle connection close events
// */
// public void OnCloseEvent(object sender, EventArgs e)
// {
// }
// /**
// * Handle Group membership update events
// */
// public void OnGroupMembershipUpdate(object sender, GroupMembershipEventArgs e)
// {
// }
// /**
// * Handle data received from the Realtime server
// */
// public virtual void OnDataReceived(object sender, DataReceivedEventArgs e)
// {
// switch (e.OpCode)
// {
// // handle message based on OpCode
// default:
// break;
// }
// }
// /**
// * Helper method to simplify task of sending/receiving payloads.
// */
// public static byte[] StringToBytes(string str)
// {
// return Encoding.UTF8.GetBytes(str);
// }
// /**
// * Helper method to simplify task of sending/receiving payloads.
// */
// public static string BytesToString(byte[] bytes)
// {
// return Encoding.UTF8.GetString(bytes);
// }
// }
//}