LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send string from c# to LabView over socket?

The LabView application that I have creates a server coacket and accepts only "string" data. My C# application creates a client socket and tries to send "byte" data over socket. How can I make this work? C# socket function does not allow me to send "string" data. It forces me to convert the data to byte array.

0 Kudos
Message 1 of 4
(4,693 Views)

vsanghvi,

 

Im a bit confused with exactly what were doing here. I understand were trying to pass data from a LV application to some C# code, but are we using data sockets? Also, are you using measurement studio for your C# code, and if so what version? 

 

Can you give us a snippet of code from the client and server side to help show us what youre doing?

 

Regards,

 

Kyle Mozdzyn

Applications Engineering

National Instruments

 

 

Regards,

Kyle M.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 4
(4,676 Views)

Hi,

 

Sorry for the confusion.

 

LV is creating the server data socket and I'm trying to create client from C# (not using measurement studio). The byte array that I was sending from C# was not being read by LV. I found the issue was with the way I was encoding the string in C#.

 

C# code:

string strCommand;

byte[] byData = System.Text.Encoding.UTF8.GetBytes(strCommand);

int nBytes = clientSock.Send(byData);

 

Instead of UTF8 I was trying ASCII and UNICODE, which was not doing the right string to byte conversion. Everything is working fine now.

 

Thanks

Vane

0 Kudos
Message 3 of 4
(4,667 Views)

Vane,

 

Its good to hear you were able to get it up and running!

 

Regards,

 

Kyle Mozdzyn

Applications Engineering

National Instruments

Regards,

Kyle M.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 4
(4,659 Views)