Socket Error

06/08/2013 15:34 ernilos#1
Hi guys! I'm making my own Socket class(my private server development...) but i have one error on this:
char *HSocket::Recv()
{
char tmp[256*256];
int tmplen = 256*256;
int resize;
do{
resize = ::recv(this->socket,(char*)tmp,tmplen,0);
char *resized = new char[resize];
sprintf(resized,"%s",tmp);
delete [] tmp;
return resized;
}while(resize > 0);
};
But i didn't get all buffer, normaly i only get the first 20 or 15 char's... Why?
06/08/2013 16:55 Schlüsselbein#2
Wtf is this piece of shit supposed to do?
Do yourself a favour and use a network library like boost::asio.
06/09/2013 00:37 Kingrap#3
Quote:
Originally Posted by Schlüsselbein View Post
Wtf is this piece of shit supposed to do?
Do yourself a favour and use a network library like boost::asio.
boost lib is shit.. D:
06/09/2013 00:46 .SkyneT.#4
Quote:
Originally Posted by Kingrap View Post
boost lib is shit.. D:
Imo you should get banned from this section for this post.

I bet boost is much better than every piece of
code you wrote, or will write.
06/09/2013 00:55 Padmak#5
Ever tried to implement a good working network lib with boost::asio?
Pain in the A**

Padmak
06/09/2013 15:55 MrSm!th#6
Quote:
Originally Posted by ernilos View Post
Hi guys! I'm making my own Socket class(my private server development...) but i have one error on this:
char *HSocket::Recv()
{
char tmp[256*256];
int tmplen = 256*256;
int resize;
do{
resize = ::recv(this->socket,(char*)tmp,tmplen,0);
char *resized = new char[resize];
sprintf(resized,"%s",tmp);
delete [] tmp;
return resized;
}while(resize > 0);
};
But i didn't get all buffer, normaly i only get the first 20 or 15 char's... Why?
You cannot delete[] a local array, it is used for dynamically allocated buffers.
06/11/2013 04:07 Delinquenz#7
Quote:
Originally Posted by Padmak View Post
Ever tried to implement a good working network lib with boost::asio?
Pain in the A**

Padmak
Word! I'm still hoping that <network> which got announced for C++14 won't be such a pain.
06/11/2013 10:29 Padmak#8
Well... isn't asio this <network> lib? Everything i can find about C++14 looks a lot like asio

Padmak
06/11/2013 10:58 Schlüsselbein#9
I think boost::asio does a very good job at being a low level(!) modern written async network lib.
Its simply that asynchronous programming per se is a difficult and complex task.

Theres only one point about asio that bothers me: the lack of a good official tutorial. The documentation is very sporadic. Imho the examples are the best resource for learning boost::asio.
06/11/2013 11:16 Padmak#10
I hope it'll be better documented as soon as it's officially standardized. But until then, i'll go with hating it for its complexity :D

Padmak
06/12/2013 05:32 Delinquenz#11
There was a nice [Only registered and activated users can see links. Click Here To Register...] for the new <network> library which suggested an tcp stream where you can shift in and out with << and >>. That would be nice.
06/12/2013 06:41 Schlüsselbein#12
Quote:
which suggested an tcp stream where you can shift in and out with << and >>. That would be nice.
I dont think thats even worth mentioning cause thats what every cpp-programmer should expect. Its a network _stream_ and therefore should support operator<</>>.

Imho cpp-netlib has a good attempt: [Only registered and activated users can see links. Click Here To Register...] (idk if its still maintained).
06/12/2013 16:25 Delinquenz#13
Quote:
Imho cpp-netlib has a good attempt:
Last update was 1 year ago and it's as far as i see it just supports HTTP.
06/15/2013 15:04 artfulwave#14
Quote:
Originally Posted by ernilos View Post
But i didn't get all buffer, normally i only get the first 20 or 15 char's... Why?
Show me your send function.send() might not send all the bytes as the kernel decided not to send all the data out in one pack.
maybe you can do it this way.

Quote:
int SendData(SOCKET socket, char *buffer, int *length)
{
int Total = 0;
int BytesLeft = *len;
int n;

while(Total < *length) {

n = send(s, buffer+Total, BytesLeft, 0);
if (n == -1) { break; }
Total += n;
BytesLeft -= n;
}

*length = Total;

return n == -1? -1 : 0;
}
And you can call the function like that.

Quote:
char buf[20] = "Send all data to ...";

int buflen = strlen(buf);

if((SendData(socket,buffer, &buflen) == -1)
{

//Failed to send all the data
cout << "Some data had n`t been sent:" << buflen << endl;

}
Take note :i am not sure if that is the matter i am just guessing.
06/15/2013 20:23 ernilos#15
Quote:
Originally Posted by artfulwave View Post
Show me your send function.send() might not send all the bytes as the kernel decided not to send all the data out in one pack.
maybe you can do it this way.



And you can call the function like that.



Take note :i am not sure if that is the matter i am just guessing.
The client works perfectly, isn't coded by me(I'm developing p.server) ><