You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i made custom message in client project
Below is the client code.
<NewNetworkManager.cs>
public class CustomGameServerMessageTypes
{
public const short ReceiveAuthenticate = 900;
public const short ShutdownMessage = 901;
public const short MaintenanceMessage = 902;
public const short HelloMessage = 903;
}
public struct HelloMessage : NetworkMessage
{
public string data;
public HelloMessage(string value)
{
data = value;
//Debug.Log($"메시지 생성 완료 : {data}, {this.GetType()}");
}
}
////////////////////////////////////////////
<Startup.cs>
public class Startup : MonoBehaviour
{
NewNetworkManager _nm;
MessageWindow _messageWindow;
// Use this for initialization
void Start()
{
_nm = NewNetworkManager.Instance;
_nm.OnDisconnected.AddListener(OnDisconnected);
_nm.OnConnected.AddListener(OnConnected);
NetworkClient.RegisterHandler<ShutdownMessage>(OnServerShutdown);
NetworkClient.RegisterHandler<MaintenanceMessage>(OnMaintenanceMessage);
//NetworkClient.RegisterHandler<HelloMessage>(HelloMessage); -> here i registe my message
_messageWindow = MessageWindow.Instance;
Debug.Log($"네트워크 메니저 인스턴스 아이디: {_nm.GetInstanceID()}");
}
private void OnMaintenanceMessage(MaintenanceMessage msg)
{
var message = msg;
_messageWindow.Title.text = "Maintenance Shutdown scheduled";
_messageWindow.Message.text = string.Format("Maintenance is scheduled for: {0}", message.ScheduledMaintenanceUTC.ToString("MM-DD-YYYY hh:mm:ss"));
_messageWindow.gameObject.SetActive(true);
}
private void OnServerShutdown(ShutdownMessage msg)
{
_messageWindow.Title.text = "Shutdown In Progress";
_messageWindow.Message.text = "Server has issued a shutdown.";
_messageWindow.gameObject.SetActive(true);
NetworkClient.Disconnect();
}
private void OnConnected() -> Send message here!!
{
Debug.Log("connected!@!@!@!@! -> hello message 보내기");
HelloMessage helloMessage = new HelloMessage("안녕하세요");
NetworkClient.Send(helloMessage, Channels.Reliable);
Debug.Log($"메시지 id : {helloMessage.GetType().GetType()}");
}
private void OnDisconnected(int? code)
{
_messageWindow.Title.text = "Disconnected!";
_messageWindow.Message.text = "You were disconnected from the server";
_messageWindow.gameObject.SetActive(true);
}
}
then i got error in my server how i registe my client message in server(my project based in MpsSamples-main\UnityMirror )
*i registed message in server code already, but it doesn't work
Below is the server code.
<UnityNetworkServer.cs>
public class NewNetworkManager : NetworkManager
{
public static NewNetworkManager Instance { get; private set; }
public ConnectedEvent OnConnected = new ConnectedEvent();
public DisconnectedEvent OnDisconnected = new DisconnectedEvent();
public class ConnectedEvent : UnityEvent { }
public class DisconnectedEvent : UnityEvent<int?> { }
public override void Awake()
{
base.Awake();
Instance = this;
}
public override void Start()
{
base.Start();
this.StartClient();
}
public override void OnClientConnect()
{
base.OnClientConnect();
Debug.Log("client connected");
OnConnected.Invoke();
}
public override void OnClientDisconnect()
{
base.OnClientDisconnect();
Debug.Log("client disconnected");
OnDisconnected.Invoke(null);
}
public override void OnClientError(Exception ex) { }
public override void OnClientNotReady() { }
public override void OnClientChangeScene(string newSceneName, SceneOperation sceneOperation, bool customHandling) { }
public override void OnClientSceneChanged()
{
base.OnClientSceneChanged();
}
public override void OnStartClient()
{
base.OnStartClient();
}
public override void OnStopClient() { }
}
public class CustomGameServerMessageTypes
{
public const short ReceiveAuthenticate = 900;
public const short ShutdownMessage = 901;
public const short MaintenanceMessage = 902;
public const short HelloMessage = 903;
}
public struct ReceiveAuthenticateMessage : NetworkMessage
{
public string PlayFabId;
}
public struct ShutdownMessage : NetworkMessage { }
[Serializable]
public struct MaintenanceMessage : NetworkMessage
{
public DateTime ScheduledMaintenanceUTC;
}
public struct HelloMessage : NetworkMessage
{
public string data;
public HelloMessage(string value)
{
data = value;
//Debug.Log($"메시지 생성 완료 : {data}, {this.GetType()}");
}
}
blow it's my server error
Unknown message id: 14476 for connection: connection(1). This can happen if no handler was registered for this message
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
i made custom message in client project
Below is the client code.
then i got error in my server how i registe my client message in server(my project based in MpsSamples-main\UnityMirror )
*i registed message in server code already, but it doesn't work
Below is the server code.
blow it's my server error
Beta Was this translation helpful? Give feedback.
All reactions