SDL_net problems
Both the functions SDLNet_TCP_Open and SDLNet_TCP_Recv wait a very long time if they can't connect or there is no data. This is very annoying, because if it can't connect, I would like to user to be able to do other things in the program during the time the SDLNet_TCP_Open function still runs. And for SDLNet_TCP_Recv, it's very annoying that this function locks my program for 30 seconds if there's no data to receive, instead of just immediatly seeing that there's no data. Is this normal?
Multithreading is useful for networking. Running your networking code in a seperate thread to your main code could be a good solution.
I'm completely hopeless now!!!
SDL_Net was starting to get very annoying, for example this code crashes:
While it shouldn't according to the manual. So, I can't even use checksockets to actually test if sockets have some data coming in.
So then I wasted 2 hours of my time to try winsock, and that one had again the recv function that waits forever and hangs your program. In a tutorial about winsock I saw something about non-blocking sockets, but those require HWND stuff and such and I want it platform independent!!
So I have to use this "constantly crashing and hanging" SDL_Net anyway to be platform independent.
I'm making the client and someone else is making the server, but he uses Java and all sorts of super high level libraries for the server and knows no C++, so he can't help me with my socket problems (I'm using DevC++ btw).
I have found no single tutorial or site explaining how to deal with these problems properly and am completely stuck :(
SDL_Net was starting to get very annoying, for example this code crashes:
Quote:
//SDL_Net crashing stuff
SDL_Init(0);
SDLNet_Init(); //initialize it
SDLNet_SocketSet sox = SDLNet_AllocSocketSet(1); //make the socketset
TCPsocket sock; //make the socket
SDLNet_TCP_AddSocket(sox, sock); //add sock to sox
IPaddress ip; //an ip
SDLNet_ResolveHost(&ip, "gamedev.net", 80); //set the ip to google port 80
sock = SDLNet_TCP_Open(&ip); //open the connection
SDLNet_CheckSockets(sox, 0); //checksockets ==> crash!
While it shouldn't according to the manual. So, I can't even use checksockets to actually test if sockets have some data coming in.
So then I wasted 2 hours of my time to try winsock, and that one had again the recv function that waits forever and hangs your program. In a tutorial about winsock I saw something about non-blocking sockets, but those require HWND stuff and such and I want it platform independent!!
So I have to use this "constantly crashing and hanging" SDL_Net anyway to be platform independent.
I'm making the client and someone else is making the server, but he uses Java and all sorts of super high level libraries for the server and knows no C++, so he can't help me with my socket problems (I'm using DevC++ btw).
I have found no single tutorial or site explaining how to deal with these problems properly and am completely stuck :(
hi Lode,
you might want to consider switching libraries (read: if i were you, i would do it [smile]). there are other libraries out there besides SDL_net which offer cross-platform networking. i strongly recommend you check out raknet. Raknet is cross platform, but it also is high level and offers a wide array of features. for example, with rakknet, you dont have to worry about managing sockets or connections, it takes care of that for you. the documentation is the best i've ever seen for any library (no kidding), and the creater, Rak'kar, is very friendly and active in his messageboard with helping people with their problems. alternatively you could check out the forum FAQ of the multiplayer forum, for a list of other libraries to choose from. ive tried SDL_net, then eNet, and then finnally i settled with rakknet. i don't think im going to switch anytime soon [smile].
btw, you might want to think about what your doing. you say that someone else is writing the server. i too had a plan like this once. i met a guy who was a networking guru who wanted to work with me. our plan was for him to write the server and protocol and for me to take care of the client. this didnt work out too well. for one thing, the guy disapeared after only a few failed tests in trying to get things to work. but, a more serious problem that we never thought of is this : the person writing the client should know exactly whats going on in the server, and you say you dont even use the same language as this person? theres lots of complicatd things going on, and you really cant just "trust" that the server is going to do everything you need it to. for example, if the person who is writing the server doesn't know anything about the game code, how will he know how to parition the clients into groups and stuff? the server should also do things like collision detection and movement. basically what im saying is, both the client and server should be written by the same person (or persons) who are working on the entire game. one really can't be ignorant of the other. however, if the game is very simple, it might work, but i would strongly recommend re-thinking this. if the situation i described isnt what your doing, then just ignore this.
good luck.
you might want to consider switching libraries (read: if i were you, i would do it [smile]). there are other libraries out there besides SDL_net which offer cross-platform networking. i strongly recommend you check out raknet. Raknet is cross platform, but it also is high level and offers a wide array of features. for example, with rakknet, you dont have to worry about managing sockets or connections, it takes care of that for you. the documentation is the best i've ever seen for any library (no kidding), and the creater, Rak'kar, is very friendly and active in his messageboard with helping people with their problems. alternatively you could check out the forum FAQ of the multiplayer forum, for a list of other libraries to choose from. ive tried SDL_net, then eNet, and then finnally i settled with rakknet. i don't think im going to switch anytime soon [smile].
btw, you might want to think about what your doing. you say that someone else is writing the server. i too had a plan like this once. i met a guy who was a networking guru who wanted to work with me. our plan was for him to write the server and protocol and for me to take care of the client. this didnt work out too well. for one thing, the guy disapeared after only a few failed tests in trying to get things to work. but, a more serious problem that we never thought of is this : the person writing the client should know exactly whats going on in the server, and you say you dont even use the same language as this person? theres lots of complicatd things going on, and you really cant just "trust" that the server is going to do everything you need it to. for example, if the person who is writing the server doesn't know anything about the game code, how will he know how to parition the clients into groups and stuff? the server should also do things like collision detection and movement. basically what im saying is, both the client and server should be written by the same person (or persons) who are working on the entire game. one really can't be ignorant of the other. however, if the game is very simple, it might work, but i would strongly recommend re-thinking this. if the situation i described isnt what your doing, then just ignore this.
good luck.
FTA, my 2D futuristic action MMORPG
If worse comes to worse, you could always just go with sockets. If you are shooting for cross platform, it isn't that hard to port.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
in socket programming, when you do anything you have to check for errors. that means connecting, recv'ing, sending, resolving hosts, etc.
so put error checking the the program and you should be able to pinpoint the problem.
so put error checking the the program and you should be able to pinpoint the problem.
Learn to make games with my SDL 2 Tutorials
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement