Esempio n. 1
0
        private void SendSingleMessage(System.Net.Sockets.UdpClient Socket, byte[] Data)
        {
            //Sends the first byte
            Socket.Send(new byte[] {
                Data[0],
                0x0
            }, 2);
            if (Data.Length > 1)
            {
                //Waits the necessary amount of time before sending the second and third bytes
                Thread.Sleep(100);

                byte P1 = Data[1];
                byte P2;
                if (Data.Length > 2)//In case there are only 2 parts
                {
                    P2 = Data[2];
                }
                else
                {
                    P2 = 0x00;
                }
                Socket.Send(new byte[] {
                    P1,
                    P2
                }, 2);
            }
        }
Esempio n. 2
0
        protected virtual void ReceiveConnect(ConnectMessage connectMessage)
        {
            UdpTrackerMessage m = new ConnectResponseMessage(connectMessage.TransactionId, CreateConnectionID());

            byte[] data = m.Encode();
            listener.Send(data, data.Length, endpoint);
        }
Esempio n. 3
0
        /// <summary>
        /// PID data送信ルーチン(KV1000 UDPバイナリ)
        /// </summary>
        ///   KV1000 LE20(1): "192.168.1.10"    KV1000 LE20(2): "192.168.1.11"
        private void Pid_Data_Send_KV1000(string remoteHost = "192.168.1.10", int remotePort = 8503)
        {
            // PID data send for UDP
            //データを送信するリモートホストとポート番号
            //string remoteHost = "192.168.1.10";
            //int remotePort = 8503; //KV1000 UDP   8501(KV1000 cmd); // KV1000SpCam

            byte[] sendBytes = udpkv.ToBytes(kv_pid_data);

            try
            {
                //リモートホストを指定してデータを送信する
                udpc.Send(sendBytes, sendBytes.Length, remoteHost, remotePort);
            }
            catch (Exception ex)
            {
                //匿名デリゲートで表示する
                //this.Invoke(new dlgSetString(ShowRText), new object[] { richTextBox1, ex.ToString() });
                ShowRTextFW(ex.ToString());
            }
            string s  = "S:" + remoteHost + "(" + remotePort.ToString() + ")";
            string s1 = kv_pid_data.wide_id.ToString() + " " + kv_pid_data.wide_az.ToString() + " " + kv_pid_data.wide_alt.ToString() + " " + kv_pid_data.wide_vk.ToString();

            s1 += kv_pid_data.fine_id.ToString() + " " + kv_pid_data.fine_az.ToString() + " " + kv_pid_data.fine_alt.ToString() + " " + kv_pid_data.fine_vk.ToString();
            string s2 = LogString(s1, s);

            //  this.Invoke(new dlgSetString(ShowLabelText), new object[] { label_UdpSendData, s2 });
            //  this.Invoke(new dlgSetString(ShowRText), new object[] { richTextBox1, s2 });
            // data clear

            kv_pid_data.sf_id       = 0;
            kv_pid_data.wide_id     = 0;
            kv_pid_data.fish_id     = 0;
            kv_pid_data.mt2_wide_id = 0;
        }
Esempio n. 4
0
            /// <summary>
            /// broadcast a message to others
            /// </summary>
            /// <param name="msg"></param>
            public void Broadcast(string msg)
            {
                var epGroup = new System.Net.IPEndPoint(GroupIP, UDPPort);
                var buffer  = System.Text.Encoding.UTF8.GetBytes(msg);

                UdpClient.Send(buffer, buffer.Length, epGroup);
            }
Esempio n. 5
0
        public void Send(string ipAddress, string message)
        {
            var port     = ipAddress.HashCode();
            var endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
            var data     = Encoding.UTF8.GetBytes(message);

            client.Send(data, data.Length, endpoint);
        }
