Skip to content

Commit b3f6022

Browse files
committed
Improved documentation. Added support for domains as connection address.
1 parent 096c8d8 commit b3f6022

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

Assets/FishNet/Plugins/FishyUnityTransport/FishyUnityTransport.cs

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6+
using System.Net;
67
using UnityEngine;
78
using TransportNetworkEvent = Unity.Networking.Transport.NetworkEvent;
89
using Unity.Burst;
@@ -141,11 +142,9 @@ public INetworkStreamDriverConstructor DriverConstructor
141142
[SerializeField]
142143
private ProtocolType m_ProtocolType;
143144

145+
#if UTP_TRANSPORT_2_0_ABOVE
144146
[Tooltip("Per default the client/server will communicate over UDP. Set to true to communicate with WebSocket.")]
145147
[SerializeField]
146-
#if !UTP_TRANSPORT_2_0_ABOVE
147-
[HideInInspector]
148-
#endif
149148
private bool m_UseWebSockets = false;
150149

151150
public bool UseWebSockets
@@ -159,15 +158,13 @@ public bool UseWebSockets
159158
/// </summary>
160159
[Tooltip("Per default the client/server communication will not be encrypted. Select true to enable DTLS for UDP and TLS for Websocket.")]
161160
[SerializeField]
162-
#if !UTP_TRANSPORT_2_0_ABOVE
163-
[HideInInspector]
164-
#endif
165161
private bool m_UseEncryption = false;
166162
public bool UseEncryption
167163
{
168164
get => m_UseEncryption;
169165
set => m_UseEncryption = value;
170166
}
167+
#endif
171168

172169
[Tooltip("The maximum amount of packets that can be in the internal send/receive queues. Basically this is how many packets can be sent/received in a single update/frame.")]
173170
[SerializeField]
@@ -181,11 +178,12 @@ public int MaxPacketQueueSize
181178
set => m_MaxPacketQueueSize = value;
182179
}
183180

184-
[Tooltip("The maximum size of an unreliable payload that can be handled by the transport.")]
181+
[Tooltip("The maximum size of an unreliable payload that can be handled by the transport. The memory for MaxPayloadSize is allocated once per connection and is released when the connection is closed.")]
185182
[SerializeField]
186183
private int m_MaxPayloadSize = InitialMaxPayloadSize;
187184

