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

C#

 
GeneralRe: How Do I Pin
Cianide8-May-15 3:14
Cianide8-May-15 3:14 
AnswerRe: How Do I PinPopular
Pete O'Hanlon8-May-15 2:24
mvePete O'Hanlon8-May-15 2:24 
GeneralRe: How Do I Pin
Cianide8-May-15 2:35
Cianide8-May-15 2:35 
GeneralRe: How Do I Pin
Pete O'Hanlon8-May-15 2:37
mvePete O'Hanlon8-May-15 2:37 
GeneralRe: How Do I Pin
Cianide8-May-15 3:16
Cianide8-May-15 3:16 
GeneralRe: How Do I Pin
Mycroft Holmes8-May-15 13:52
professionalMycroft Holmes8-May-15 13:52 
GeneralRe: How Do I Pin
ZurdoDev8-May-15 3:16
professionalZurdoDev8-May-15 3:16 
Questionreceived data by UDP client Pin
hasan hadi7-May-15 21:43
hasan hadi7-May-15 21:43 
Hi,
I writing code for send and received data by use UDP client the send data is ok but problem in received data
1- I send this data "S11E"to program and in program display received data in label i see only "S" display in label why not display "S11E"

2- I put received code inside code button this mean cannot received any data until press the button .
can be Mark program that reads data automatically

used this code for recived data
C#
byte[] reciveddata= udpClient.Receive(ref ipend);
                string returnData = Encoding.ASCII.GetString(reciveddata);
 
                label3.Text = ""+returnData;

in reciveddata only one byte but I send string data .
where is problem?

my code

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;


namespace etherent_send_and_recive_data
{
    public partial class Form1 : Form
    {
        UdpClient udpClient;
        IPEndPoint ipend;
        public Form1()
        {

            InitializeComponent();
            udpClient = new UdpClient();
           
        }

        private void send_data_through_etherent( string send_data_ETH)
        {
           
            byte[] senddataETH = ASCIIEncoding.ASCII.GetBytes(send_data_ETH);

            udpClient.Send(senddataETH,4);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int port;
           button1.Text = "disconnected";
            port = int.Parse(textBox2.Text);
            ipend = new IPEndPoint(IPAddress.Parse(textBox1.Text), port);
                       

            try
            {
               
                udpClient.Connect(ipend);
                button1.Text = "Connected";
                
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.ToString());
            }
              
            
        }

       

        private void switch1_StateChanged(object sender, NationalInstruments.UI.ActionEventArgs e)
        {
            if (switch1.Value == true) send_data_through_etherent("S11E");
            else send_data_through_etherent("S10E");
            
            try
            {

               byte[] reciveddata= udpClient.Receive(ref ipend);
                string returnData = Encoding.ASCII.GetString(reciveddata);

                label3.Text = ""+returnData;
                
            }
            catch (Exception e1)
            {
                MessageBox.Show("ERROR");

            }

        }

    
    }

}


modified 8-May-15 3:51am.

AnswerRe: received data by UDP client Pin
F-ES Sitecore9-May-15 2:25
professionalF-ES Sitecore9-May-15 2:25 
GeneralRe: received data by UDP client Pin
hasan hadi9-May-15 3:38
hasan hadi9-May-15 3:38 
GeneralRe: received data by UDP client Pin
F-ES Sitecore9-May-15 7:05
professionalF-ES Sitecore9-May-15 7:05 
GeneralRe: received data by UDP client Pin
hasan hadi9-May-15 7:42
hasan hadi9-May-15 7:42 
GeneralRe: received data by UDP client Pin
F-ES Sitecore9-May-15 7:48
professionalF-ES Sitecore9-May-15 7:48 
GeneralRe: received data by UDP client Pin
hasan hadi9-May-15 8:07
hasan hadi9-May-15 8:07 
AnswerRe: received data by UDP client Pin
Dr Gadgit10-May-15 5:03
Dr Gadgit10-May-15 5:03 
Question(solved) shorter syntax for invoking static methods in generic non-static class ? Pin
BillWoodruff7-May-15 20:41
professionalBillWoodruff7-May-15 20:41 
AnswerRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Sascha Lefèvre7-May-15 22:31
professionalSascha Lefèvre7-May-15 22:31 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
BillWoodruff7-May-15 22:46
professionalBillWoodruff7-May-15 22:46 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Sascha Lefèvre7-May-15 23:53
professionalSascha Lefèvre7-May-15 23:53 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
BillWoodruff8-May-15 0:40
professionalBillWoodruff8-May-15 0:40 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Sascha Lefèvre8-May-15 5:27
professionalSascha Lefèvre8-May-15 5:27 
SuggestionRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Richard Deeming8-May-15 0:42
mveRichard Deeming8-May-15 0:42 
Questionhow do I get datasource to put to any drive c# Pin
Member 97020587-May-15 14:19
Member 97020587-May-15 14:19 
AnswerRe: how do I get datasource to put to any drive c# Pin
Dave Kreskowiak7-May-15 16:50
mveDave Kreskowiak7-May-15 16:50 
AnswerRe: how do I get datasource to put to any drive c# Pin
OriginalGriff7-May-15 20:35
mveOriginalGriff7-May-15 20:35 

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.