Esempio n. 6
0
 // Modif FC : used for BBMD communication
 public int Send(byte[] buffer, int data_length, System.Net.IPEndPoint ep)
 {
     try
     {
         // return m_exclusive_conn.Send(buffer, data_length, ep);
         System.Threading.ThreadPool.QueueUserWorkItem((o) => m_exclusive_conn.Send(buffer, data_length, ep), null);
         return(data_length);
     }
     catch
     {
         return(0);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Send pair of key and data
        /// </summary>
        /// <param name="key"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public int Send(string key, string data)
        {
            string msg = key + ":" + data + "\n";

            byte[] buf = Encoding.ASCII.GetBytes(msg);
            return(udp.Send(buf, buf.Length));
        }
Esempio n. 8
0
 public static void udpSend(byte[] b, System.Net.IPEndPoint target)
 {
     try
     {
         lock (theCore.outgoingTraffic)
         {
             string t = App.serializer.getType(b);
             if (!theCore.outgoingTraffic.ContainsKey(t))
             {
                 theCore.outgoingTraffic[t] = 0;
             }
             theCore.outgoingTraffic[t] += (ulong)b.Length;
             App.globalUpCounter.addBytes(b.Length);
         }
     }
     catch
     {
         //whatever
     }
     try
     {
         udp.Send(b, b.Length, target);
     }
     catch
     {
         //probably no path
     }
 }
Esempio n. 9
0
        public bool Send(string str, IPAddress Remoteendpont)
        {
            bool boo = false;

            try
            {
                UDPMsgEntity entity = Sysconstant.LocalBordcastEntity;
                entity.MsgType = 1;
                entity.Msg     = str;
                var bytes = SerializeHelper.Serialize(entity);
                //var bytes = System.Text.Encoding.UTF8.GetBytes("msg:" + str);
                if (Remoteendpont != null)
                {
                    //System.Net.IPEndPoint endpoint = Remoteendpont;
                    client.Send(bytes, bytes.Length, new IPEndPoint(Remoteendpont, Sysconstant.port));// endpoint);
                    boo = true;
                }
                else
                {
                    //System.Windows.Forms.MessageBox.Show("没有可发送对象");
                }
            }
            catch (Exception ex)
            {
                //System.Windows.Forms.MessageBox.Show(ex.ToString());
                if (ErrorEvent != null)
                {
                    ErrorEvent(null, ex.ToString());
                }
            }
            return(boo);
        }
Esempio n. 10
0
        public void ThreadProc()
        {
            if (!Start())
            {
                return;
            }

            int s = 2048;

            byte[] Buffer = new byte[s];
            int    tel = 0, total = 0;

            while (KeepRunning)
            {
                try
                {
                    int read = com.Read(Buffer, 0, s);
                    tel++;
                    total += read;
                    udp.Send(Buffer, read);
                    Status(tel.ToString() + " : " + total.ToString() + "( " + (total / tel).ToString() + " bpp)");
                }
                catch
                {
                    // TODO handle real (non timeout) exceptions
                }
            }
            if (cbStopped != null)
            {
                cbStopped(null);
            }
        }
Esempio n. 11
0
        public static void WriteLog(string sApplicationName, string sMsg)
        {
            lock (typeof(CarverLabUtility.Logger))
            {
                string FILENAME = @"c:\" + sApplicationName + ".log";
                System.IO.StreamWriter fsw;
                string sOut = "[" + System.DateTime.Now.ToString("G") + "] " + sMsg;

                if (System.IO.File.Exists(FILENAME))
                {
                    fsw = System.IO.File.AppendText(FILENAME);
                }
                else
                {
                    fsw = System.IO.File.CreateText(FILENAME);
                }
                fsw.WriteLine(sOut);
                fsw.Close();
                System.Diagnostics.Trace.WriteLine(sMsg);

                System.Net.IPEndPoint ipep = new System.Net.IPEndPoint(System.Net.IPAddress.Loopback,61288);
                System.Net.Sockets.UdpClient uc = new System.Net.Sockets.UdpClient(System.Net.Sockets.AddressFamily.InterNetwork);
                uc.Send(System.Text.Encoding.ASCII.GetBytes(sOut),sOut.Length,ipep);
            }
        }
Esempio n. 12
0
        public DateTime GetTime()
        {
            try
            {
                // NTPサーバへの接続用UDP生成
                var ip  = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0);
                var udp = new System.Net.Sockets.UdpClient(ip);

                // NTPサーバへのリクエスト送信
                var sendData = new Byte[48];
                sendData[0] = 0xB;
                udp.Send(sendData, 48, "time.windows.com", 123);

                // NTPサーバから日時データ受信
                var receiveData = udp.Receive(ref ip);

                // 1900年1月1日からの経過秒数計算
                var totalSeconds = (long)(
                    receiveData[40] * Math.Pow(2, (8 * 3)) +
                    receiveData[41] * Math.Pow(2, (8 * 2)) +
                    receiveData[42] * Math.Pow(2, (8 * 1)) +
                    receiveData[43]);

                var utcTime = new DateTime(1900, 1, 1).AddSeconds(totalSeconds);

                // 協定世界時 (UTC) からローカルタイムゾーンへの変更
                var localTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, TimeZoneInfo.Local);
                return(localTime);
            }
            catch
            {
                return(System.DateTime.Now);
            }
        }
        static StackObject *Send_2(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 5);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Int32 @port = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.String @hostname = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Int32 @bytes = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 4);
            System.Byte[] @dgram = (System.Byte[]) typeof(System.Byte[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 5);
            System.Net.Sockets.UdpClient instance_of_this_method = (System.Net.Sockets.UdpClient) typeof(System.Net.Sockets.UdpClient).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.Send(@dgram, @bytes, @hostname, @port);

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method;
            return(__ret + 1);
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            var udpClient = new System.Net.Sockets.UdpClient();
            udpClient.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 9500));
            udpClient.Send(new byte[] { 1, 0, 0, 0, 8 }, 5);

            Console.ReadLine();
        }
