While debugging it this code returned false
r = WSAStartup(MAKEWORD(2,2), &Winsock);
if(!r)
{return false;}
which would suggest the socket isnt being made and I have no idea why tho
While debugging it this code returned false
r = WSAStartup(MAKEWORD(2,2), &Winsock);
if(!r)
{return false;}
which would suggest the socket isnt being made and I have no idea why tho
Upon adding that error checking method to my other networking application using similar code, it also caused my server to no longer receive updates on the client's position, so I have removed that. Does anyone know why this isn't working, its really starting to bug me :/
While debugging it this code returned false
r = WSAStartup(MAKEWORD(2,2), &Winsock); if(!r) {return false;}
which would suggest the socket isnt being made and I have no idea why tho
http://msdn.microsoft.com/en-us/library/windows/desktop/ms742213%28v=vs.85%29.aspx
why exactly did you think zero for that function means failure?
I'm looking over your code, and nothing terrible jumps out to me. have you tried changing to tcp to make sure everything's setup correctly, then switch back to udp?
Upon adding that error checking method to my other networking application using similar code, it also caused my server to no longer receive updates on the client's position, so I have removed that. Does anyone know why this isn't working, its really starting to bug me :/
Step 1: error checking. Step 2: error handling/logging. For example, the documentation for WSAStartup says:
Return valueIf successful, the WSAStartup function returns zero. Otherwise, it returns one of the error codes listed below.The WSAStartup function directly returns the extended error code in the return value for this function. A call to theWSAGetLastError function is not needed and should not be used.<list of error codes omitted>
So WSAStartup is not returning false, it is returning its "success" value, which you are misinterpreting as failure. It is important to thoroughly read the documentation for the functions you are using about what kind of error codes can be returned.
You should at the very least write a log message somewhere when a fatal error occurs, and preferably provide a notification to the user rather than crashing to desktop. Most APIs have a way to get a human (or at least, geek) readable error description, which will help enormously in diagnosing such failures when they happen to a random user on the internet, who might want to play your game but might not be particularly technical.
A few things still need some work:
A relatively simple alternative to multi-threading is to use "non-blocking" sockets. This means you can try to receive in your main loop without stalling the game logic until new data arrives. I would recommend this to someone who is still getting to grips with socket programming. Trying to learn and understand multi-threaded programming is significantly harder, and trying to do both at the same time is a recipe for confusion and error.
When you have your code working, you might also consider writing some code to detect and handle the case where the client or server dies or is shut down. Something as simple as checking if no messages have been received for a reasonable period of time, and then assuming the remote peer is "gone" and informing the user.
I'm unsure how to create these advance ways of error checking, I've put watches on the variables and they all seem to be taking in the expected values, still, there is no networking. I've used very very similar code before on another project, which was transferring only x,y values.
So all I've done is added a z value to the struct, and its not working
Can't you offer me some sample code, I don't understand fully what you mean
Which part didn't you understand?