tneva82
February 20th, 2009, 02:36 PM
Not working at all. I can open the port without errors, I get client connected to it but reading results in -1 as a result.
IPaddress readAddress;
TCPsocket readSocket;
Just the address of server and the socket it's going to use for receiving.
int serverNetwork::openPort(int readPort) {
if(SDLNet_ResolveHost(&readAddress, NULL, readPort) !=0) {
printf("Address resolving failed!");
exit(1);
}
readSocket=SDLNet_TCP_Open(&readAddress);
if(!readSocket) {
printf("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
exit(2);
}
}
Resolve servers address and open socket to it. As far as I can see no real difference to example codes. Just names.
int serverNetwork::receiveData(char *answer, int maxLength) {
return result=SDLNet_TCP_Recv(readSocket, answer, maxLength);
}
And here's where issues seems to be. Result is constantly -1. How What's causing that? SDL_Net doc's say just that it's error. Nothing about what sort of error.
And here's the code which uses class of which above are part of.
serverNetwork *server=new serverNetwork();
char *answer=new char[120];
int count;
bool running=TRUE;
server->openPort(4500);
printf("Server running\n");
while(running) {
server->checkForConnections();
count=server->receiveData(answer, 120);
printf("%i\n", count); // prints -1 every time.
Anybody could point the(probably obvious) error I'm making?
IPaddress readAddress;
TCPsocket readSocket;
Just the address of server and the socket it's going to use for receiving.
int serverNetwork::openPort(int readPort) {
if(SDLNet_ResolveHost(&readAddress, NULL, readPort) !=0) {
printf("Address resolving failed!");
exit(1);
}
readSocket=SDLNet_TCP_Open(&readAddress);
if(!readSocket) {
printf("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
exit(2);
}
}
Resolve servers address and open socket to it. As far as I can see no real difference to example codes. Just names.
int serverNetwork::receiveData(char *answer, int maxLength) {
return result=SDLNet_TCP_Recv(readSocket, answer, maxLength);
}
And here's where issues seems to be. Result is constantly -1. How What's causing that? SDL_Net doc's say just that it's error. Nothing about what sort of error.
And here's the code which uses class of which above are part of.
serverNetwork *server=new serverNetwork();
char *answer=new char[120];
int count;
bool running=TRUE;
server->openPort(4500);
printf("Server running\n");
while(running) {
server->checkForConnections();
count=server->receiveData(answer, 120);
printf("%i\n", count); // prints -1 every time.
Anybody could point the(probably obvious) error I'm making?