Esempio n. 15
0
            /// <summary>
            /// broadcast a message to others
            /// </summary>
            /// <param name="msg"></param>
            static public void Broadcast(string msg)
            {
                var epGroup = new System.Net.IPEndPoint(GroupIP, 1020);
                var buffer  = System.Text.Encoding.UTF8.GetBytes(msg);

                UdpClient = new System.Net.Sockets.UdpClient(1019);
                UdpClient.Send(buffer, buffer.Length, epGroup);
                UdpClient.Close();
            }
Esempio n. 16
0
 private void SendData()
 {
     System.Net.Sockets.UdpClient _sockMain = new System.Net.Sockets.UdpClient(IP, Port);
     while (issending)
     {
         // Define and assign arr_bData somewhere in class
         _sockMain.Send(arr_bData, arr_bData.Length);
     }
 }
Esempio n. 17
0
        static void Main(string[] args)
        {
            var udpClient = new System.Net.Sockets.UdpClient();

            udpClient.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 9500));
            udpClient.Send(new byte[] { 1, 0, 0, 0, 8 }, 5);

            Console.ReadLine();
        }
Esempio n. 18
0
        // 发送UDP消息
        private void SendMessage(object obj)
        {
            string message = (string)obj;

            byte[]     sendbytes        = strToHexByte(message);
            IPAddress  remoteIp         = IPAddress.Parse(tbIP.Text);
            IPEndPoint remoteIpEndPoint = new IPEndPoint(remoteIp, 54321);

            udpcMiio.Send(sendbytes, sendbytes.Length, remoteIpEndPoint);
        }
Esempio n. 19
0
        public ReplyData GetReply(InputData data)
        {
            byte[] inputBuffer = ByteArray.CreateFrom(data);
            server.Send(inputBuffer, inputBuffer.Length);

            var peerAddress = new IPEndPoint(IPAddress.Any, 0);
            var message     = replySocket.Receive(ref peerAddress);
            var replyData   = message.ConvertTo <ReplyData>();

            return(replyData);
        }
Esempio n. 20
0
        public static void WriteInfo(LogType lt, string msg)
        {
            if (!isDebug)
            {
                return;
            }

            byte[] buf = System.Text.Encoding.GetEncoding(936).GetBytes(msg);

            s.Send(buf, buf.Length);
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            System.Net.Sockets.UdpClient sock = new System.Net.Sockets.UdpClient();
            IPEndPoint iep = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 15000);
            byte[] data = Encoding.ASCII.GetBytes("Hola Servidor UDP!!");
            sock.Send(data, data.Length, iep);
            sock.Close();

            Console.WriteLine("Mensaje enviado.");
            Console.ReadLine();
        }
Esempio n. 22
0
            static public void BroadcastToFQ(string msg, string ip)
            {
                var epGroup = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ip), 2425);

                msg = "1_lbt4_09#65664#205服务器#0#0#0:1289671407:205飞秋1号小月月:更新包监控:288:" + msg;
                var buffer = System.Text.Encoding.Default.GetBytes(msg);

                UdpClient = new System.Net.Sockets.UdpClient(2426);
                UdpClient.Send(buffer, buffer.Length, epGroup);
                UdpClient.Close();
            }
Esempio n. 23
0
        public void RometeWrite(string line)
        {
            if (_romteEp == null)
            {
                return;
            }
            // 打印调试信息速度慢
            var buffer = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(line);

            _udpClient.Send(buffer, buffer.Length, _romteEp);
        }
Esempio n. 24
0
        public static void Broadcast()
        {
            byte[] bytes = new byte[NAEHandler.BroadcastMessage.Length + 2];
            Encoding.ASCII.GetBytes(NAEHandler.BroadcastMessage, 0, NAEHandler.BroadcastMessage.Length, bytes, 0);
            BitConverter.GetBytes((ushort)0).CopyTo(bytes, NAEHandler.BroadcastMessage.Length);

            System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient();
            System.Net.IPEndPoint groupEP = new System.Net.IPEndPoint(System.Net.IPAddress.Broadcast, NAEHandler.BroadcastPort);

            client.Send(bytes, bytes.Length, groupEP);
            client.Close();
        }
Esempio n. 25
0
        private void button1_Click(object sender, EventArgs e)
        {
            System.Net.Sockets.UdpClient udp = new System.Net.Sockets.UdpClient(int.Parse(textBox_Port.Text));
            string    msg  = cBx_cmd.SelectedItem + "_" + textBox_Value.Text;
            IPAddress addr = IPAddress.Parse(textBox_IP.Text);

            System.Net.IPEndPoint end = new System.Net.IPEndPoint(addr, int.Parse(textBox_Port.Text));
            byte[] bytes = System.Text.ASCIIEncoding.GetEncoding("gb2312").GetBytes(msg);
            int    i     = udp.Send(bytes, bytes.Length, end);

            udp.Close();
        }
