Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Socket Assistance

Status
Not open for further replies.

ChewDoggie

Programmer
Mar 14, 2005
604
US
G'morning !

Is there a way to Send Data via a socket control that's in a traditional string format, rather than a byte format ? OR maybe there's a different (3rd party) socket control out there that sends data like the old VB6 Socket control did ?

I have a machine on the other end that is expecting an ASCII string (not a byte-array) and I don't have any access to it.

THanks !

Chew

10% of your life is what happens to you. 90% of your life is how you deal with it.
 
You can use HTTP post to send data as string. This would have to go a URL though?. VB would have probably sent as bytes but converted it to a string before it was given to the program.

If you was to use a third party control then the user would have to install this. There are Open Source controls on codeplex that will do this. To be honest though it is not that difficult to write your own.

Age is a consequence of experience
 
This isn't it exactly, but may work... this is pasted from a special class that we're using but could point in the right direction.

<code>
/// <summary>
/// Converts string to byte array
/// </summary>
/// <param name="ValueToByte">String to convert</param>
/// <returns>byte array of original string</returns>
public static byte[] GenerateByteFromString(String ValueToByte)
{
return Encoding.Unicode.GetBytes(ValueToByte);
}

/// <summary>
/// Converts byte array to string
/// </summary>
/// <param name="ValueToString">Byte array to convert</param>
/// <returns>string of original byte array</returns>
public static String GenerateStringFromByte(Byte[] ValueToString)
{
return Encoding.Unicode.GetString(ValueToString);
}
</code>
 
Thanks, Neswalt !

I investigated something similar after posting this question and the Send method of the Winsock control barfed when it encountered a string, rather than a byte-array.

I was hoping that there was a 3rd party version out there that fit the bill.

Thanks again !

Chew

10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top