私はこれに関するいくつかの本当の助けが必要です。 CRCミスマッチエラーを解決する方法がわかりません。私がやろうとしているすべては私のサーバーに自分のクライアントからバイト配列を送信し、私はこのエラーを取得しています:UNetクライアントの切断エラー:NetworkClient.ConnectのCRCMismatch
UNet Client Disconnect Error: CRCMismatch UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
私は、ドットを接続してネットワークを取得するには今ヶ月以上のためにしようとしてきました正しく動作させるためには、私が取るすべてのステップは、5つのステップに戻る。私は基本的にサークルに行ってきました、私は存在するすべての団結ネットワーキングのチュートリアルをやったし、私はまだ失われています。私は本当にこれを解決するための助けが必要です。誰かがこれで私を助けてくれますか?私はまた以下の完全なコードを添付しました。前もって感謝します!
クライアント側
public class Client : NetworkBehaviour {
NetworkClient client = new NetworkClient();
private const int MAX_CONNECTION = 100;
private string serverIP = "127.0.0.1";
private int port = 5708;
private int hostId;
private int webHostId;
private int reliableChannel;
private int reliableSeqChannel;
private int reliableFragChannel;
private int unreliableChannel;
private int unreliableSeqChannel;
private string playerName;
private int connectionId;
private float connectionTime;
private bool isStarted = false;
private bool isConnected = false;
private bool readyToSendMsg = false;
private byte error;
private GameObject infoDisplayText;
public Texture2D texToSend;
string typeToSend = "Deer";
string idToSend = "1";
int strengthToSend = 80;
int hitPointsToSend = 2;
private string GetPlayerName()
{
switch (Network.player.ipAddress.ToString())
{
case "192.168.1.160":
playerName = "SMO Server";
break;
case "192.168.1.161":
playerName = "SMO Client 1";
break;
case "192.168.1.162":
playerName = "SMO Client 2";
break;
case "192.168.1.163":
playerName = "SMO Client 3";
break;
case "192.168.1.164":
playerName = "SMO Client 4";
break;
default:
playerName = "SMO UNREG";
break;
}
return playerName;
}
private void Start()
{
infoDisplayText = GameObject.Find("InfoDisplay");
client.RegisterHandler(AnimalDataMsgType.SYSTEM_CONNECT, OnConnected);
client.RegisterHandler(AnimalDataMsgType.SYSTEM_DISCONNECT, OnDisconnected);
client.RegisterHandler(AnimalDataMsgType.SYSTEM_ERROR, OnError);
client.Connect(serverIP, port);
}
public void Connect()
{
string pName = GetPlayerName();
if (pName == "")
return;
playerName = pName;
NetworkTransport.Init();
ConnectionConfig cc = new ConnectionConfig();
reliableChannel = cc.AddChannel(QosType.Reliable);
reliableSeqChannel = cc.AddChannel(QosType.ReliableSequenced);
reliableFragChannel = cc.AddChannel(QosType.ReliableFragmented);
unreliableChannel = cc.AddChannel(QosType.Unreliable);
unreliableSeqChannel = cc.AddChannel(QosType.UnreliableSequenced);
cc.PacketSize = 1440;
cc.FragmentSize = 900;
cc.ResendTimeout = 1000;
cc.DisconnectTimeout = 5000;
cc.ConnectTimeout = 1000;
cc.MaxConnectionAttempt = 5;
HostTopology topo = new HostTopology(cc, MAX_CONNECTION);
hostId = NetworkTransport.AddHost(topo, 0);
// Run client/server on different machines
//hostID = NetworkTransport.AddHost(topo, port, null);
connectionId = NetworkTransport.Connect(hostId, serverIP, port, 0, out error);
infoDisplayText = GameObject.Find("InfoDisplay");
infoDisplayText.GetComponent<Text>().text += playerName + " connected.\n";
connectionTime = Time.time;
isConnected = true;
}
private void Update()
{
if (!isConnected)
return;
int recHostId, connectionId, channelId;
byte[] recBuffer = new byte[1024];
int bufferSize = 1024;
int dataSize;
byte error;
NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
switch (recData)
{
case NetworkEventType.ConnectEvent:
Debug.Log("Player " + connectionId + " has connected");
infoDisplayText.GetComponent<Text>().text += "Connected to Server.\n";
break;
}
}
public void SendOnButtonPress()
{
if (readyToSendMsg == true)
SendTexture(texToSend, typeToSend, idToSend, strengthToSend, hitPointsToSend);
}
//Call to send the Texture and a simple string message
public void SendTexture(Texture2D tex, string type, string id, int strength, int hitpoints)
{
AnimalData animalData = new AnimalData();
animalData.Tex = tex.GetRawTextureData();
animalData.Type = type;
animalData.Id = id;
animalData.Strength = strength;
animalData.Hitpoints = hitpoints;
client.Send(AnimalDataMsgType.animalData, animalData);
}
private void OnConnected(NetworkMessage netMsg)
{
readyToSendMsg = true;
Debug.Log("Connected to server");
}
private void OnDisconnected(NetworkMessage netMsg)
{
readyToSendMsg = false;
Debug.Log("Disconnected from server");
}
private void OnError(NetworkMessage netMsg)
{
//SystemErrorMessage errorMsg = reader.SmartRead<SystemErrorMessage>();
// Debug.Log("Error connecting with code " + errorMsg.errorCode);
Debug.Log("Error connecting.");
}
サーバー側
public class Server : NetworkBehaviour
{
private const int MAX_CONNECTION = 100;
private int port = 5708;
private int hostId;
private int webHostId;
private int reliableChannel;
private int reliableSeqChannel;
private int reliableFragChannel;
private int unreliableChannel;
private int unreliableSeqChannel;
private bool isStarted = false;
private byte error;
private GameObject infoDisplayText;
private void Awake()
{
infoDisplayText = GameObject.Find("InfoDisplay");
}
private void Start()
{
NetworkTransport.Init();
ConnectionConfig cc = new ConnectionConfig();
reliableChannel = cc.AddChannel(QosType.Reliable);
reliableSeqChannel = cc.AddChannel(QosType.ReliableSequenced);
reliableFragChannel = cc.AddChannel(QosType.ReliableFragmented);
unreliableChannel = cc.AddChannel(QosType.Unreliable);
unreliableSeqChannel = cc.AddChannel(QosType.UnreliableSequenced);
HostTopology topo = new HostTopology(cc, MAX_CONNECTION);
hostId = NetworkTransport.AddHost(topo, port, null);
if (NetworkTransport.IsStarted)
{
isStarted = true;
Debug.Log("NetworkTransport is Started.");
infoDisplayText.GetComponent<Text>().text += "NetworkTransport is Started.\n";
}
Debug.Log("Server Started.");
infoDisplayText.GetComponent<Text>().text += "Server Started.\n";
setupRegisterHandler();
}
private void Update()
{
if (!isStarted)
return;
int recHostId, connectionId, channelId;
byte[] recBuffer = new byte[1024];
int bufferSize = 1024;
int dataSize;
byte error;
NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
switch (recData)
{
case NetworkEventType.ConnectEvent:
Debug.Log("Player " + connectionId + " has connected");
infoDisplayText.GetComponent<Text>().text += "Player " + connectionId + " has connected\n";
break;
}
}
// Create a client and connect to the server port
public void setupRegisterHandler()
{
NetworkServer.Listen(port);
Debug.Log("Registering server callbacks");
NetworkServer.RegisterHandler(AnimalDataMsgType.animalData, OnTextureReceive);
}
//Called when texture is received
public void OnTextureReceive(NetworkMessage netMsg)
{
AnimalData animalData = netMsg.ReadMessage<AnimalData>();
string type = animalData.Type;
Debug.Log("Type : " + type);
string id = animalData.Id;
Debug.Log("ID : " + id);
int strength = animalData.Strength;
Debug.Log("Strength : " + strength);
int hitpoints = animalData.Hitpoints;
Debug.Log("Hit Points : " + hitpoints);
//Your Received Texture2D
Texture2D receivedtexture = new Texture2D(1280, 1024);
receivedtexture.LoadRawTextureData(animalData.Tex);
receivedtexture.Apply();
Debug.Log(type + " data received!");
infoDisplayText.GetComponent<Text>().text += type + " data received!\n";
}
}
AnimalDataMsgTypeクラス
public class AnimalDataMsgType
{
public static short animalData = MsgType.Highest + 1;
public static short SYSTEM_CONNECT = MsgType.Connect;
public static short SYSTEM_DISCONNECT = MsgType.Disconnect;
public static short SYSTEM_ERROR = MsgType.Error;
}
AnimalDataクラス
public class AnimalData : MessageBase
{
public byte[] Tex; // data coming from CanvasController
public string Type; // data coming from CanvasController
public string Id; // data coming from GameManager
public int Strength; // data coming from PlayerController
public int Hitpoints; // data coming from PlayerController
public bool IsAlive; // data coming from PlayerController
}
AnimalDataMsgTypeクラスとAnimalDataクラスも提供できますか?それで、私はそれを理解しようとすることができますか? – ZayedUpal
@ZayedUpal投稿の最後にこれらのクラスを追加しました。 – greyBow
HLAPI CRCは、既知のNetworkBehaviourスクリプトのハッシュと、NetworkSettingsAttributeで使用するチャネルです。はい、2つの異なる(互換性のない)Unityプロジェクトまたは同じプロジェクトのバージョンが互いに会話する場合に発生することを意図しています。 アプリケーション(またはクライアントとサーバーが別々の場合はアプリケーション)を再構築してみてください。ネットワークコードを変更して再構築するのを忘れた場合には、この問題が発生する可能性があります。 –