Originally Posted by
vart
Buffer too small error is very straight-forward - you allocated buffer is not big enough to store the resulting string
you should check that client[cNum].nicklen really represents the length of the client[cNum].Name
and counting your characters in the format - do you allocate space for nul-character?
as a side question - this is C++ - why you do not use std::stringstream object?
Hell, you should see the way I currently have it set up. its done all manually. I'll definately look into stringstream. Put it this way, I never took any coding classes, and i'm dependent on using namespace std. What does that tell ya? Thanks for the help! Btw, I already tried to make the buffer about 10 times larger than it should need to be and it did the same thing. I'll check this out and report back.
EDIT:
Well, I made my buffer:
RandomData= new char[2000]; and it still says the same thing... I don't see why, but either way i'm very new to stringstream and if someone could give me an easy out and give me an example of what stringstream functions i'd use to accomplish what i'm trying to do here?
The thing is i'm always dealing with dynamic buffers, its never just a constant stream. Some of the data is constant, but the name lengths and the commands that i'm sending/recieving with my server always change. Basically its an IRC client but for another purpose.
Basically, what i'm doing here is constructing the outgoing packet.
This is the code that i'm using that works but I know there has got to be a much better way. And it would be a good thing to notice that I create the dynamic buffer exactly the same here and it works fine when I sort through it manually.
Code:
//make buffer the size of the static data(22) plus the size of the user's nickname
RandomData= new char[22+client[cNum].nicklen];
RandomVar=0;
RandomData[RandomVar]=0x3a; //insert a ':'
RandomVar++;
//insert the user's nickname into the buffer
for(int x=0;x<(client[cNum].nicklen);x++)
{
RandomData[RandomVar]=client[cNum].Name[x];
RandomVar++;
}
//insert the static data
for(int x=0;x<21;x++)
{
RandomData[RandomVar]=partreply[x];
RandomVar++;
}
//send to everyone so they all know who left the lobby
for(int x=0;x<MAX_CONNECTIONS;x++)
{
if(client[x].s>0) // 's' is the client socket
send(client[x].s,RandomData,RandomVar,0);
}
And basically, this is what would get sent out to all the clients:
":lytar!u@h PART #Lob_18_0\r\n"
If anyone can help me out here, or let me know what I SHOULD be doing, i'd appreciate it. I have my own little crappy way of coding sometimes. But anyhow, i'd really appreciate a little direction here since this is probably one of the simpler packets I have to construct, I have some terribly confusing ones like:
Code:
//add the names
for(int y=0;y<(client[ConnectedList[xx]].nicklen);y++)
{
RandomData[RandomVar]=client[ConnectedList[xx]].Name[y];
RandomVar++;
}
After you access the same struct more than twice it starts to get mind boggling. And I may do this two or three times to create one packet. The reason I use a struct is to easily keep track of and access multiple client's data. I'm sure there is lots of optimization I can do, but hell. There has got to be an easier way. TIA.