TCP/IP Question
-
Hi, I wrote a simple tcp/ip program in VC++....I have a question regarding sending data. I created a simple tcp/ip chat program where one copy of the same prog. is made a server and other copy of it is the client, and I'm able to send string messages back and forth. I wanted to know if instead of string messages I want to send data of type BYTE. I would like to send for ex. data type BYTE test [5] = 0x03 0x19 0x00 0x12 0xD5 //Send the message iSent = m_sConnectSocket.Send(LPCTSTR(m_strMessage),iLen); I thought I could repalce the m_strMessage with variable "test" of type BYTE, but no luck If you could help me out, I would greatly appericate it. Arun
-
Hi, I wrote a simple tcp/ip program in VC++....I have a question regarding sending data. I created a simple tcp/ip chat program where one copy of the same prog. is made a server and other copy of it is the client, and I'm able to send string messages back and forth. I wanted to know if instead of string messages I want to send data of type BYTE. I would like to send for ex. data type BYTE test [5] = 0x03 0x19 0x00 0x12 0xD5 //Send the message iSent = m_sConnectSocket.Send(LPCTSTR(m_strMessage),iLen); I thought I could repalce the m_strMessage with variable "test" of type BYTE, but no luck If you could help me out, I would greatly appericate it. Arun
Thats simple. :) Send expects a [long constant pointer to TCHAR] variable, so just putting somthing of type byte isn`t right. still, the second parameter of .Send is a length of data to be sent, thats it in TCHARs. So make it that way: Suppose you have a BYTE g_aBytes[1024]; filled with some interesting bytes and you want to send 651 of them. just make a call like that: iSent = m_sConnectSocket.Send((LPCTSTR) g_aBytes, 651); here you do s old-style C cast from array of bytes to LPCTSTR. Also you expicitly tell the socket how much data you`d like to send. That`ll do the trick, unless you dont use UNICODE. :) In general , from your post i see you`re not much expirienced in C++ programming. I recommend some serious reading - for example Bjane Stroustroup C++ programming language third edition. Be good, Sincerely yours, Ilya Kalujny.