So, I’m trying to make an online game, and I’m working on the online (Duh), but I can only connect with localhost, if I use External IP Or another computer does it fails.
I DO NOT want to use Master Server, because i’m planning to make the online server free for all, so they can Set-Up their own Server
and Yes, I got portforward already, I tried with several ports, 2550, 25600, all with no luck.
I already tries UseNAT, and the connection test script says everyone can connect to me.
to end this, here’s the full script:
//Strings
private var ServerPortString : String;
private var NOfPlayersServerString : String;
var ClientPortString : String;
var Ip : String;
//ints
var ServerPort : int;
var NOfPlayersServer : int;
private var playerCount: int = 0;
var ClientPort : int;
//true/false
var IsCreatingServer = true;
var IsConnectingToClient = false;
var IsOnMainMenu = false;
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}
function StartServer() {
Network.InitializeServer(NOfPlayersServer, ServerPort, true);
MasterServer.RegisterHost("Worldz", "Test Server", "I don't know what the hell is this.");
}
function OnGUI() {
if(IsCreatingServer){
ServerPortString = GUI.TextField (Rect (Screen.width/2-150,Screen.height/1.5-20, 300, 20), ServerPortString, 25);
NOfPlayersServerString = GUI.TextField (Rect (Screen.width/2-150,Screen.height/1.3-20, 300, 20), NOfPlayersServerString, 25);
ServerPort = int.Parse(ServerPortString);
NOfPlayersServer = int.Parse(NOfPlayersServerString);
if(GUI.Button (Rect (Screen.width/2-100,Screen.height/1.4-25,200,50),"Create Server")){
StartServer();
}
}
if(IsConnectingToClient){
Ip = GUI.TextField (Rect (Screen.width/2-150,Screen.height/1.5-20, 300, 20), Ip, 25);
ClientPortString = GUI.TextField (Rect (Screen.width/2-150,Screen.height/1.2-20, 300, 20), ClientPortString, 25);
ClientPort = int.Parse(ClientPortString);
if(GUI.Button (Rect (Screen.width/2-100,Screen.height/2-25,200,50),"Connect to the Server")){
ConnectToServer();
}
if(GUI.Button (Rect (Screen.width/2-100,Screen.height/1.3-25,200,50),"Back")){
IsConnectingToClient = false;
IsOnMainMenu = true;
}
}
if(IsOnMainMenu){
if(GUI.Button (Rect (Screen.width/2-100,Screen.height/2-25,200,50),"Connect to a Server")){
IsOnMainMenu = false;
IsConnectingToClient = true;
}
if(GUI.Button (Rect (Screen.width/2-100,Screen.height/1.5-25,200,50),"Create a Server")){
IsOnMainMenu = false;
IsCreatingServer = true;
}
}
}
function ConnectToServer() {
Network.Connect(Ip,ClientPort);
}
function Update() {
if(ServerPortString == null){
ServerPortString = ("0");
}
if(ClientPortString == null){
ServerPortString = ("0");
}
if(NOfPlayersServerString == null){
NOfPlayersServerString = ("0");
}
}
function OnServerInitialized() {
Debug.Log("Server initialized and ready");
}
function OnPlayerConnected(player: NetworkPlayer) {
Debug.Log("Player " + playerCount++ +
" connected from " + player.ipAddress +
":" + player.port);
// Populate a data structure with player information ...
}
function OnPlayerDisconnected(player: NetworkPlayer) {
Debug.Log("Clean up after player " + player);
Network.RemoveRPCs(player);
Network.DestroyPlayerObjects(player);
}
