FixGetIp
This commit is contained in:
parent
8581fef566
commit
cd2e112c3a
2 changed files with 6 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlTypes;
|
using System.Data.SqlTypes;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
@ -87,7 +88,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void JoinYourself(int port) // single player
|
public void JoinYourself(int port) // single player
|
||||||
{
|
{
|
||||||
endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
|
endPoint = new IPEndPoint(GetIp(), port);
|
||||||
socket.Connect(endPoint);
|
socket.Connect(endPoint);
|
||||||
SendData();
|
SendData();
|
||||||
Thread listen = new Thread(StartListening);
|
Thread listen = new Thread(StartListening);
|
||||||
|
@ -98,7 +99,8 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
public static IPAddress GetIp()
|
public static IPAddress GetIp()
|
||||||
{
|
{
|
||||||
string hostName = Dns.GetHostName(); // Retrive the Name of HOST
|
string hostName = Dns.GetHostName(); // Retrive the Name of HOST
|
||||||
string myIP = Dns.GetHostByName(hostName).AddressList[1].ToString();// Get the IP
|
var ipList = Dns.GetHostByName(hostName).AddressList;
|
||||||
|
string myIP = ipList[ipList.Count() - 1].ToString();// Get the IP
|
||||||
return IPAddress.Parse(myIP);
|
return IPAddress.Parse(myIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Init()
|
private void Init()
|
||||||
{
|
{
|
||||||
endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
|
endPoint = new IPEndPoint(GetIp(), port);
|
||||||
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
managerThread = new Dictionary<Socket, Thread>();
|
managerThread = new Dictionary<Socket, Thread>();
|
||||||
clients = new List<Socket>();
|
clients = new List<Socket>();
|
||||||
|
|
Loading…
Add table
Reference in a new issue