|
You last visited: Today at 07:12
Advertisement
Socket Error
Discussion on Socket Error within the C/C++ forum part of the Coders Den category.
06/08/2013, 15:34
|
#1
|
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?
|
|
|
06/08/2013, 16:55
|
#2
|
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.
|
|
|
06/09/2013, 00:37
|
#3
|
elite*gold: 0
Join Date: Dec 2011
Posts: 367
Received Thanks: 199
|
Quote:
Originally Posted by Schlüsselbein
Wtf is this piece of **** supposed to do?
Do yourself a favour and use a network library like boost::asio.
|
boost lib is ****.. D:
|
|
|
06/09/2013, 00:46
|
#4
|
elite*gold: 273
Join Date: Sep 2010
Posts: 1,831
Received Thanks: 786
|
Quote:
Originally Posted by Kingrap
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.
|
|
|
06/09/2013, 00:55
|
#5
|
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
|
|
|
06/09/2013, 15:55
|
#6
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,908
Received Thanks: 25,409
|
Quote:
Originally Posted by ernilos
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
|
#7
|
elite*gold: 0
Join Date: Jan 2009
Posts: 1,160
Received Thanks: 232
|
Quote:
Originally Posted by Padmak
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
|
#8
|
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
|
|
|
06/11/2013, 10:58
|
#9
|
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.
|
|
|
06/11/2013, 11:16
|
#10
|
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
|
|
|
06/12/2013, 05:32
|
#11
|
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.
|
|
|
06/12/2013, 06:41
|
#12
|
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).
|
|
|
06/12/2013, 16:25
|
#13
|
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.
|
|
|
06/15/2013, 15:04
|
#14
|
elite*gold: 0
Join Date: Dec 2012
Posts: 20
Received Thanks: 0
|
Quote:
Originally Posted by ernilos
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
|
#15
|
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
|
Quote:
Originally Posted by artfulwave
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) ><
|
|
|
 |
|
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.
|
|