bool CPeer::Send(char * Data, int len)
{
if (!tested)//check if tested
return false;
if (!conn)//ditto
return false;
send (s,(char *) &Data,len,0);
}
Pointers and send()
would this work?
If you were MEANT to understand it, we wouldn't have called it 'code'
It should compile, but based on the little bit of code you have here I''m going to guess it won''t do what you want (assuming you''re trying to do the obvious thing).
Why don''t you just:
send (s,Data,len,0);
??
Why don''t you just:
send (s,Data,len,0);
??
I want to send the data in data, not the memaddress, how would i do that?
BTW:CPeer will be in a linked list and I will need to send data between two CPeers... also I need to check that CPeer is tested and conn...
BTW:CPeer will be in a linked list and I will need to send data between two CPeers... also I need to check that CPeer is tested and conn...
If you were MEANT to understand it, we wouldn't have called it 'code'
I think gmcbay has the right idea. Also if the data is long you may need more than one send:
Note that this will block until all data is sent.
bool CPeer::Send(char * Data, int len){ if (!tested)//check if tested return false; if (!conn)//ditto return false; int sent = 0; while (sent < len) { int sentThisTime = send (s,Data+sent,len-sent,0); if (sentThisTime == SOCKET_ERROR) { //handle error return false;//? } sent += sentThisTime; }}
Note that this will block until all data is sent.
The quick answer to your question:
use Data in send, not &Data
send (s,Data,len,0);
not send (s,(char *) &Data,len,0);
eh?
use Data in send, not &Data
send (s,Data,len,0);
not send (s,(char *) &Data,len,0);
eh?
eh?
Another function breaks down the data into managable chuncks, onlt 128 bytes at a time, but im worried that char * Data when cast (char *) then refenenced &Data would send the mem addres on the clients computer, not the data its self
If you were MEANT to understand it, we wouldn't have called it 'code'
quote:
Original post by Baloogan
im worried that char * Data when cast (char *) then refenenced &Data would send the mem addres on the clients computer, not the data its self
Correct, that''s why all the replies here say not to do that
August 20, 2002 10:51 AM
Just as a note to zppz, send() will only return before all data is sent on a non-blocking socket (or if an error occurs). If you are going to use a tight loop to send all the data, you would be better off using blocking sockets, it will chew less cpu.
Thank you all for your posts, now CPeer works! Thank you...
If you were MEANT to understand it, we wouldn't have called it 'code'
With recv, I still pass "(char *) &data" into it would THAT work?
eg:
eg:
bool CPeer::Recv(char * Data, int len){ if (!tested)//ditto return false; if (!conn)//ditto return false; recv(s,(char*) &Data,len,0); return true;}
If you were MEANT to understand it, we wouldn't have called it 'code'
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement