using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1.UDP;

class UdpClientTest
{
    public static void Test()
    {
        Socket socket = new Socket(socketType: SocketType.Dgram, protocolType: ProtocolType.Udp);
        EndPoint endPoint = new DnsEndPoint("ChargingVerify01.taiwanebus.net", 14011);
        socket.Connect(endPoint);
        var sendResult = socket.Send(
            buffer: new byte[] { 1, 2, 3 },
            size: 3,
            socketFlags: SocketFlags.None
            );
        var buffer = new byte[100];
        var receivedData = socket.Receive(buffer);
        Console.WriteLine(receivedData);


        UdpClient udpClient = new UdpClient();
        udpClient.Connect("ChargingVerify01.taiwanebus.net", 14011);
        udpClient.ReceiveAsync().ContinueWith(UdpClientResultHandler);
        var tt = udpClient.Send(
            dgram: new byte[] { 1, 2, 3 },
            bytes: 3
            );
        Console.WriteLine(tt);
        Task.Delay(30_000).Wait();
    }

    private static void UdpClientResultHandler(Task<UdpReceiveResult> task)
    {

    }
}