Example #1
0
        public void On(RefreshPrices _)
        {
            System.Send(new PriceChanged(
                            destinationId: Addresses.TraderAddress,
                            newPrice: (decimal)(_pricesRandomizer.NextDouble() * 100),
                            priceId: Guid.NewGuid()));

            GenerateNewPrices();
        }
Example #2
0
 /// <summary>
 /// 发送EMAIL
 /// </summary>
 /// <param name="message">MailMessage</param>
 /// <param name="smtp">SmtpClient</param>
 /// <returns>true/false</returns>
 public bool Send(MailMessage message, System.Net.Mail.SmtpClient smtp) {
     try {
         smtp.Send(message);
         return true;
     } catch(Exception ex) {
         errorMessage = ex.ToExceptionDetail();
         return false;
     } finally {
         message = null;
         smtp = null;
     }
 }
Example #3
0
        public int SendMessage(System.Net.Sockets.Socket sender)
        {
            Enum MessageType = Message.MessageType.Message; // the type of message where sending here is a text message.
            Message msg = new Message();

            string sdfsa = GetMessageFromStream();

            byte[] message = Encoding.ASCII.GetBytes(sdfsa + "<EOF>");
            int sent = sender.Send(message);

            return sent;
        }
Example #4
0
        public void On(GenerateNextMessage _)
        {
            if (_messagesAlreadySent >= MessagesToBeSent)
            {
                return;
            }

            System.Send(new SendContent("testMessage", Addresses.TcpWritersDispatcher));
            _messagesAlreadySent++;

            System.Scheduler.Schedule(new GenerateNextMessage(Id), TimeSpan.FromMilliseconds(25));
        }
Example #5
0
        public void On(ClientConnected connected)
        {
            var tcpClient = connected.Client;
            var tcpStream = tcpClient.GetStream();

            var status = Process(tcpStream, tcpClient);

            if (status == ProcessingStatus.ClientDisconected)
            {
                return;
            }

            System.Send(new ChunkReaded(Addresses.ConnectionWorkers, tcpStream, connected.Client));
        }
Example #6
0
        public void On(RemoveFrom30 remove)
        {
            if (!_alive)
            {
                return;
            }

            _30SecWindow.Remove(remove.PriceId);

            if (_30SecWindow.Values.All(x => x.NewPrice < _price * 0.95m))
            {
                _alive = false;
                System.Send(new Sell(Addresses.OrderProcessorAddress, Id.Value, _latestPrice));
            }
        }
        public void On(StartListening e)
        {
            _tcpListener = new TcpListener(IPAddress.Any, 3000);
            _tcpListener.Start();

            _running = true;
            while (_running)
            {
                try
                {
                    var client = _tcpListener.AcceptTcpClient();
                    System.Send(new ClientConnected(Addresses.ConnectionWorkers, client));
                }
                catch (Exception)
                {
                    _running = false;
                }
            }
        }
Example #8
0
        public int SendIP(System.Net.Sockets.Socket sender)
        {
            Message msg = new Message();

            string HostIpAddress =
                Net.GetHostIpAddress();

            // the type of message where sending here is a Ip address.
            string type =
                "type:" + msg.GetMessageTypeByName(Message.MessageType.SentIP);

            byte[] message = Encoding.ASCII.GetBytes(HostIpAddress +
                                                " connected. " +
                                                 type +
                                                  Chat.EOF_FLAG);

            int sent = sender.Send(message);

            return sent;
        }
Example #9
0
        public void On(ChunkReaded chunk)
        {
            var status = Process(chunk.Stream, chunk.Client);

            if (status == ProcessingStatus.ClientDisconected)
            {
                return;
            }

            if (status == ProcessingStatus.MessageReaded)
            {
                System.Send(new ChunkReaded(Addresses.ConnectionWorkers, chunk.Stream, chunk.Client));
            }

            if (status == ProcessingStatus.ClientIsNotSending)
            {
                System.Scheduler.Schedule(
                    new ChunkReaded(Addresses.ConnectionWorkers, chunk.Stream, chunk.Client),
                    TimeSpan.FromMilliseconds(100));
            }
        }