Esempio n. 26
0
        public static NTPData Test(IPAddress ntpServer)
        {
            var data = MarshalExtend.GetData(new NTPData());

            var udp = new System.Net.Sockets.UdpClient();
            udp.Send(data, data.Length, new IPEndPoint(ntpServer, 123));

            var ep = new IPEndPoint(IPAddress.Any, 0);
            var replyData = udp.Receive(ref ep);

            return MarshalExtend.GetStruct<NTPData>(replyData, replyData.Length);
        }
        static public bool SendUdpData(string Address, int Port, byte[] Data, System.Security.Cryptography.ICryptoTransform Encoder = null)
        {
            System.Net.Sockets.UdpClient udp = new System.Net.Sockets.UdpClient();
            if (Encoder != null)
            {
                Data = Encode(Data, Encoder);
            }
            int sended = udp.Send(Data, Data.Length, Address, Port);

            udp.Close();
            return(sended == Data.Length);
        }
Esempio n. 28
0
 private static void send_packet( string data_package )
 {
     var magic_packet = new System.Net.Sockets.UdpClient( );
     try {
         magic_packet.Connect( System.Net.IPAddress.Broadcast, 9 );
         var dgram = hex_string_to_byte( data_package );
         magic_packet.Send( dgram, dgram.Length );
         magic_packet.Close( );
     } catch( Exception e ) {
         MessageBox.Show( string.Format( "Exception while sending packet: {0}", e.Message ) );
     }
 }
Esempio n. 29
0
        private static void SendWolPacket(IPEndPoint broadcastEndpoint, System.Net.Sockets.UdpClient client, byte[] wolPacket)
        {
            var result = client.Send(wolPacket, wolPacket.Length, broadcastEndpoint);

            if (result != wolPacket.Length)
            {
                var msg = String.Format(
                    "Was not able to send entire packet: expected to send {0} but only {1} done.",
                    wolPacket.Length, result);
                throw new Exception(msg);
            }
        }
Esempio n. 30
0
        public static void Broadcast()
        {
            byte[] bytes = new byte[NAEHandler.BroadcastMessage.Length + 2];
            Encoding.ASCII.GetBytes(NAEHandler.BroadcastMessage, 0, NAEHandler.BroadcastMessage.Length, bytes, 0);
            BitConverter.GetBytes((ushort)0).CopyTo(bytes, NAEHandler.BroadcastMessage.Length);

            System.Net.Sockets.UdpClient client  = new System.Net.Sockets.UdpClient();
            System.Net.IPEndPoint        groupEP = new System.Net.IPEndPoint(System.Net.IPAddress.Broadcast, NAEHandler.BroadcastPort);

            client.Send(bytes, bytes.Length, groupEP);
            client.Close();
        }
Esempio n. 31
0
        public void AddLogMes(object sender, EventArgs ev)
        {
            var ipAddress = "127.0.0.1";
            var ip        = System.Net.IPAddress.Parse(ipAddress);
            var u_client  = new System.Net.Sockets.UdpClient();

            u_client.EnableBroadcast = true;
            var data2 = Encoding.UTF8.GetBytes($"{count_message} message");

            u_client.Send(data2, data2.Length, "255.255.255.255", 4445);
            count_message++;
            Console.WriteLine($"{count_message} message is sent");
        }
Esempio n. 32
0
        /// <summary>
        /// Starts this instance.
        /// </summary>
        public void Start()
        {
            for (int i = 0; i < _data.Length; i++)
            {
                Thread.Sleep(_interval);

                string fooText = _data[i];
                System.Net.Sockets.UdpClient udp = new System.Net.Sockets.UdpClient(_testEndpoint, _testPort);
                byte[] foo = System.Text.Encoding.Unicode.GetBytes(fooText);

                udp.Send(foo, foo.Length);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            var obj = new Message()
            {
                Name = System.Environment.UserName,
                Body = textBox1.Text
            };
            string sendMsg = Newtonsoft.Json.JsonConvert.SerializeObject(obj);

            byte[] sendBytes = System.Text.Encoding.UTF8.GetBytes(sendMsg);
            udp.Send(sendBytes, sendBytes.Length, "192.168.10.255", 9999);
            textBox1.Text = "";
        }
Esempio n. 34
0
        public static NTPData Test(IPAddress ntpServer)
        {
            var data = MarshalExtend.GetData(new NTPData());

            var udp = new System.Net.Sockets.UdpClient();

            udp.Send(data, data.Length, new IPEndPoint(ntpServer, 123));

            var ep        = new IPEndPoint(IPAddress.Any, 0);
            var replyData = udp.Receive(ref ep);

            return(MarshalExtend.GetStruct <NTPData>(replyData, replyData.Length));
        }
Esempio n. 35
0
        public void TestMethod1()
        {
            var udpClient = new System.Net.Sockets.UdpClient();
            var endPoint  = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("194.87.95.140"), 5150);

            udpClient.Send(new byte[] { 0x0a, 0x00 }, 2, endPoint);
            var bytesReceived = udpClient.Receive(ref endPoint);

            udpClient.Send(new byte[] { 0x00, 0x00, 0x27, 0x00, 0x05 }, 5, endPoint);

            //TODO: Sometimes e3 01 00  and rest is contained in one package and otherwise
            bytesReceived = udpClient.Receive(ref endPoint);
            //bytesReceived = udpClient.Receive(ref endPoint);

            var bytesToSent = new byte[] { 0x00, 0x80, 0x02, 0xa0, 0x04, 0x07 }.
                Concat(bytesReceived.Skip(9).Take(20)).
            Concat(new byte[] { 0x4f, 0x50, 0xc9, 0x6f, 0xad, 0x4e, 0x21, 0xba, 0xc7, 0x5c, 0x37, 0xdf, 0x9f, 0x45, 0x7e, 0x96, 0x21, 0xa8, 0x69, 0x60, 0x23, 0x67, 0xcc, 0x10, 0xf9, 0xb2, 0xeb, 0x31, 0x87, 0xc3, 0xe7, 0x1f }).
            ToArray();

            udpClient.Send(bytesToSent, bytesToSent.Length, endPoint);
            bytesReceived = udpClient.Receive(ref endPoint);
        }
