예제 #1
0
        public void Send(ClientStatus sentClient, byte[] sendBytes)
        {
            //UdpClientを作成する
            if (udpClient == null)
            {
                udpClient = new System.Net.Sockets.UdpClient();
            }

            //非同期的にデータを送信する
            udpClient.BeginSend(sendBytes, sendBytes.Length, sentClient.address.ToString(), sentClient.port, SendCallback, udpClient);
        }
예제 #2
0
        private void SendSessionStart(ClientStatus sendServer, ClientStatus clientStatus)
        {
            using (var memory = new MemoryStream())
            {
                using (BinaryWriter binaryStream = new BinaryWriter(memory, System.Text.Encoding.UTF8))
                {
                    binaryStream.Write(Message.IdSessionStart);
                    binaryStream.Write(clientStatus.nickName);
                }

                Send(sendServer, memory.ToArray());
            }
        }
예제 #3
0
        private void SendNetworkId(ClientStatus client)
        {
            using (var memory = new MemoryStream())
            {
                using (BinaryWriter binaryStream = new BinaryWriter(memory, System.Text.Encoding.UTF8))
                {
                    binaryStream.Write(Message.IdGetNetworkId);
                    binaryStream.Write(client.networkId);


                    Debug.Log("return msg: ---------------");
                    Debug.Log("nickName:" + client.nickName);
                    Debug.Log("address:" + client.address);
                    Debug.Log("port:" + client.port);
                    Debug.Log("networkId:" + client.networkId);
                    Debug.Log("---------------------------");
                }

                Send(client, memory.ToArray());
            }
        }
예제 #4
0
        public UDPClient(int setPort, int setServerPort, string name) : base(setPort)
        {
            // ホスト名を取得する
            string hostname = Dns.GetHostName();

            // ホスト名からIPアドレスを取得する
            IPAddress[] adrList = Dns.GetHostAddresses(hostname);

            surverStatus          = new ClientStatus();
            surverStatus.address  = adrList[3];
            surverStatus.port     = setServerPort;
            surverStatus.nickName = "server";


            status          = new ClientStatus();
            status.address  = adrList[1];
            status.port     = sendPort;
            status.nickName = name;

            Console.WriteLine("MyPort:" + myPort);
            Console.WriteLine("ServerPort:" + sendPort);

            SendSessionStart(surverStatus, status);
        }