188185
/// <summary>The maximum size of an unreliable payload that can be handled by the transport.</summary>
186+
/// <remarks>The memory for MaxPayloadSize is allocated once per connection and is released when the connection is closed.</remarks>
189187
public int MaxPayloadSize
190188
{
191189
get => m_MaxPayloadSize;
@@ -288,19 +286,25 @@ public struct ConnectionAddressData
288286
[SerializeField]
289287
public string ServerListenAddress;
290288

291-
private static NetworkEndpoint ParseNetworkEndpoint(string ip, ushort port, bool silent = false)
289+
private static NetworkEndpoint ParseNetworkEndpoint(string address, ushort port, bool silent = false)
292290
{
293291
NetworkEndpoint endpoint = default;
294292

295-
if (!NetworkEndpoint.TryParse(ip, port, out endpoint, NetworkFamily.Ipv4) &&
296-
!NetworkEndpoint.TryParse(ip, port, out endpoint, NetworkFamily.Ipv6))
293+
if (!NetworkEndpoint.TryParse(address, port, out endpoint, NetworkFamily.Ipv4) &&
294+
!NetworkEndpoint.TryParse(address, port, out endpoint, NetworkFamily.Ipv6))
297295
{
298-
if (!silent)
296+
IPAddress[] ipList = Dns.GetHostAddresses(address);
297+
if (ipList.Length > 0)
299298
{
300-
Debug.LogError($"Invalid network endpoint: {ip}:{port}.");
299+
endpoint = ParseNetworkEndpoint(ipList[0].ToString(), port, true);
301300
}
302301
}
303302

303+
if (endpoint == default && !silent)
304+
{
305+
Debug.LogError($"Invalid network endpoint: {address}:{port}.");
306+
}
307+
304308
return endpoint;
305309
}
306310

@@ -381,6 +385,7 @@ public struct SimulatorParameters
381385
/// - packet jitter (variances in latency, see: https://en.wikipedia.org/wiki/Jitter)
382386
/// - packet drop rate (packet loss)
383387
/// </summary>
388+
384389
#if UTP_TRANSPORT_2_0_ABOVE
385390
[HideInInspector]
386391
[Obsolete("DebugSimulator is no longer supported and has no effect. Use Network Simulator from the Multiplayer Tools package.", false)]
@@ -400,6 +405,9 @@ public struct SimulatorParameters
400405
private NetworkPipeline m_UnreliableSequencedFragmentedPipeline;
401406
private NetworkPipeline m_ReliableSequencedPipeline;
402407

408+
/// <summary>
409+
/// The current ProtocolType used by the transport
410+
/// </summary>
403411
public ProtocolType Protocol => m_ProtocolType;
404412

405413
private RelayServerData m_RelayServerData;
@@ -635,9 +643,11 @@ public void SetConnectionData(NetworkEndpoint endPoint, NetworkEndpoint listenEn
635643
/// <param name="packetDelay">Packet delay in milliseconds.</param>
636644
/// <param name="packetJitter">Packet jitter in milliseconds.</param>
637645
/// <param name="dropRate">Packet drop percentage.</param>
646+
638647
#if UTP_TRANSPORT_2_0_ABOVE
639648
[Obsolete("SetDebugSimulatorParameters is no longer supported and has no effect. Use Network Simulator from the Multiplayer Tools package.", false)]
640649
#endif
650+
641651
public void SetDebugSimulatorParameters(int packetDelay, int packetJitter, int dropRate)
642652
{
643653
if (m_Driver.IsCreated)
@@ -753,6 +763,7 @@ private bool AcceptConnection()
753763

754764
HandleRemoteConnectionState(RemoteConnectionState.Started, ParseClientId(connection));
755765
return true;
766+
756767
}
757768

758769
private void ReceiveMessages(ulong clientId, NetworkPipeline pipeline, DataStreamReader dataReader)
@@ -823,6 +834,10 @@ private bool ProcessEvent()
823834
}
824835
else
825836
{
837+
if (m_ClientState == LocalConnectionState.Starting)
838+
{
839+
Debug.LogError("Failed to connect to server.");
840+
}
826841
SetClientConnectionState(LocalConnectionState.Stopping);
827842
DisposeInternals();
828843
SetClientConnectionState(LocalConnectionState.Stopped);
@@ -879,6 +894,11 @@ private void IterateIncoming()
879894
}
880895
}
881896

897+
private void OnDestroy()
898+
{
899+
Shutdown();
900+
}
901+
882902
private int ExtractRtt(NetworkConnection networkConnection)
883903
{
884904
if (m_Driver.GetConnectionState(networkConnection) != NetworkConnection.State.Connected)
@@ -1157,7 +1177,6 @@ private bool StartClient()
11571177
}
11581178
SetClientConnectionState(LocalConnectionState.Stopped);
11591179
}
1160-
11611180
return succeeded;
11621181
}
11631182

@@ -1332,6 +1351,7 @@ public void CreateDriver(FishyUnityTransport transport, out NetworkDriver driver
13321351
ConfigureSimulatorForUtp1();
13331352
#endif
13341353
bool asServer = m_ServerState == LocalConnectionState.Starting;
1354+
13351355
m_NetworkSettings.WithNetworkConfigParameters(
13361356
maxConnectAttempts: transport.m_MaxConnectAttempts,
13371357
connectTimeoutMS: transport.m_ConnectTimeoutMS,
@@ -1501,7 +1521,6 @@ private void SetupPipelinesForUtp2(NetworkDriver driver,
15011521
);
15021522
}
15031523
#endif
1504-
15051524
// -------------- Utility Types -------------------------------------------------------------------------------
15061525

15071526

@@ -1547,11 +1566,6 @@ public override int GetHashCode()
15471566
public override event Action<ServerConnectionStateArgs> OnServerConnectionState;
15481567
public override event Action<RemoteConnectionStateArgs> OnRemoteConnectionState;
15491568

1550-
private void OnDestroy()
1551-
{
1552-
Shutdown();
1553-
}
1554-
15551569
public override string GetConnectionAddress(int connectionId)
15561570
{
15571571
bool isServer = m_ServerState == LocalConnectionState.Started;
@@ -1584,7 +1598,7 @@ public override string GetConnectionAddress(int connectionId)
15841598
}
15851599
return string.Empty;
15861600

1587-
NetworkEndPoint GetLocalEndPoint()
1601+
NetworkEndpoint GetLocalEndPoint()
15881602
{
15891603
#if UTP_TRANSPORT_2_0_ABOVE
15901604
return m_Driver.GetLocalEndpoint();

0 commit comments

Comments
 (0)