Files
Gen_Hack-and-Slash-Roguelite/Client/Assets/Scripts/Test/UdpClientTest.cs

39 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Google.Protobuf;
using Network;
using Protocol;
using System.Collections.Generic;
using UnityEngine;
namespace Test
{
public class UdpClientTest : MonoBehaviour
{
private async void Start()
{
var request = new LoginRequest
{
Username = "原神启动谁会通过UDP启动啊喂",
Password = "20200928",
};
var requestBytes = new byte[request.CalculateSize()];
request.WriteTo(requestBytes);
var sendBytes = new List<byte>
{
(byte)MessageType.LoginRequest
};
sendBytes.AddRange(requestBytes);
var responseBytes = await UnityUdpClient.Instance.SendAndReceiveData(sendBytes.ToArray());
if (responseBytes.Length == 0) return;
else if (responseBytes[0] == (byte)MessageType.LoginResponse)
{
var response = LoginResponse.Parser.ParseFrom(responseBytes[1..]);
Debug.Log($"Received response: {response}");
}
}
}
}