Error when trying to connect to room by name

Options
I created a Unity app that connect to Photon Realtime using PUN. This part work well and I can send and receive events. The second part is a .NET app (using the .NET sdk) that try to connect to the same room. I can connect to Photon, the authentication is ok and I can connect to the lobby. But, when I'm trying to connect to the room (created on the Unity side), I always receive this error: Getting into game failed, client stays on masterserver: OperationResponse 226: ReturnCode: 32758 (Game does not exists). Parameters: {}. The room exist. I use the same name on both side and at the same time, I can send and receive event in the Unity app. Both side use the same region. What's wrong?

Here is the Unity code:

using UnityEngine;
using System.Collections;

public class PhotonController : Photon.PunBehaviour
{
// Use this for initialization
void Start () {
// Set debug level
PhotonNetwork.logLevel = PhotonLogLevel.Full;

// Connect Photon
PhotonNetwork.ConnectUsingSettings("0.1");
}

public override void OnConnectedToMaster()
{
// Join random room
Debug.Log("Connected to master");
}

public override void OnJoinedLobby(){
// Join random room
bool result = PhotonNetwork.CreateRoom("simulateur", new RoomOptions() { isOpen = true, isVisible = true, maxPlayers = 4 }, TypedLobby.Default);
}

public override void OnCreatedRoom()
{
Debug.Log("Room: simulateur was created");
}

void OnJoinedRoom(){
Debug.Log("In room: simulateur");
}

public override void OnDisconnectedFromPhoton()
{
Debug.Log("Disconnected from Photon");
}

// Update is called once per frame
void Update () {

}

void OnGUI(){
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
}
}


And here is the code for the .NET app:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

using ExitGames.Client.Photon;
using ExitGames.Client.Photon.LoadBalancing;

namespace SocialMainController
{
public partial class frmMainController : Form
{
// Client
CustomClient client;
delegate void UpdateViewDelegate();

public frmMainController()
{
InitializeComponent();
}
private void frmMainController_Load(object sender, EventArgs e)
{
// Create new client
client = new CustomClient(true);
client.OnUpdate = this.UpdateView;
bool result = client.IsConnectedAndReady;
}

private void UpdateView()
{
if (this.lblConnectServer.InvokeRequired)
{
UpdateViewDelegate d = new UpdateViewDelegate(this.UpdateView);
this.Invoke(d);
}
else
{
// Update ui
lblConnectServer.Text = client.State.ToString();
}
}

private void cmdConnectRoom_Click(object sender, EventArgs e)
{
// Feedback
lblConnectRoom.Text = "Connecting...";

// Join room
bool result = client.OpJoinRoom("simulateur");
}

private void cmdSendEvent_Click(object sender, EventArgs e)
{
// Send event
byte evCode = 0;
byte[] content = new byte[] { };
bool reliable = true;
bool result = client.OpRaiseEvent(evCode, content, reliable, new RaiseEventOptions() { Receivers = ReceiverGroup.All });
}
}
public class CustomClient : LoadBalancingClient
{
public CustomClient(bool createGameLoopThread)
: base()
{
if (createGameLoopThread)
{
this.updateThread = new Thread(this.UpdateLoop);
this.updateThread.IsBackground = true;
this.updateThread.Start();
}

// Player
this.NickName = "Player_" + (SupportClass.ThreadSafeRandom.Next() % 1000);
this.LocalPlayer.SetCustomProperties(new Hashtable() { { "class", "tank" + (SupportClass.ThreadSafeRandom.Next() % 99) } });

// Connection properties
this.AppId = "blablabla";
this.AppVersion = "0.1";
this.ConnectToRegionMaster("us");
}

protected override Player CreatePlayer(string actorName, int actorNumber, bool isLocal, Hashtable actorProperties)
{
CustomPlayer tmpPlayer = null;
if (this.CurrentRoom != null)
{
tmpPlayer = (CustomPlayer)this.CurrentRoom.GetPlayer(actorNumber);
}

if (tmpPlayer == null)
{
tmpPlayer = new CustomPlayer(actorName, actorNumber, isLocal);
tmpPlayer.CacheProperties(actorProperties);

if (this.CurrentRoom != null)
{
this.CurrentRoom.StorePlayer(tmpPlayer);
}
}
else
{
this.DebugReturn(DebugLevel.ERROR, "Player already listed: " + actorNumber);
}

return tmpPlayer;
}

// Game loop variables
private readonly Thread updateThread;

private int intervalDispatch = 50;
private int lastDispatch = Environment.TickCount;
private int intervalSend = 50;
private int lastSend = Environment.TickCount;
private int intervalMove = 500;
private int lastMove = Environment.TickCount;
internal int lastUiUpdate = Environment.TickCount;
private int intervalUiUpdate = 1000;

public Action OnUpdate { get; set; }

// Game loop
public void UpdateLoop()
{
while (true)
{
Update();
Thread.Sleep(10);
}
}

// Update
public virtual void Update()
{
if (Environment.TickCount - this.lastDispatch > this.intervalDispatch)
{
this.lastDispatch = Environment.TickCount;
this.loadBalancingPeer.DispatchIncomingCommands();
}

if (Environment.TickCount - this.lastSend > this.intervalSend)
{
this.lastSend = Environment.TickCount;
this.loadBalancingPeer.SendOutgoingCommands();
}

if (Environment.TickCount - this.lastUiUpdate > this.intervalUiUpdate)
{
this.lastUiUpdate = Environment.TickCount;
if (this.OnUpdate != null)
{
this.OnUpdate();
}
}
}

public override void OnEvent(EventData photonEvent)
{
switch (photonEvent.Code)
{
case EventCode.ErrorInfo:
break;
case EventCode.Join:
break;
}
}
}

}

Thanks for your help!

Answers

  • kittyLLLL
    Options
    Your issue might be that Photon doesn't automatically join the Lobby anymore. Go to your Photon Serversettings and enable Auto join lobby. Alternatively also add this line of code after PhotonNetwork.ConnectUsingSettings("0.1");

    PhotonNetwork.JoinLobby();

    ALSO, you try to create a room once you join the lobby. INSTEAD try to join an existing room.
    Then try calling PhotonNetwork.CreateRoom(); if you fail to join an existing room ( Use the function OnPhotonJoinRoomFailed !! ) There's also the PhotonNetwork.JoinOrCreateRoom function (Something like that at least) which you should take a look at.