Originally Posted by
ac251404
update - Ok great I can see all the info I need being sent back and forth... new problem. the send() function works with const *char but sending character arrays obviously does not work. Do I need to send in a different manner so that the server recieves binary or does send handle this on its own?
send() sends raw data - it doesn't care about characters, etc. It's declared as*:
Code:
int send(int s, const void *msg, size_t len, int flags);
, passing a char array like you're doing is perfectly acceptable.
The one thing that bites most people in the butt is that send() might not send everything you ask it to send. It's imperative that the return value is checked: On success, send() will tell you how much it really sent. For simple blocking socket applications, you can easily write a function that ensures everything is sent:
Code:
int sendall(int s, void *msg, int len)
{
int transferred = 0, send_ret;
unsigned char *umsg = msg;
while(transferred < len)
{
send_ret = send(s, umsg + transferred, len - transferred, 0);
if(send_ret <= 0) return send_ret;
transferred += send_ret;
}
return len;
}
For raw binary, I usually use unsigned char - 1 byte & unsigned (or whatever type is). So:
Code:
unsigned raw_data[3] = {0xFF, 0xFB, 0x18};
sendall(your_socket, raw_data, 3);
Should hopefully work. There's more than one way to accomplish this however.
EDIT:
A better way to work that might even be {IAC, WILL, 0x18};
where IAC & WILL are either:
#define IAC 0xFF
const unsigned char IAC 0xFF;