kodex
2005.06.30, 02:37 PM
Ok guys this is the last thing i need to do before i can move back to my own programming. I have 2 Apps Client/Server. The client connects to the server fine. It will let me write net data fine no problems. The issue is the data is never received by the server.
I know this stuff can be a huge pain, so if anyone can help me fix this I will paypal you $30. I know im bribing now but im sick of trying to get it to work and im comming up quick on a deadline.
Here is the code that is being used. I will also post the whole source on my site (link at end) if anyone wants to look at it.
CLIENT
int WriteNetData(int socket, void *buffer, int numBytes)
{
Ptr bytes = buffer; //ptr to buffer
int count, n;
n = count =0;
while(count< numBytes) //loop until we have sent all bytes
{
n = send(socket, bytes, numBytes - count, 0); //send..... CRASHES HERE
if(n>0)
{
count += n;
bytes += n;
}
else
if(n<0) //error
return(-1);
}
return(count);
}
static Boolean IsSocketReadyForWrite(int socket)
{
struct fd_set connectionSet;
struct timeval timeout;
int result;
//set timeout values
timeout.tv_sec =0;
timeout.tv_usec =0;
FD_ZERO(&connectionSet);
FD_SET(socket, &connectionSet);
//call select to see if data is waiting on the socket
result = select(socket+1, nil, &connectionSet, nil, &timeout);
//check results
if (result < 0 )
return (false);
if (result>0)
{
if(FD_ISSET(socket, &connectionSet))
return(true);
else
return(false);
}
return(false);
}
SERVER
Boolean IsDataWaitingToBeRead(int socket)
{
struct fd_set connectionSet;
struct timeval timeout;
int result;
//Set timeout and set values
timeout.tv_sec = 0; //no timeout
timeout.tv_usec = 0;
FD_ZERO(&connectionSet); //use our macro to clear the set
FD_SET(socket, &connectionSet); //use our macro to set socket
//Call Select to see if there is data waiting on this socket
result = select(socket+1, &connectionSet, nil, nil, &timeout);
//check results
if (result < 0) //no data
return(false);
if (result > 0)
{
if (FD_ISSET (socket, &connectionSet))
return(true); //data avaiable
else
return(false);
}
//we can never get here
return(false);
}
int ReadNetData(int socket, void *buffer, int numBytes)
{
Ptr bytes = buffer; // Ptr to buffer
int count, n;
n = count = 0;
while (count < numBytes) // loop until we've got all the bytes
{
n = recv(socket, bytes, numBytes - count, 0); // read data
if (n > 0) // we got some bytes
{
count += n; // inc byte count
bytes += n; // inc ptr to buffer
}
else
if (n < 0) // error
return(-1);
}
return(count);
}
Basicly all im trying to do is send a string over a network connection, I dont know why im having so much trouble. Ive had this work in the past, i suspect i messed up some small annoying detail.
Full Code at www.dragon-forged.com/netcode.zip
Thanks Guys!
PS. Once i get all the networking going im going to open source a real barebones version of it to make things easier for people in the future.
I know this stuff can be a huge pain, so if anyone can help me fix this I will paypal you $30. I know im bribing now but im sick of trying to get it to work and im comming up quick on a deadline.
Here is the code that is being used. I will also post the whole source on my site (link at end) if anyone wants to look at it.
CLIENT
int WriteNetData(int socket, void *buffer, int numBytes)
{
Ptr bytes = buffer; //ptr to buffer
int count, n;
n = count =0;
while(count< numBytes) //loop until we have sent all bytes
{
n = send(socket, bytes, numBytes - count, 0); //send..... CRASHES HERE
if(n>0)
{
count += n;
bytes += n;
}
else
if(n<0) //error
return(-1);
}
return(count);
}
static Boolean IsSocketReadyForWrite(int socket)
{
struct fd_set connectionSet;
struct timeval timeout;
int result;
//set timeout values
timeout.tv_sec =0;
timeout.tv_usec =0;
FD_ZERO(&connectionSet);
FD_SET(socket, &connectionSet);
//call select to see if data is waiting on the socket
result = select(socket+1, nil, &connectionSet, nil, &timeout);
//check results
if (result < 0 )
return (false);
if (result>0)
{
if(FD_ISSET(socket, &connectionSet))
return(true);
else
return(false);
}
return(false);
}
SERVER
Boolean IsDataWaitingToBeRead(int socket)
{
struct fd_set connectionSet;
struct timeval timeout;
int result;
//Set timeout and set values
timeout.tv_sec = 0; //no timeout
timeout.tv_usec = 0;
FD_ZERO(&connectionSet); //use our macro to clear the set
FD_SET(socket, &connectionSet); //use our macro to set socket
//Call Select to see if there is data waiting on this socket
result = select(socket+1, &connectionSet, nil, nil, &timeout);
//check results
if (result < 0) //no data
return(false);
if (result > 0)
{
if (FD_ISSET (socket, &connectionSet))
return(true); //data avaiable
else
return(false);
}
//we can never get here
return(false);
}
int ReadNetData(int socket, void *buffer, int numBytes)
{
Ptr bytes = buffer; // Ptr to buffer
int count, n;
n = count = 0;
while (count < numBytes) // loop until we've got all the bytes
{
n = recv(socket, bytes, numBytes - count, 0); // read data
if (n > 0) // we got some bytes
{
count += n; // inc byte count
bytes += n; // inc ptr to buffer
}
else
if (n < 0) // error
return(-1);
}
return(count);
}
Basicly all im trying to do is send a string over a network connection, I dont know why im having so much trouble. Ive had this work in the past, i suspect i messed up some small annoying detail.
Full Code at www.dragon-forged.com/netcode.zip
Thanks Guys!
PS. Once i get all the networking going im going to open source a real barebones version of it to make things easier for people in the future.