|
Post by u9 on Feb 27, 2008 17:31:14 GMT -5
Here is some feedback and a few bugs...
I noticed that this object does not have an initialize and a terminate method. This as such is probably fine, if nothing needs to be initialized, but i ran into a small problem when running from the IDE. When the program terminates, i need to make some kind of call to stop the server... otherwise i have get a "address in use" error when i try and start another program that also wants to use the network. So what is the call that stops the network?
Why does Net.ReadValue require a connection number when it is the client? How does the client know what connection number it has?
What is the purpose of net.ReadSentValue ?
I was also wondering, how do i know when a client has connected? I have tried just looping from GetFirstConnIndex() to GetLastConnIndex() but ran into some problems. See following.
How does a client know when he has been disconnected? Is there any function I can call to see if the connection is still OK?
This code gives a type mismatch error:
For idx = net.getFirstConnIndex() To net.getLastConnIndex() system.debugPrint net.ReadValue("ip", idx ) Next
This has something to do with what Get_XXX_ConnIndex() returns i think. If i wrap the idx in a cint() it works.
When my third computer connects to the server a dialog box pops up on the server saying: Run-time error '360': Object already loaded
Running the code above (fixed with cint()) I have tried connecting and disconnecting from the server with 2 computers, and after a few "re-connects" i get this error: Run-time error '457': This key is already associated with an element of this collection. I think this error has something to do with net.CloseConnection() not working properly for the client. If I disconnect the client using CloseConnection() and then reconnect by calling StartClient() then I get error '9': subscript out of range, on the client who is trying to re-connect.
I hope this helps.
|
|
|
Post by Guilect on Feb 27, 2008 21:39:04 GMT -5
"So what is the call that stops the network?" CloseConnection() This is about the same as 'stopserver'.
"Why does Net.ReadValue require a connection number when it is the client? " Don't know, that is the way it is. Right after connecting, I believe you can use .GetLastConnIndex to see what index it has. You could build in a pause on the server to prevent any new connections from being made for a few seconds to allow for this.
"What is the purpose of net.ReadSentValue ?" It reads back the data that was most recently sent. A$ = "hello" senddata A$ IF readsentvalue = "hello" then A$ = "good bye" Use it however you see fit.
"how do i know when a client has connected? I have tried just looping from GetFirstConnIndex() to GetLastConnIndex() " That is one way or watch Net.GetConnCount().
"If i wrap the idx in a cint() it works." I have made a small change to the code. I think this will fix this issue.
I have seen the error 9 message. Will try to investigate. for now try wrapping all calls with checks for valid data.
|
|
|
Post by u9 on Feb 28, 2008 6:06:38 GMT -5
Regarding error 9, i get the error when i call net.startclient() after it has been disconnected using CloseConnection(). If i quit the program and then try to connect, there is no problem. It is usually net.startclient() that fails and i can read the "subscript out of range" in net.GetLastError().
|
|
|
Post by u9 on Feb 28, 2008 6:20:47 GMT -5
doing some testing it seems that CloseConnection() is the culprit. It seems to decrease the GetLastConnIndex(), both on the server and the client, down to 0 when it is called. This is wrong as they always initialize to 1, both for the server and the client.
Hope this helps.
I have another worry. When a client (in the middle of all connected clients) disconnects, do all the other clients get a new connection index? I.e. is there no way of keeping track of which player belongs to which index?
|
|
|
Post by Guilect on Feb 28, 2008 7:52:49 GMT -5
I appreciate the help. I am learning about this as we go.
I will look into the CloseConnection routine and see what is going on there.
Not sure what happens to clients's indexes. Will have to test when time permits.
|
|
|
Post by Guilect on Feb 28, 2008 12:44:43 GMT -5
"When my third computer connects to the server a dialog box pops up on the server saying: Run-time error '360': Object already loaded"
I believe that I have fixed this issue. (BTW: "my third computer". You have 3 computers !!!)
This is how the clients work. They each get a unique index number when they connect to a server. The client will always have the same index number as long as they stay connected to the server. If a client disonnects, that index number is freed up for future use. The next client that connects gets the first (lowest) value index that is available.
ex. you have 5 clients all connected:
client 1 : index 1 client 2 : index 2 client 3 : index 3 client 4 : index 4 client 5 : index 5
client 4 drops out. a new client connects, It now gets assigned index 4.
|
|
|
Post by matthew on Feb 28, 2008 13:21:23 GMT -5
(BTW: "my third computer". You have 3 computers !!!) lol ;D
|
|
|
Post by u9 on Feb 28, 2008 14:29:36 GMT -5
Hehe i have 5 computers Two laptops (one old, one new), two desktops (one old, one new), and then my girlfriend has a laptop That's why Brutus2D registration is such a pain But I only used 3 in the test. One server, and two tried to connect twice... just for some testing. Anyways, when you fix the "out of range" error I can do some more testing on what happens when clients in the middle disconnect and how to handle that etc. Keep up the good work
|
|
|
Post by u9 on Mar 3, 2008 4:17:30 GMT -5
I tried the new update, but getfirstconnindex and getlastconnindex are still not right. Try this program: brutus.pewtersoftware.com/upload/files/networking_test.rarIt shows firstconnindex and lastconnindex in the window title. When you start the program the values are 0 and 1. If you click "Host a game" (which calls net.startserver) the first index is set to 2. If you then click cancel (which calls net.closeconnection) the indices are both set to 0, i.e. not the values they initialized with. Calling start again will set only the first index to 2, so we end up with 2 and 0. That was on the server. Now click on "Host a game" to start the server, then start a few other instances of the program and click "connect to server", type your IP and click "Connect"... you should notice that on the last client connected the indices are 1-1... while for any client connected before has indices 1-4, probably telling how many clients are connected to the server. Either they should all have indices 1-1 or all 1-4. Anyway, press escape for one of the clients you will notice his indices set to 0-0, and as such, if you try to reconnect with the same client you get the "out of range" error. I think this is because the last index is 0 instead of 1. Also, I don't know if this is proper behaviour, but if you disconnect the first client who connected, the firstConnIndex does not go up to 3. Maybe it shouldn't. It stays at 2 even though that client has disconnected. And If i then disconnect all the clients in the same order i connected, then lastConnIndex will not count down again (probably not important?). Only if the clients disconnect in reverse order as they connected will lastConnIndex count down to 1 agian. I have been thinking, maybe this way of indexing the connection isn't the best way to do it. Maybe one could instead have a method like net.GetNext() for iterating through all connections returning -1 at the end, and then having some kind of "carot-reset" method, e.g. net.ResetIndex(), to start from the beginning of the list again. This way you don't have to "keep track" of the indices. You could just use a simple list, adding and removing connections as they connect/disconnect. What do you think? Anyways, to sum up, the biggest problem right now is that when you call closeconnection the indices get wrong values, and therefore a client cannot reconnect without first restarting the program. Hope this helps.
|
|
|
Post by Guilect on Mar 3, 2008 9:03:09 GMT -5
"Hope this helps." Of course it helps. I appreciate your effort and the time you spend on helping out.
I will look at coming up with either a fix to the current method or a different method. Stay tuned...
|
|
|
Post by Guilect on Mar 11, 2008 6:38:26 GMT -5
I have been working on the reported issues. I have had mixed results.
I blelieve that the connect-disconnect-reconnect issue is resolved.
As for the clients getting their own info regarding number of connections, not so good.
As such, I would like to propose that the server application just broadcast this info, just like any other network communications and the clients receive it. Make it a push technique rather than a poll ( or pull) technique. There are techniques which can be employed to keep the net traffic down. You can use the IsDiff command, you can only periodically send this data, or just send it one time at the beginning of a game if you would not allow more players to join once a game is started.
I am still thinking of how clients can get which connectiion indexes are active.
I think simplifying the senddata command so that clients just always talk to the server would be good. The server can re-broadcast info to other clients.
|
|
|
Post by u9 on Mar 12, 2008 5:56:55 GMT -5
hmm... yeah i agree. In fact, in a server-client architecture i don't think the clients can talk to each other. So i think it is a good idea to keep it like that. I am excited to try the connect-disconnect-reconnect I have set up most of the framework for a network game, but i don't really know what game to make hehe
|
|
|
Post by Guilect on Mar 12, 2008 19:51:07 GMT -5
U9: here is a version that has what I think is the connect-disconnect-reconnect issue fixed; if you want to try it. I probably have slightly changed some other code in this version in order to try to fix other issues. So you might have to make some small changes to your code to run. (like make the server dish out all the info and just have the clients read data from the server. BTW: the server is always index 1) brutus.pewtersoftware.com/upload/files/Brutus2D_Net2.zipnote: if a server exe does not exit cleanly the port it was connected to can still be taken. It is only released when the exe ends completely. This is not a B2D thing, this is a windows thing.
|
|
|
Post by Guilect on Mar 16, 2008 19:03:30 GMT -5
Ok new version. added a new command just for Clients: Net.GetClientIndex() It returns -1 until its real value is received from the Server. (just remembered, the command is not in the IDE's autocomplete. I'll add it after we are comfortable with how the Net object works in general). In general Clients should just senddata (which goes to the Server). And readvalues from the server. The server index, once a server is started, is always 1. The following commands should be considered Server only : GetConnCount() -- Returns the connection count. GetFirstConnIndex() -- Returns the lowest client index. GetLastConnIndex() -- Returns the highest client index. The server can broadcast these values where and when appropriate and the Clients can pick up the values. Get it here brutus.pewtersoftware.com/upload/files/Brutus2D_Net3.zip
|
|
|
Post by u9 on Mar 22, 2008 15:19:22 GMT -5
i'll give it a try as soon as i have some time
|
|