public InitializationResponse ConnectToServer() { client.Connect(server_endpoint); this.private_endpoint = ((IPEndPoint)client.LocalEndPoint).Convert(); System.Console.WriteLine($"{client.LocalEndPoint}"); System.Console.WriteLine($"Local endpoint: {private_endpoint.GetAddress()}:{private_endpoint.Port}"); this.state = Tcp_State.Initialization; this.stream = new NetworkStream(client); InitializationRequest info = new InitializationRequest { ClientId = id, PrivateEndpoint = private_endpoint }; info.WriteDelimitedTo(stream); var response = InitializationResponse.Parser.ParseDelimitedFrom(stream); this.state = Tcp_State.WithoutLobby; return(response); }
public static System.Net.IPAddress GetAddress(this IPEndPointMessage endpoint) { switch (endpoint.Address.IpFamilyCase) { case IpV4: return(new System.Net.IPAddress(endpoint.Address.IpV4)); case IpV6: return(new System.Net.IPAddress(endpoint.Address.IpV6.ToByteArray())); default: return(null); } }
public void Initialize() { stream = new NetworkStream(client); public_endpoint = ((IPEndPoint)client.RemoteEndPoint).Convert(); Log($"Session initialization started."); var initializationRequest = InitializationRequest.Parser.ParseDelimitedFrom(stream); private_endpoint = initializationRequest.PrivateEndpoint; id = initializationRequest.ClientId; var initializationResponse = new InitializationResponse(); initializationResponse.SomeLobbyIds.AddRange(server.lobbies.Keys.Take(10)); initializationResponse.WriteDelimitedTo(stream); Log($"Session established. Peer's private endpoint: {private_endpoint}"); }
public static System.Net.IPEndPoint Convert(this IPEndPointMessage ep) { return(new System.Net.IPEndPoint(ep.GetAddress(), ep.Port)); }