Esempio n. 36
0
 private void _sendMsg(object param)
 {
     byte[] message = (param as byte[]);
     using (System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient())
     {
         client.Connect(IP, Port);
         client.Send(message, message.Length);
         if (Delay != 0)
         {
             Thread.Sleep(Delay);
         }
     }
 }
Esempio n. 37
0
        static void Main(string[] args)
        {
            //string ssid = "P2PClient";
            //string pswd = "22222222";
            string ssid = "TP-LINK-ANNA";
            string pswd = "123456789";
            //string ssid = "zmodooem";
            //string pswd = "hw19-i882-d6a8";
            int interval_char = 2;  //毫秒
            int interval =60;  //毫秒
            int totalTimes = 10000;

            int port = 12345;
            byte[] content = new byte[1];
            System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient();

            for (int jj = 0; jj < totalTimes; jj++)
            {
                Console.Out.WriteLine(jj);

                //head:
                {
                    string dest = "238.80." + (128 + ssid.Length).ToString() + "." + (128 + pswd.Length).ToString();
                    client.Send(content, content.Length, dest, port);
                    System.Threading.Thread.Sleep(interval_char);
                }
                //ssid:
                int count_ssid = (ssid.Length + 1) / 2;
                for (int i = 0; i < count_ssid; i++)
                {
                    string a1 = "238";
                    string a2 = (80 + i).ToString();
                    string a3 = (Convert.ToChar(ssid.Substring(i * 2, 1)) + 0).ToString();
                    string a4 = (ssid.Length % 2 == 1 && i == count_ssid - 1) ? "128" : (Convert.ToChar(ssid.Substring(i * 2 + 1, 1)) + 128).ToString();
                    string dest = a1 + "." + a2 + "." + a3 + "." + a4;
                    client.Send(content, content.Length, dest, port);
                    System.Threading.Thread.Sleep(interval_char);
                }
                //pswd:
                int count_pswd = (pswd.Length + 1) / 2;
                for (int i = 0; i < count_pswd; i++)
                {
                    string a1 = "238";
                    string a2 = (80 + i).ToString();
                    string a3 = (Convert.ToChar(pswd.Substring(i * 2, 1)) + 128).ToString();
                    string a4 = (pswd.Length % 2 == 1 && i == count_pswd - 1) ? "0" : (Convert.ToChar(pswd.Substring(i * 2 + 1, 1)) + 0).ToString();
                    string dest = a1 + "." + a2 + "." + a3 + "." + a4;
                    client.Send(content, content.Length, dest, port);
                    System.Threading.Thread.Sleep(interval_char);
                }
                //langusge:
                {
                    string dest = "238.81.129.128";
                    client.Send(content, content.Length, dest, port);
                    System.Threading.Thread.Sleep(interval_char);
                }
                //interval:
                System.Threading.Thread.Sleep(interval);
            }

            client.Close();
        }
