Click here to Skip to main content
15,890,438 members
Home / Discussions / C#
   

C#

 
QuestionHow know the state connected for udp client Pin
hasan hadi6-May-15 17:13
hasan hadi6-May-15 17:13 
AnswerRe: How know the state connected for udp client Pin
Dave Kreskowiak6-May-15 17:23
mveDave Kreskowiak6-May-15 17:23 
GeneralRe: How know the state connected for udp client Pin
hasan hadi6-May-15 23:29
hasan hadi6-May-15 23:29 
GeneralRe: How know the state connected for udp client Pin
Dave Kreskowiak7-May-15 1:24
mveDave Kreskowiak7-May-15 1:24 
GeneralRe: How know the state connected for udp client Pin
hasan hadi7-May-15 3:17
hasan hadi7-May-15 3:17 
AnswerRe: How know the state connected for udp client Pin
F-ES Sitecore6-May-15 23:28
professionalF-ES Sitecore6-May-15 23:28 
GeneralRe: How know the state connected for udp client Pin
hasan hadi6-May-15 23:35
hasan hadi6-May-15 23:35 
AnswerRe: How know the state connected for udp client Pin
hasan hadi10-May-15 16:12
hasan hadi10-May-15 16:12 
Hi,
This code from my friend about how can check the connection
if connected or not also continuous check

C#
public bool TestConnection(string ip)
        {
            Ping p = new Ping();
            try
            {
                PingReply reply = p.Send(ip, 3000);
                if (reply.Status == IPStatus.Success)
                    return true;
            }
            catch (Exception e)
            {
                return false;
            }
            return false;


for example

C#
private void button2_Click(object sender, EventArgs e)
      {
          busy = true;
          if (TestConnection(textBox2.Text))
          {
              Byte[] sendBytes = Encoding.ASCII.GetBytes("B");

              udpClient.Send(sendBytes, sendBytes.Length);
              var receivedData = udpClient.Receive(ref ep);
              textBox1.Text = Encoding.ASCII.GetString(receivedData);
              label1.Text = Encoding.ASCII.GetString(receivedData);
          }
          busy = false;
      }

      private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
      {
          if (!busy)
          {
              Byte[] sendBytes = Encoding.ASCII.GetBytes("C");
              udpClient.Send(sendBytes, sendBytes.Length);
              var receivedData = udpClient.Receive(ref ep);
              textBox1.Text = Encoding.ASCII.GetString(receivedData);
          }
      }

      private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          Thread.Sleep(500);
          if (TestConnection(textBox2.Text))
          {
              backgroundWorker1.RunWorkerAsync();
          }
          else
          {
              MessageBox.Show("No Device Connected");
          }

      }

QuestionSQL Server Connection Best Practice Pin
JBHowl6-May-15 8:58
JBHowl6-May-15 8:58 
AnswerRe: SQL Server Connection Best Practice Pin
Richard Deeming6-May-15 9:28
mveRichard Deeming6-May-15 9:28 
AnswerRe: SQL Server Connection Best Practice Pin
Dave Kreskowiak6-May-15 11:11
mveDave Kreskowiak6-May-15 11:11 
AnswerRe: SQL Server Connection Best Practice Pin
F-ES Sitecore6-May-15 22:39
professionalF-ES Sitecore6-May-15 22:39 
QuestionCreating Large, Blank Bitmaps Pin
JBHowl6-May-15 3:39
JBHowl6-May-15 3:39 
AnswerRe: Creating Large, Blank Bitmaps Pin
Dave Kreskowiak6-May-15 4:15
mveDave Kreskowiak6-May-15 4:15 
GeneralRe: Creating Large, Blank Bitmaps Pin
JBHowl6-May-15 4:41
JBHowl6-May-15 4:41 
GeneralRe: Creating Large, Blank Bitmaps Pin
Eddy Vluggen6-May-15 5:14
professionalEddy Vluggen6-May-15 5:14 
GeneralRe: Creating Large, Blank Bitmaps Pin
Dave Kreskowiak6-May-15 11:07
mveDave Kreskowiak6-May-15 11:07 
AnswerRe: Creating Large, Blank Bitmaps Pin
Pete O'Hanlon6-May-15 5:00
mvePete O'Hanlon6-May-15 5:00 
GeneralRe: Creating Large, Blank Bitmaps Pin
JBHowl6-May-15 5:03
JBHowl6-May-15 5:03 
GeneralRe: Creating Large, Blank Bitmaps Pin
Pete O'Hanlon6-May-15 8:50
mvePete O'Hanlon6-May-15 8:50 
AnswerRe: Creating Large, Blank Bitmaps Pin
OriginalGriff6-May-15 6:14
mveOriginalGriff6-May-15 6:14 
GeneralRe: Creating Large, Blank Bitmaps Pin
JBHowl6-May-15 7:16
JBHowl6-May-15 7:16 
QuestionHow can I use webcam in WebBrowser Control? Pin
Member 116126625-May-15 17:45
Member 116126625-May-15 17:45 
AnswerRe: How can I use webcam in WebBrowser Control? Pin
Dr Gadgit6-May-15 2:14
Dr Gadgit6-May-15 2:14 
QuestionC# Get Audio File From Resources Pin
Kevin Marois5-May-15 9:03
professionalKevin Marois5-May-15 9:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.