Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 07:12

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Socket Error

Discussion on Socket Error within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
ernilos's Avatar
 
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
Socket Error

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?
ernilos is offline  
Old 06/08/2013, 16:55   #2
 
Schlüsselbein's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 1,137
Received Thanks: 869
Wtf is this piece of **** supposed to do?
Do yourself a favour and use a network library like boost::asio.
Schlüsselbein is offline  
Old 06/09/2013, 00:37   #3
 
elite*gold: 0
Join Date: Dec 2011
Posts: 367
Received Thanks: 199
Quote:
Originally Posted by Schlüsselbein View Post
Wtf is this piece of **** supposed to do?
Do yourself a favour and use a network library like boost::asio.
boost lib is ****.. D:
Kingrap is offline  
Old 06/09/2013, 00:46   #4
 
.SkyneT.'s Avatar
 
elite*gold: 273
Join Date: Sep 2010
Posts: 1,831
Received Thanks: 786
Quote:
Originally Posted by Kingrap View Post
boost lib is ****.. 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.
.SkyneT. is offline  
Old 06/09/2013, 00:55   #5
 
Padmak's Avatar
 
elite*gold: 58
Join Date: Jun 2008
Posts: 2,311
Received Thanks: 8,420
Ever tried to implement a good working network lib with boost::asio?
Pain in the A**

Padmak
Padmak is offline  
Thanks
1 User
Old 06/09/2013, 15:55   #6


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,908
Received Thanks: 25,409
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.
MrSm!th is offline  
Old 06/11/2013, 04:07   #7

 
Delinquenz's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,160
Received Thanks: 232
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.
Delinquenz is offline  
Old 06/11/2013, 10:29   #8
 
Padmak's Avatar
 
elite*gold: 58
Join Date: Jun 2008
Posts: 2,311
Received Thanks: 8,420
Well... isn't asio this <network> lib? Everything i can find about C++14 looks a lot like asio

Padmak
Padmak is offline  
Old 06/11/2013, 10:58   #9
 
Schlüsselbein's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 1,137
Received Thanks: 869
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.
Schlüsselbein is offline  
Old 06/11/2013, 11:16   #10
 
Padmak's Avatar
 
elite*gold: 58
Join Date: Jun 2008
Posts: 2,311
Received Thanks: 8,420
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

Padmak
Padmak is offline  
Old 06/12/2013, 05:32   #11

 
Delinquenz's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,160
Received Thanks: 232
There was a nice for the new <network> library which suggested an tcp stream where you can shift in and out with << and >>. That would be nice.
Delinquenz is offline  
Old 06/12/2013, 06:41   #12
 
Schlüsselbein's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 1,137
Received Thanks: 869
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: (idk if its still maintained).
Schlüsselbein is offline  
Old 06/12/2013, 16:25   #13

 
Delinquenz's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,160
Received Thanks: 232
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.
Delinquenz is offline  
Old 06/15/2013, 15:04   #14
 
artfulwave's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 20
Received Thanks: 0
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.
artfulwave is offline  
Old 06/15/2013, 20:23   #15
 
ernilos's Avatar
 
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
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) ><
ernilos is offline  
Reply


Similar Threads Similar Threads
Socket Error
12/23/2012 - S4 League - 2 Replies
Hey, i wanna a Solution for this Problem http://img823.imageshack.us/img823/7619/67715599. jpg
PBDO Bot Error !! A Socket connection error while connecting to the bot auth server.
12/08/2012 - DarkOrbit - 11 Replies
A Socket connection error while connecting to the bot auth server. Trying another one. ERROR PBDO
Port/Socket Error
01/11/2012 - CO2 Private Server - 4 Replies
Alright, pretty sure this is the right place to post this. I have decided to fool around with CO PServers as all I have ever coded and messed with is Java. I have touched a little bit into C# before but nothing major. But this is besides the point, actually I am fairly certain this has nothing to do with the coding of the server (oddly enough?). Basically I have the ports 9958/5816 forwarded, added exceptions in firewall (inbound and outbound) and even tried cutting off the firewall, yet...
socket error W[200] L[........
02/13/2011 - CrossFire - 4 Replies
habe folgendes problem bei crossfire (habe keine hacks bots... auf mein pc) habe windows7 32bit und wenn ich crossfire im abgesiicherten modus installire dann pc neu starte und starten will bleibt es bei der check box auf 66% stehen und es kommt die oben genannte fehler meldung wie kann ich das beheben ?
Socket Error?
07/29/2010 - S4 League - 8 Replies
Everything is alright everything loads up. Then this pops up! Why is this happening and how do I fix it? http://i285.photobucket.com/albums/ll54/animecraz ed598/S4leagueError2.jpg



All times are GMT +1. The time now is 07:14.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.