Example #10
0
        public void On(SendContent message)
        {
            bool failed = false;

            try
            {
                var encoder = new ASCIIEncoding();
                var buffer  = encoder.GetBytes(message.Content);

                _clientStream.Write(buffer, 0, buffer.Length);
                _clientStream.Flush();
            }
            catch (Exception)
            {
                failed = true;
            }
            finally
            {
                System.Send(new SendContent(message, Addresses.DiskWriter, failed));
            }
        }
 void InitiateSession(System.Net.Sockets.Socket sd, string @base)
 {
     string Command = "NSPlayer/9.0.0.2980; {" + Guid.NewGuid().ToString() + "}; Host: " + @base;
     byte[] P1B1 = { 0xf0, 0xf0, 0xf0, 0xf0, 0xb, 0x0, 0x4, 0x0, 0x1c, 0x0, 0x3, 0x0 };
     byte[] P1B2 = Pad0(System.Text.Encoding.ASCII.GetBytes(Command), 6);
     sd.Send(HPacket(0x1, P1B1, P1B2));
 }
Example #12
0
        /// <summary>
        /// 向一个Socket发送集合中的所有文件
        /// </summary>
        /// <param name="client">已连接的Socket</param>
        public void Send(System.Net.Sockets.Socket client)
        {
            lock (this)
            {
                IEnumerator ie = this.GetEnumerator();
                while (ie.MoveNext())
                {
                    FileInfo fi = ((DictionaryEntry)ie.Current).Value as FileInfo;
                    int id = (int)((DictionaryEntry)ie.Current).Key;

                    lock (this)//防止多线程同时打开文件
                    {
                        System.IO.FileStream fs = new System.IO.FileStream(Config.WorkPath + fi.ToString(), System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        try
                        {
                            int i = 0;
                            if (FileResume != null && FileResume.ID == id)
                            {
                                i = FileOffSet;//续传文件从续传位置开始
                            }
                            for (; i < fs.Length; i += Config.FILE_BLOCK_LENGTH)
                            {
                                MessageBuffer mb = new MessageBuffer(MessageType.SendFile, id, i, Config.FILE_BLOCK_LENGTH);
                                mb.ReadFileBytes(fs);
                                client.Send(mb.GetBytes());
                            }
                        }
                        finally
                        {
                            fs.Close();//确保关闭文件流
                        }
                    }
                }
            }
        }
        public static void SendEmail(string from, List<string> to, List<string> cc, List<string> bcc, string subject, string body, bool isBodyHtml, List<System.Net.Mail.Attachment> attachments, System.Net.Mail.SmtpClient smtp)
        {
            MailMessage EmailMsg = new MailMessage();
            EmailMsg.From = new MailAddress(from);
            foreach (string s in to)
            {
                EmailMsg.To.Add(new MailAddress(s));
            }
            foreach (string c in cc)
            {
                EmailMsg.CC.Add(new MailAddress(c));
            }
            foreach (string c in bcc)
            {
                EmailMsg.Bcc.Add(new MailAddress(c));
            }
            EmailMsg.Subject = subject;
            EmailMsg.Body = body;
            EmailMsg.IsBodyHtml = isBodyHtml;

            foreach (System.Net.Mail.Attachment att in attachments)
            {
                EmailMsg.Attachments.Add(att);
            }
            EmailMsg.Priority = MailPriority.Normal;

            smtp.Send(EmailMsg);
        }
 public static void SendEmail(string from, string to, string subject, string body, System.Net.Mail.SmtpClient smtp)
 {
     //SmtpClient smtp = new SmtpClient(mailserver);
     MailMessage mm;
     mm = new MailMessage(from, to);
     //if (!string.IsNullOrEmpty(email.CC)) { mm.CC.Add(email.CC); }
     //if (!string.IsNullOrEmpty(email.BCC)) { mm.Bcc.Add(email.BCC); }
     mm.Subject = subject;
     mm.Body = body;
     smtp.Send(mm);
 }
        public static void SendEmail(string from, List<string> to, string subject, string body, System.Net.Mail.SmtpClient smtp)
        {
            MailMessage EmailMsg = new MailMessage();
            EmailMsg.From = new MailAddress(from);
            foreach (string s in to)
            {
                EmailMsg.To.Add(new MailAddress(s));
            }
            EmailMsg.Subject = subject;
            EmailMsg.Body = body;
            EmailMsg.IsBodyHtml = true;
            EmailMsg.Priority = MailPriority.Normal;

            smtp.Send(EmailMsg);
        }
 void TTTest(System.Net.Sockets.Socket sd)
 {
     byte[] HB = { 0x1, 0x0, 0x0, 0x0, 0xff, 0xff, 0x1, 0x0 };
     sd.Send(HPacket(0x1b, HB, null));
 }
 void WriteStream(System.Net.Sockets.Socket sd, string path, decimal time, int hsize)
 {
     int p = 0;
     int np = 0;
     long rp = 0;
     FileStream fs = null;
     bool fe = File.Exists(path);
     fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
     byte[] P5B1 = { 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0xac, 0x40, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
     byte[] rb = null;
     if (fe == true)
     {
         rb = new byte[fs.Length];
         fs.Read(rb, 0, rb.Length);
         p = GetPacketLength(rb);
         np = GetNumberOfPackets(rb);
         rp = (fs.Length - hsize) / p;
         decimal rtime = default(decimal);
         rtime = ((rp) / np) * time;
         byte[] br = HexDoublePercision(rtime);
         Array.ConstrainedCopy(br, 0, P5B1, 8, 8);
     }
     Log.Debug("MMSDownloader : Requesting Media Header...");
     sd.Send(HPacket(0x15, P5B1, null));
     int n = 0;
     int n1 = 0;
     byte[] bs = new byte[8];
     int i = 0;
     int cur = 0;
     int sp = 0;
     byte[] b = ReturnB(sd);
     if (fe == true)
         fs.Position = 0;
     if (b[36] == 0x11)
     {
     more:
         n1 = 0;
         while (!(n1 == 8))
         {
             n = sd.Receive(bs, n1, 8 - n1, 0);
             n1 = n1 + n;
         }
         Array.ConstrainedCopy(bs, 0, b, 0, n);
         i = bs[6] + bs[7] * (256) - 8;
         string s = HexString(bs, 0, 0);
         cur = cur + i;
         Log.Debug("MMSDownloader : Header Size: " + cur + "Bytes");
         byte[] header = new byte[i];
         n1 = 0;
         while (!(n1 == i))
         {
             n = sd.Receive(header, n1, i - n1, 0);
             n1 = n1 + n;
         }
         if (fe == true)
         {
             if (Find(header, rb) == -1)
                 Log.Debug("MMSDownloader : ERROR! Files Dont Match!");
             //: Exit Sub
         }
         if (p == 0)
             p = GetPacketLength(header);
         if (np == 0)
             np = GetNumberOfPackets(header);
         fs.Write(header, 0, header.Length);
         if (bs[5] == 0x4 | bs[5] == 0x8)
         {
             goto more;
         }
     }
     if (fe == true)
         fs.Position = fs.Length - 1;
     Log.Debug("MMSDownloader : Header Recieved And Written...Requesting Media...");
     byte[] P6B1 = { 0x1, 0x0, 0x0, 0x0, 0xff, 0xff, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
     sd.Send(HPacket(0x7, P6B1, null));
     byte[] b2 = ReturnB(sd);
     cur = 0;
     if (b2[36] == 0x21)
     {
         byte[] b3 = ReturnB(sd);
         if (b3[36] == 0x5)
         {
             n1 = 0;
             while (!(n1 == 8))
             {
                 n = sd.Receive(bs, n1, 8 - n1, 0);
                 n1 = n1 + n;
             }
             i = bs[6] + bs[7] * (256);
             i = i - 8;
             string s = null;
             s = HexString(bs, 8, 0);
             byte[] buffer = new byte[p];
             do
             {
                 n1 = 0;
                 while (!(n1 == i))
                 {
                     n = sd.Receive(buffer, n1, i - n1, 0);
                     n1 = n1 + n;
                 }
                 if (fe == true)
                 {
                     if (Find(buffer, rb) > -1)
                     {
                         sp = sp + 1;
                         Log.Debug("MMSDownloader : skipped: " + sp);
                         goto skip;
                     }
                     else
                     {
                         fe = false;
                     }
                 }
                 s = HexString(buffer, 0, 0);
                 if (s.Contains("1B 0 4 0") == true)
                     Log.Debug("MMSDownloader : !!!!");
                 fs.Write(buffer, 0, p);
                 cur = cur + p;
                 PercentDownloaded = (byte)((float)rp / np * 100f);
                 CurrentBytesDownloaded = cur;
                 Log.Debug("MMSDownloader : Recieving Packets. Packet Size Is " + p + "." + Environment.NewLine + "Recieved " + rp + " Packets Out Of " + np + "." + Environment.NewLine + "Downloaded So Far " + cur + "Bytes.");
             skip:
                 n1 = 0;
                 int b1 = 0;
                 while (!(n1 == 8))
                 {
                     n = sd.Receive(bs, n1, 8 - n1, 0);
                     if (n == 0)
                         b1 = b1 + 1;
                     if (b1 > 0)
                         Log.Debug("MMSDownloader : " + b1);
                     n1 = n1 + n;
                 }
                 string s1 = HexString(bs, 0, 0);
                 if (s1.Contains("CE FA B B0") == true)
                 {
                     do
                     {
                         int x = ReturnB2(sd);
                         if (x == 1)
                         {
                             Log.Debug("MMSDownloader : Download Is Complete!"); return;
                         }
                         if (x == 2)
                         {
                             Log.Debug("MMSDownloader : Sending Network Timing Test..");
                             TTTest(sd);
                             n1 = 0;
                             while (!(n1 == 8))
                             {
                                 n = sd.Receive(bs, n1, 8 - n1, 0);
                                 n1 = n1 + n;
                             }
                         }
                     } while (!(HexString(bs, 8, 0).Contains("CE FA B B0") == false));
                 }
                 i = bs[6] + bs[7] * (256) - 8;
                 rp = rp + 1;
             } while (true);
         }
     }
 }
 void RequestFile(System.Net.Sockets.Socket sd, string rest)
 {
     byte[] P4B1 = { 0x1, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
     byte[] P4B2 = Pad0(System.Text.Encoding.ASCII.GetBytes(rest), 0);
     sd.Send(HPacket(0x5, P4B1, P4B2));
 }
Example #19
0
        /// <summary>
        /// 向一个Socket发送集合中某个文件的一部分内容
        /// </summary>
        /// <param name="client">已连接的Socket</param>
        /// <param name="id">文件的标识号</param>
        /// <param name="offset">发送内容的起始位置</param>
        /// <param name="length">发送内容的长度</param>
        public void Send(System.Net.Sockets.Socket client, int id, int offset, int length)
        {
            if (this.ContainsKey(id))
            {
                FileInfo fi = this[id];
                lock (this)
                {
                    System.IO.FileStream fs = new System.IO.FileStream(Config.WorkPath + fi.ToString(), System.IO.FileMode.Open);

                    MessageBuffer mb = new MessageBuffer(MessageType.SendFile, id, offset, length);
                    mb.ReadFileBytes(fs);
                    client.Send(mb.GetBytes());
                    fs.Close();
                }
            }
            else
            {
                MessageBuffer mb = new MessageBuffer(MessageType.RequeryBlockError, id, offset, 0);
                client.Send(mb.GetBytes());
            }
        }
        //Sends requested MDA File
        private void SendMDAFileChange(System.Net.Sockets.UdpClient PlatformSendUDP, string hostname, int port)
        {
            MDACommand platformCommand = new MDACommand();

            platformCommand.MCW = BitConverter.ToUInt32(new byte[4] {MOOG_NEWMDAFILE, RequestedMDAFile, 0, 0 }, 0);

            byte[] sendBytes = flipStrBytes(platformCommand);

            try
            {
                PlatformSendUDP.Send(sendBytes, sendBytes.Length, hostname, port);
                //PlatformSendUDP.Send(sendBytes, sendBytes.Length);
            }
            catch (System.Exception ex)
            {
                //Cause failure of some sorts.
                //errorBar.BeginInvoke(new InvokeDelegateString(ErrorBarMessage), ex.Message);
                MessageBox.Show(ex.Message, "Send Command Error");
            }
        }
Example #21
0
 public void writeTo(System.Net.Sockets.Socket sock)
 {
     sock.Send(buf, _count, System.Net.Sockets.SocketFlags.None);
 }
Example #22
0
        /* ----------------------------------------------------------------------------------------------------------------------------------------------- */
        /**
         *  @brief    server loop which waits for data from robot and answers with XML File
         *
         *  @retval   none
         */
        /* ----------------------------------------------------------------------------------------------------------------------------------------------- */
        private void robotServerLoop(System.Net.Sockets.Socket comHandler)
        {
            // variable declarations
            byte[] localIncomingDataByteBuffer;                           // data buffer for incoming data
            byte[] localReceivedFullMessageBytes;
            byte[] sendMessage;
            int bytesReceived;
            String localCommandString;
            String localInfoString;

            // variable initializations

            localReceivedFullMessageBytes = null;
            sendMessage = new Byte[2048];

            // set state to running
            setRobotConnectionState(ConnectionState.running);

            // --------------------------------------------------
            // now lets start the endles loop
            // --------------------------------------------------
            while (true)
            {
                // reset and start the stopwatch to measure the time between two robot info cycles
                stopWatch_.Reset();
                stopWatch_.Start();

                // command the garbage collector to collect at the beginning of each cycle
                System.GC.Collect();

                // signal to the connected application that the command data is ready to be modified
                nextCycleStarted_ = true;

                // ------------------------------------------------------------
                // wait for data and receive bytes
                // ------------------------------------------------------------
                try
                {
                    while (patternFound_ == false)
                    {
                        String testString;

                        localIncomingDataByteBuffer = new Byte[2048];                 // load byte buffer with instance

                        bytesReceived = comHandler.Receive(localIncomingDataByteBuffer);
                        if (bytesReceived == 0)
                        {
                            makeLoggingEntry("client closed connection (bytesReceived=0)");
                            setRobotConnectionState(ConnectionState.closing);
                            break; // client closed socket
                        }

                        testString = System.Text.Encoding.ASCII.GetString(localIncomingDataByteBuffer, 0, bytesReceived);

                        // start stopwatch for receiving task
                        stopWatchReceive_.Reset();
                        stopWatchReceive_.Start();

                        // fill the received bytes into the local buffer and check if a full message came from robot
                        localReceivedFullMessageBytes = giveRightByteArray(localIncomingDataByteBuffer, bytesReceived);
                    }

                    // increment the packages counter
                    receivedPackagesCount_++;

                    // clear the pattern found flag
                    patternFound_ = false;
                }
                catch
                {
                    makeLoggingEntry("connection closed from remote host...\n\r");
                    setRobotConnectionState(ConnectionState.closing);
                    break;
                }

                stopWatchReceive_.Stop();

                stopWatchSend_.Reset();
                stopWatchSend_.Start();

                // -------------------------------------------------------------------------------------
                // signals the connector that the sending operation just started =>
                // the external system has to wait until this variable goes again to true
                // -------------------------------------------------------------------------------------
                nextCycleStarted_ = false;

                // --------------------------------------------------------------
                // only try to load the xml stuff when there is data available
                // --------------------------------------------------------------
                if (localReceivedFullMessageBytes != null)
                {
                    // -------------------------------------------------------------------------
                    // check if the string is valid and then save it to the locally xml storage
                    // -------------------------------------------------------------------------
                    if (checkReceivedMessage(localReceivedFullMessageBytes) == true)
                    {
                        try
                        {
                            // check if there is synchron AKorr active
                            doSynchronAKorr();

                            // check if there is synchron RKorr active
                            doSynchronRKorr();

                            // get the sendString variable under mutex protection from getter method
                            localCommandString = getCommandString();

                            // get the receiveString variable under mutex protection from getter method
                            localInfoString = getRobotInfoString();

                            // mirror the IPO counter you received yet
                            localCommandString = mirrorInterpolationCounter(localInfoString, localCommandString);

                            // get bytes out of string
                            sendMessage = System.Text.Encoding.ASCII.GetBytes(localCommandString);

                            // send data to robot
                            comHandler.Send(sendMessage, 0, sendMessage.Length, System.Net.Sockets.SocketFlags.None);

                            sendPackagesCount_++;

                            // copy the edited string under mutex protection back
                            setCommandString(localCommandString);
                        }
                        catch
                        {
                            makeLoggingEntry("could not send XML string");
                        }
                    }
                }

                stopWatchSend_.Stop();

                stopWatch_.Stop();
                communicationTimeMilliSeconds_ = stopWatch_.ElapsedMilliseconds;
                communicationTimeTicks_ = stopWatch_.ElapsedTicks;

                // ----------------------------------------------------------------------------------------------
                // count the delayed packages
                // ----------------------------------------------------------------------------------------------
                if (communicationTimeMilliSeconds_ > 16)
                {
                    delayedPackagesCount_++;
                    delayedPackagesMilliSecondsComm_ = communicationTimeMilliSeconds_;
                    delayedPackagesMilliSecondsSend_ = stopWatchSend_.ElapsedTicks;
                    delayedPackagesTicksComm_ = stopWatch_.ElapsedTicks;
                    delayedPackagesMilliSecondsReceive_ = stopWatchReceive_.ElapsedTicks;
                }

                // ----------------------------------------------------------------------------------------------
                // close communication channel to robot if state changed to closing
                // ----------------------------------------------------------------------------------------------
                if ((getRobotConnectionState() == ConnectionState.closeRequest) ||(getRobotConnectionState() == ConnectionState.closing) )
                {
                    setRobotConnectionState(ConnectionState.closing);
                    break;
                }
            }
        }
        //Sends most recent MDA command
        private void SendState(System.Net.Sockets.UdpClient PlatformSendUDP, string hostname, int port)
        {
            InputDataMutex.WaitOne();
            MDACommand LocalCurrentMDA = CurrentMDACommand;
            InputDataMutex.ReleaseMutex();

            byte[] sendBytes = flipStrBytes(LocalCurrentMDA);

            try
            {
                PlatformSendUDP.Send(sendBytes, sendBytes.Length, hostname, port);
            }
            catch (System.Exception ex)
            {
                //Cause failure of some sorts.
                errorBar.BeginInvoke(new InvokeDelegateString(ErrorBarMessage), ex.Message);
            }
        }
Example #24
0
        private static void SendDataClient(System.Net.Sockets.Socket workerSocket)
        {
            // Send back the reply to the client
                string replyMsg = "Server Reply:" + m_currentmessage;
                // Convert the reply to byte array
                byte[] byData = System.Text.Encoding.ASCII.GetBytes(replyMsg);

                workerSocket.Send(byData);
        }
        //Sends desired command
        private void SendCommand(byte command, System.Net.Sockets.UdpClient PlatformSendUDP, string hostname, int port)
        {
            MDACommand platformCommand = new MDACommand();

            platformCommand.MCW = (uint) command;

            byte[] sendBytes = flipStrBytes(platformCommand);

            try
            {
                PlatformSendUDP.Send(sendBytes, sendBytes.Length, hostname, port);
                //PlatformSendUDP.Send(sendBytes, sendBytes.Length);
            }
            catch (System.Exception ex)
            {
                //Cause failure of some sorts.
                //errorBar.BeginInvoke(new InvokeDelegateString(ErrorBarMessage), ex.Message);
                MessageBox.Show(ex.Message,"Send Command Error");
            }
        }
 void SendTimingTest(System.Net.Sockets.Socket sd)
 {
     byte[] P2B1 = { 0xf1, 0xf0, 0xf0, 0xf0, 0xb, 0x0, 0x4, 0x0 };
     sd.Send(HPacket(0x18, P2B1, null));
 }
        //Sends most recent MDA command
        private void SendState(System.Net.Sockets.UdpClient PlatformSendUDP, string hostname, int port, byte[] localBytes)
        {
            byte[] sendBytes = flipStrBytes(localBytes);

            try
            {
                sendDeltaTime += DateTime.Now.TimeOfDay.TotalSeconds - BitConverter.ToDouble(localBytes, Time_Offset);
                PlatformSendUDP.Send(sendBytes, sendBytes.Length, hostname, port);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message,"Send State Error");
            }
        }
 void RequestConnection(System.Net.Sockets.Socket sd)
 {
     string Command3 = "\\\\" + sd.LocalEndPoint.ToString().Replace(":", "\\TCP\\");
     Command3 = "\\\\" + StringHereToHere(Command3, "\\\\", "\\TCP\\") + "\\TCP\\1755";
     byte[] P3B1 = { 0xf1, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa0, 0x0, 0x2, 0x0, 0x0, 0x0 };
     byte[] P3B2 = Pad0(System.Text.Encoding.ASCII.GetBytes(Command3), 2);
     sd.Send(HPacket(0x2, P3B1, P3B2));
 }
Example #29
0
        /*
        *********************************************************************************************************
        *                                              SendData()
        *
        * Description : Cette fonction envoie des données sur le socket
        *
        * Argument(s) : s               Le socket de communication
        *               data            Buffer contenant le data à envoyer
        *
        * Return(s)   : int             Le nombre d'octets envoyés sur le socket
        *********************************************************************************************************
        */
        private static int SendData(System.Net.Sockets.Socket s, byte[] data)
        {
            int total = 0;
            int size = data.Length;
            int dataleft = size;
            int sent;

            while (total < size)
            {
                sent = s.Send(data, total, dataleft, SocketFlags.None);
                total += sent;
                dataleft -= sent;
            }
            return total;
        }
Example #30
0
 /// <summary>
 /// Sends a UDP datagram to the host at the specified remote endpoint.
 /// </summary>
 /// <param name="tempClient">Client to use as source for sending the datagram</param>
 /// <param name="packet">Packet containing the datagram data to send</param>
 public static void Send(System.Net.Sockets.UdpClient tempClient, PacketSupport packet)
 {
     tempClient.Send(packet.Data,packet.Length, packet.IPEndPoint);
 }