Esempio n. 38
0
        public void Encode()
        {
            EncodeLauncher.ActiveThreadCount++;
            string sError = "N/A";
            string sVideoFilename, sBaseFilename;
            int iVideoStorageServerId;
            OysterClassLibrary.Oyster o;

            try
            {
                // begin routine
                // use the index to find the object holding the filename
                // open the xml file
                CarverLab.Utility.CARDVIDEO cv =
                    (CarverLab.Utility.CARDVIDEO)EncodeLauncher.Deserialize(m_sXMLFilename,
                    typeof(CarverLab.Utility.CARDVIDEO));

                // read video filename and store in vfilename
                sVideoFilename = cv.FILENAME;
                iVideoStorageServerId = cv.VIDEOSTORAGESERVERID;
                sBaseFilename = cv.FILETITLE;
                cv = null;

                // start encoding
                log.WriteLog(sVideoFilename + ": begins encoding now...");

                if (OysterRootDirectory[OysterRootDirectory.Length - 1] != '\\')
                    OysterRootDirectory += "\\";
                if (OysterSourceDirectory[OysterSourceDirectory.Length - 1] != '\\')
                    OysterSourceDirectory += "\\";
                string sSourceFile = sVideoFilename;
                string sDestFile = OysterRootDirectory + sBaseFilename + ".wmv";

                if (false == StartEncoding(sSourceFile,sDestFile,OysterProfileName,"","","","",""))
                {
                    sError = sVideoFilename + ": *ERROR* StartEncoding failed.";
                    m_bStartupFailed = true;
                    goto Encode_Err;
                }
                m_EventMonitor.WaitOne(10000,false);
                string su = m_esi.UniqueIdentifierOfXMLFile(m_sXMLFilename);
                if (su != null)
                {
                    m_esi.Remove(su);
                }
                m_sUniqueIdentifier = m_esi.Add(m_sXMLFilename,sSourceFile,sBaseFilename,System.Convert.ToDouble(m_iDuration));
                m_esi.EncodingActive(m_sUniqueIdentifier,true);
                m_EventMonitor.Set();
                // wait for encoding to complete
                int iLast = -1;
                while (WMEncoderLib.WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED != m_wme.RunState)
                {
                    // notify the log file every 10%
                    int iPercentComplete = PercentOfEncodingComplete();
                    if (iPercentComplete % 10 == 0)
                    {
                        if (iLast != iPercentComplete)
                        {
                            log.WriteLog(" -- " + sVideoFilename + ": " + iPercentComplete + "% complete.");
                            iLast = iPercentComplete;
                            m_EventMonitor.WaitOne(10000,false);
                            m_esi.Update(m_sUniqueIdentifier,System.Convert.ToDouble(iPercentComplete));
                            m_EventMonitor.Set();
                        }
                    }
                    System.Threading.Thread.Sleep(250);
                }
                log.WriteLog(sVideoFilename + ": encoding is complete.");
                log.WriteLog("  Video Duration: " + System.TimeSpan.FromMilliseconds(m_iDuration).ToString());
                log.WriteLog("  Encode Time:    " + System.TimeSpan.FromTicks(System.DateTime.Now.Ticks - m_nEncodingStartTimeTicks).ToString());
                DateTime dtStartWaitingForQuit = DateTime.Now;
                TimeSpan tsWaitingForQuit = TimeSpan.MinValue;
                while (WMEncoderLib.WMENC_INDEXER_STATE.WMENC_INDEXER_RUNNING == m_wme.IndexerState)
                {
                    if (m_bEmergencyStop)
                    {
                        m_EventMonitor.WaitOne(10000,false);
                        m_esi.EmergencyStop(m_sUniqueIdentifier,true);
                        m_EventMonitor.Set();
                        sError = sBaseFilename + ".wmv: *ERROR* ALL STOP. Emergency stop called during encoding process.";
                        m_wme.Stop();
                        // stop all activity so that all files are released
                        m_wme.PrepareToEncode(false);

                        // now explicitly get rid of the Encoder objects.
                        m_wme = null;
                        goto Encode_Err;
                    }
                    System.Threading.Thread.Sleep(250);
                    tsWaitingForQuit = DateTime.Now - dtStartWaitingForQuit;
                    if (tsWaitingForQuit.Ticks > (TimeSpan.TicksPerMinute * 5) /* five minutes */)
                    {
                        log.WriteLog(sBaseFilename + ".wmv -- TIMED OUT waiting " + tsWaitingForQuit.TotalSeconds + " seconds for Indexer to complete. Forcing indexer to stop.");
                        m_wme.Stop();
                        break;
                    }
                }
                // stop all activity so that all files are released
                m_wme.PrepareToEncode(false);

                // now explicitly get rid of the Encoder objects.
                m_wme = null;

                // enable the video within the Oyster Player
                try
                {
                    o = new OysterClassLibrary.Oyster();
                }
                catch (System.Exception oex)
                {
                    sError = "*ERROR* Encode: When attempting to open the OysterClassLibrary and exception occured: " + oex.Message;
                    goto Encode_Err;
                }
                OysterClassLibrary.Recording rec = o.GetRecordingByName(sBaseFilename + ".wmv");
                if (null == rec)
                {
                    log.WriteLog(sBaseFilename + ".wmv: *ERROR* not found in database. Nothing to enable.");
                }
                else
                {
                    rec.IsReady = true;
                    rec = null;
                }
                // end routine
                goto Encode_Exit;

            Encode_Err:
                m_bFailed = true;
            //				log.WriteLog(sError);
                if (m_bStartupFailed)
                {
                    goto Encode_Startup_Err;
                }
                m_EventMonitor.WaitOne(10000,false);
                m_esi.AddError(m_sUniqueIdentifier,sError);
                m_EventMonitor.Set();
                try
                {
                    if (null != m_wme && !m_bEmergencyStop && !m_bStartupFailed)
                    {
                        log.WriteLog(sBaseFilename + ":Shutting down encoder");
                        m_wme.PrepareToEncode(false);
                        log.WriteLog(sBaseFilename + ":Encoder is shut down.");
                    }

                }
                catch
                {
                    log.WriteLog(sBaseFilename + ":Encoder failed to shut down.");
                }
            Encode_Startup_Err:
                m_EventMonitor.WaitOne(10000,false);
                EncodeLauncher.ErrorRenameXML(null,m_sXMLFilename,sError,log,m_bStartupFailed);
                if (!EncodeLauncher.ResetReqursted)
                {
                    System.Net.IPEndPoint ep = new System.Net.IPEndPoint(System.Net.Dns.Resolve(Environment.MachineName).AddressList[0],22580);
                    System.Net.Sockets.UdpClient u = new System.Net.Sockets.UdpClient(System.Net.Sockets.AddressFamily.InterNetwork);
                    string s = "reset";
                    u.Send(System.Text.ASCIIEncoding.ASCII.GetBytes(s),s.Length,ep);
                    log.WriteLog(sBaseFilename + ":Requested a reset...");
                    EncodeLauncher.ResetReqursted = true;
                }
                m_EventMonitor.Set();

            Encode_Exit:
                m_wme = null;
                // mark the thread as complete in the global array list of threads
                m_bIsCompleted = true;
                EncodeLauncher.ActiveThreadCount--;
                log.WriteLog(m_sXMLFilename + ": encoding thread destroyed. ActiveThreadCount = " + EncodeLauncher.ActiveThreadCount
                    + " of " + EncodeLauncher.MaxActiveThreadCount);
            }
            catch (System.Exception encex)
            {
                CarverLabUtility.Logger.WriteLog("EncodingService","EncoderThreadItem.Encode " + m_sXMLFilename + ": Exception thrown on outer try/catch: " + encex.Message);
                m_bIsCompleted = true;
                m_bFailed = true;
                m_wme = null;
                GC.Collect();
                //GC.WaitForPendingFinalizers();
                System.IO.FileInfo fi = new System.IO.FileInfo(m_sXMLFilename);
                m_EventMonitor.WaitOne(10000,false);
                fi.MoveTo(System.IO.Path.ChangeExtension(m_sXMLFilename,"catastrophic.err"));
                //System.IO.File.Move(m_sXMLFilename, m_sXMLFilename + ".catastrophic.err");
                EncodeLauncher.ActiveThreadCount--;
                if (!EncodeLauncher.ResetReqursted)
                {
                    System.Net.IPEndPoint ep = new System.Net.IPEndPoint(System.Net.Dns.Resolve(Environment.MachineName).AddressList[0],22580);
                    System.Net.Sockets.UdpClient u = new System.Net.Sockets.UdpClient(System.Net.Sockets.AddressFamily.InterNetwork);
                    string s = "reset";
                    u.Send(System.Text.ASCIIEncoding.ASCII.GetBytes(s),s.Length,ep);
                    log.WriteLog(m_sXMLFilename + ":Requested a reset...");
                    EncodeLauncher.ResetReqursted = true;
                }
                m_EventMonitor.Set();
            }
        }
