Crystal Space
Welcome,
Guest
. Please
login
or
register
.
May 25, 2013, 05:16:36 am
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
9224
Posts in
2230
Topics by
5389
Members
Latest Member:
Sandradhernandez
Crystal Space
Crystal Space Development
Support
Some questions about how to insert net code in "simpmap"?
« previous
next »
Pages:
[
1
]
Author
Topic: Some questions about how to insert net code in "simpmap"? (Read 2516 times)
Jr. Member
Posts: 81
Some questions about how to insert net code in "simpmap"?
«
on:
February 04, 2009, 11:53:04 am »
I have some questions about how to insert net code in "simpmap".
I have created a simple server. And I add some code in " bool Simple::OnKeyboard(iEvent& ev)" function, so if it gets the keybord message, it will send the message to the server. And now the server can receive every keybord message from simpmap.
But I don't know where to insert the net code, so the simpmap can receive the message from server in time.
Please help me !!! Thank you very much!!
Logged
Leetonicon
Newbie
Posts: 15
Re: Some questions about how to insert net code in "simpmap"?
«
Reply #1 on:
February 09, 2009, 07:00:20 pm »
Could you clarify what you mean by "in time". More directly:
What did you try already
What type of sockets are you using (TCP or UDP)
What type of I/O are you using (blocking or nonblocking)
A long time ago (before I opted to switch over to python / cel and then have my video card fail out) I had a fairly simple app built on top of simpmap that was set up to send stuff over non-blocking UDP sockets... if memory serves, I did both the send and receive in the same ProcessFrame function and don't recall having any problems as long as the amount of data was reasonably small (I had problems if I sent too much data from server to client and client started getting multiple messages glued together that it mistakenly treated as a single message but that just required improving the message format.)
Logged
Jr. Member
Posts: 81
Re: Some questions about how to insert net code in "simpmap"?
«
Reply #2 on:
February 10, 2009, 07:52:17 am »
Quote from: Leetonicon on February 09, 2009, 07:00:20 pm
Could you clarify what you mean by "in time". More directly:
What did you try already
What type of sockets are you using (TCP or UDP)
What type of I/O are you using (blocking or nonblocking)
A long time ago (before I opted to switch over to python / cel and then have my video card fail out) I had a fairly simple app built on top of simpmap that was set up to send stuff over non-blocking UDP sockets... if memory serves, I did both the send and receive in the same ProcessFrame function and don't recall having any problems as long as the amount of data was reasonably small (I had problems if I sent too much data from server to client and client started getting multiple messages glued together that it mistakenly treated as a single message but that just required improving the message format.)
The sockets i use is TCP. And the I/O type i use is nonblocking.
Now the server can send and receive, but the client can only send message, it can not receive message from server after the simpmap run the function "Run ()" Simple::Application().
I don't know where to insert the net code, so when the simpmap is running, it can receive message from server at the same time.
Logged
Leetonicon
Newbie
Posts: 15
Re: Some questions about how to insert net code in "simpmap"?
«
Reply #3 on:
February 12, 2009, 12:31:31 am »
Okay... I went back and looked at my code... I had migrated to using a thread (p_threads) so that I could get data from the server at a rate that was independent of the FPS calculations... having said that, the easiest thing to do is just put your recv() calls in ProcessFrame... you will have some delay (since if the server moves an object 3 units at time T, it may not be shown moving on the screen until T+k, where k is the delay to send across the wire + the delay between when the client gets the data and when ProcessFrame gets called... but assuming client and server are either on same machine or at least connected via LAN and your getting 30 fps, this shouldn't be the end of the world... I would suggest going that approach until you've played with CS more and only then worry about doing more advanced interpolation etc. (note that depending on what you're using (i.e. if you are using some of the cell behaviors that move objects for you), the delay may not be noticable... most of the time the server update is consistent with what CEL was dead reckoning you should be, and the rest is somewhat unavoidable just from the nature of the doing distributed processing)
So... did that answer your question or did you already try putting the recv() calls in processFrame? [Note that even in my code with threads, I basically had a get data loop in the separate thread to constantly update the client state (with some hand done dead reckoning if I hadn't gotten any updates from the server recently) and then in processFrame, I used to mutex to prevent doing stuff during an update of the local client state and then used the current client state to do all my positioning but I'd recommend avoiding threads during initial development (other than to keep them in mind) as I'm not a huge fan of debugging multi-threaded applications if I can help it]
Logged
Jr. Member
Posts: 81
Re: Some questions about how to insert net code in "simpmap"?
«
Reply #4 on:
March 04, 2009, 03:37:49 pm »
Thank you for your advice!! But now I met a serious problem.
If I put the recv() calls in processFrame function, the whole program will dead when it runs to processFrame function. And if i delete the recv() calls from processFrame , the program can run as usually.
I don't know why, please help me !!
Logged
Leetonicon
Newbie
Posts: 15
Re: Some questions about how to insert net code in "simpmap"?
«
Reply #5 on:
March 05, 2009, 09:17:03 pm »
Are you sure you're doing non-blocking sockets? (and not doing something like while (!data = recv(100)))
I don't have any network code lying around, but basically, you should probably be doing something like either:
Option 1: select based polling:
add socket to r_fd; // man select should give you some examples
select(&r_fd,&w_fd,&e_fd,0); // bah ... I can never remember the order of r,w,e
if (check) // check to see if the socket is ready to be read
recv(data,1000); //would block if there was nothing there, but select says it's safe
Option 2: non blocking sockets:
//after creating sockets
setsockopt(sock,SOCK_NBLOCK) ; //man setsockopt ... you probably need to include something and I'm blanking on the right flag
in your process frames:
retval = recv(data,1000); //read the man page ... if memory serves, 0 means no data, -1 means error, positive definitely indicates the number of bytes read... if you want to be slightly more robust, you can check errno ... EAGAIN (I think) indicates nothing was ready, other errors indicate things like the fact that the socket is dead so you'd want to either quit or try reconnecting.
Edit to add: if you haven't done so before, I'd strongly suggest you implement or at least take apart and minimally extend a non-blocking chat client/server (there should be plenty of tutorials on the web)... just using basic printf/gets to send/recv data over a network to avoid having to deal with both the complexities of networking and learning crystal space.
«
Last Edit: March 05, 2009, 09:20:46 pm by Leetonicon
»
Logged
Jr. Member
Posts: 81
Re: Some questions about how to insert net code in "simpmap"?
«
Reply #6 on:
March 06, 2009, 10:21:54 am »
Thank you for your help;
Finally I work it !
I use "select" function in ProcessFrame (), and then simpmap work successfully!!
This problem is bothering me several weeks. Thank you for your help again!!
Logged
Pages:
[
1
]
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Crystal Space Development
-----------------------------
=> General Crystal Space Discussion
=> Support
-----------------------------
Crystal Space Project Development
-----------------------------
=> Feature Requests
=> Plugins
=> Bug Reports
-----------------------------
Crystal Space Development
-----------------------------
=> Game Content Creation
-----------------------------
Miscellaneous
-----------------------------
=> Article/Tutorial Requests
=> Article/Tutorial Discussion
-----------------------------
Crystal Space Project Development
-----------------------------
=> Development Discussion
-----------------------------
Crystal Space Projects
-----------------------------
=> Project Discussion
=> WIP Projects
=> Finished Projects
-----------------------------
Associate Projects
-----------------------------
=> CEL Discussion
=> Crystal Core Discussion
=> CrystalBlend Discussion
-----------------------------
Crystal Space Project Development
-----------------------------
=> Google Summer of Code
-----------------------------
Associate Projects
-----------------------------
=> Apricot (Open Game)
=> Ares Project
Loading...