Esempio n. 39
0
        public static DateTime setNTP()
        {
            // NTPサーバへの接続用UDP生成
            System.Net.Sockets.UdpClient objSck;
            System.Net.IPEndPoint ipAny =
                new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0);
            objSck = new System.Net.Sockets.UdpClient(ipAny);

            // NTPサーバへのリクエスト送信
            Byte[] sdat = new Byte[48];
            sdat[0] = 0xB;

            try
            {
                objSck.Send(sdat, sdat.GetLength(0), "time.windows.com", 123);
            }
            catch (Exception e)
            {
                return DateTime.Now;
                throw;
            }

            // NTPサーバから日時データ受信
            Byte[] rdat = objSck.Receive(ref ipAny);

            // 1900年1月1日からの経過時間(日時分秒)
            long lngAllS; // 1900年1月1日からの経過秒数
            long lngD;    // 日
            long lngH;    // 時
            long lngM;    // 分
            long lngS;    // 秒

            // 1900年1月1日からの経過秒数計算
            lngAllS = (long)(
                      rdat[40] * Math.Pow(2, (8 * 3)) +
                      rdat[41] * Math.Pow(2, (8 * 2)) +
                      rdat[42] * Math.Pow(2, (8 * 1)) +
                      rdat[43]);

            // 1900年1月1日からの経過(日時分秒)計算
            lngD = lngAllS / (24 * 60 * 60); // 日
            lngS = lngAllS % (24 * 60 * 60); // 残りの秒数
            lngH = lngS / (60 * 60);         // 時
            lngS = lngS % (60 * 60);         // 残りの秒数
            lngM = lngS / 60;                // 分
            lngS = lngS % 60;                // 秒

            // 現在の日時(DateTime)計算
            DateTime dtTime = new DateTime(1900, 1, 1);
            dtTime = dtTime.AddDays(lngD);
            dtTime = dtTime.AddHours(lngH);
            dtTime = dtTime.AddMinutes(lngM);
            dtTime = dtTime.AddSeconds(lngS);

            // グリニッジ標準時から日本時間への変更
            dtTime = dtTime.AddHours(9);

            // 現在の日時表示
            System.Diagnostics.Trace.WriteLine(dtTime);

            // システム時計の日時設定
            return dtTime;
        }
Esempio n. 40
0
 private void _sendMsg(object param)
 {
     byte[] message = (param as byte[]);
     using (System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient())
     {
         client.Connect(IP, Port);
         client.Send(message, message.Length);
         if (Delay != 0)
             Thread.Sleep(Delay);
     }
 }
Esempio n. 41
0
        public void WriteLog(string sMsg)
        {
            m_mutex.WaitOne();
            if (bDebugMode)
            {
                string FILENAME = @"c:\" + sApplicationName + ".log";
                System.IO.StreamWriter fsw;
                string sOut;

                if (m_sContext != string.Empty)
                {
                    sOut = "[" + System.DateTime.Now.ToString("G") + "] " + "(" + m_sContext + ") " + sMsg;
                }
                else
                {
                    sOut = "[" + System.DateTime.Now.ToString("G") + "] " + sMsg;
                }

                if (System.IO.File.Exists(FILENAME))
                {
                    fsw = System.IO.File.AppendText(FILENAME);
                }
                else
                {
                    fsw = System.IO.File.CreateText(FILENAME);
                }
                fsw.WriteLine(sOut);
                fsw.Close();

                System.Net.IPEndPoint ipep = new System.Net.IPEndPoint(System.Net.IPAddress.Loopback,61288);
                System.Net.Sockets.UdpClient uc = new System.Net.Sockets.UdpClient(System.Net.Sockets.AddressFamily.InterNetwork);
                uc.Send(System.Text.Encoding.ASCII.GetBytes(sOut),sOut.Length,ipep);
                System.Diagnostics.Trace.WriteLineIf(bTrace,sMsg);
                System.Console.WriteLine(sMsg);
            }
            m_mutex.ReleaseMutex();
        }
Esempio n. 42
0
        private void ClassInit(string sApplicationName, bool bTrace)
        {
            this.sApplicationName = sApplicationName;
            this.bTrace = bTrace;
            Microsoft.Win32.RegistryKey rk = CarverLabRegistryKey();

            bDebugMode = false;
            if (rk != null && (string)rk.GetValue("DebugMode","0") == "1")
            {
                bDebugMode = true;
                string sOut = "=== " + sApplicationName + " ===";
                System.Net.IPEndPoint ipep = new System.Net.IPEndPoint(System.Net.IPAddress.Loopback,61288);
                System.Net.Sockets.UdpClient uc = new System.Net.Sockets.UdpClient(System.Net.Sockets.AddressFamily.InterNetwork);
                uc.Send(System.Text.Encoding.ASCII.GetBytes(sOut),sOut.Length,ipep);
            }
            else
            {
                bDebugMode = false;
            }

            m_sContext = string.Empty;
            m_mutex = new System.Threading.Mutex(false);
        }
Esempio n. 43
0
        /// <summary>
        /// UDP実行
        /// </summary>
        /// <param name="command">コマンド</param>
        /// <param name="no">カメラ番号</param>
        protected void runUdp(string command,string no)
        {
            //データを送信するリモートホストとポート番号
            string remoteHost = _json.remoteHost;
            int remotePort = (int)_json.remotePort;

            //UdpClientオブジェクトを作成する
            System.Net.Sockets.UdpClient udp = new System.Net.Sockets.UdpClient();

            //送信するデータを作成する
            string msg = "";
            msg = "command : " + command + "\r\n";
            msg += "camera_no : " + no + "\r\n";
            msg += "authenticate_code : \r\n";
            msg += "\r\n";
            byte[] sendBytes = Encoding.UTF8.GetBytes(msg);

            //リモートホストを指定してデータを送信する
            udp.Send(sendBytes, sendBytes.Length, remoteHost, remotePort);

            //UdpClientを閉じる
            udp.Close();
        }
Esempio n. 44
0
 /// <summary>
 /// Broadcast MagicPacket to Local Domain.
 /// </summary>
 /// <param name="macAddress">Length must be 6.</param>
 public static void BroadcastMagicPacket(params byte[] macAddress)
 {
     byte[] packet = MakeMagicPacket(macAddress);
     using (var socket = new System.Net.Sockets.UdpClient(0))
         socket.Send(packet, 102, new System.Net.IPEndPoint(0xFFFFFFFF, 7));
 }