Network attempt (solved)

Previous topic - Next topic

Moru

QuoteEdit: Solution turns out to be not to call NETNUMPLAYERS() every frame. I'm now only calling it once every five seconds and only on the server, the clients take too long to call. So the server gets to send the client-list to all the clients.

I'm still having trouble getting network to work, here are some comments so far:

Manual missing for NETSENDMSG (tutorial says it needs two parameters but editor and compiler says three)

If one client sends a message, how does the other clients know from whom it came? Do I need to add the client ID to the message myself? Wouldn't this make it easy to spoof messages so they look like they are coming from someone else?

Is there a way for the server or the clients to get a message when a player leaves or joins?

Does the ID returned from NETCREATEPLAYER$ have to be a string as in the tutorial? I only get numbers so far.

Setting the connect adress to 0.0.0.0 doesn't search the network for a server, not even if I'm running it local on the same computer. Setting adress to "" works though.

This is my testcode so far, I can connect to the server and get logged in and in the playerlist I get the same display on both running programs, Admin and User1 is displayed as players. If I wait a while the server changes the User1 name to something random and locks up wich sometimes causes the client to lock up also.

I'm still seeing that the server program reacts slowly, the userlist changes much later on the server (background process) than on the client. The program is doing a 20 ms pause each SHOWSCREEN wich makes at least my computer run at 0-10% processor power so it can't be why it's so slow.

On the screenshot the top program is the host, the other the client.

Code (glbasic) Select
// --------------------------------- //
// Project: Network test
// Start: Wednesday, June 11, 2008
// IDE Version: 5.254

AUTOPAUSE FALSE // don't pause the game when running in the background

// Global declarations for the network options
GLOBAL __TCP_IP = 0  // If we want a TCP/IP connection we use this one to start the server
GLOBAL __IPX = 1 // If we want IPX we use this one (Only local area network server, not internet)

GLOBAL ok = 0
GLOBAL name$ = "" // The local players name
GLOBAL id$ = 0 // Your local player-id
GLOBAL playerID$[] // array with all ID's connected (after ShowPlayers have run)
GLOBAL playername$[] // array with all names connected
GLOBAL playermsg$[] // space for the message from each player
GLOBAL running_as_client // to keep track of if we are server or client
GLOBAL running_as_server

LOCAL in$
LOCAL msg$

// Connecting to the server, 0.0.0.0 as adress makes it search the local area for a fitting host
ok = NETJOINGAME(__TCP_IP, "My testserver", "", "")
IF ok = TRUE
running_as_client = TRUE
ELSE
PRINT "Can't connect to server", 100, 100
PRINT "trying to create server instead", 100, 110
SHOWSCREEN

ok = Host() // Call the function for hosting a game
IF ok = TRUE
running_as_server = TRUE
ENDIF
ENDIF

PRINT "Name:", 0, 100
INPUT name$, 100,100

id$=NETCREATEPLAYER$(name$)

// ------------------------------------------------------------- //
// ---  Main game loop  ---
// ------------------------------------------------------------- //
WHILE 1=1
// Get a character from the keyboard
in$ = INKEY$()
IF in$ <> "" // If user pressed a key
ok = NETSENDMSG(id$, "", in$) // send message to all
ENDIF

//msg$=NETGETMSG$(id$)

PRINT "Message: " + msg$, 100, 0
GOSUB ShowPlayers

PRINT "ID: " + id$ + " - " + RND(50), 0, 0 // just to show that the program is running
SHOWSCREEN
SLEEP 20 // give the processor some rest (and let the other clients work)
WEND


END

// ------------------------------------------------------------- //
// ---  HOST  ---
// ------------------------------------------------------------- //
FUNCTION Host:
// Hosting a server:
ok = NETHOSTGAME(__TCP_IP, "My testserver", "", "")
IF ok = TRUE
RETURN TRUE
ELSE
PRINT "Can't create server", 100, 100
SHOWSCREEN
KEYWAIT
RETURN FALSE
ENDIF
ENDFUNCTION // HOST


// ------------------------------------------------------------- //
// ---  SHOWPLAYERS  ---
// ------------------------------------------------------------- //
SUB ShowPlayers:
LOCAL NumPlayers = 0
LOCAL i = 0

PRINT "Joined Players:", 100, 50
NumPlayers=NETNUMPLAYERS()
REDIM playerID$[NumPlayers]
REDIM playername$[NumPlayers]

FOR i=0 TO NumPlayers-1
playerID$[i]=NETGETPLAYERID$(i)
playername$[i]=NETPLAYERNAME$(playerID$[i])
PRINT i + " " + playername$[i] + " (ID:" + playerID$[i]+")", 100, i*20+100
NEXT

ENDSUB // SHOWPLAYERS


[attachment deleted by admin]

acristo

I'm having the same problem, even with the example Trucidare posted on the forums some days ago...
Also, I created an virtual machine (vmware) and I was able to connect the  client tothe server without a problem, but again the server started getting very slow.. and finally both (client and server) hang.

This is really annoying... there is anything that can be done ? or I need to forget about using network part of GLBasic ?


trucidare

This Problem isnt actual. I Thougt its done by Gernot.
My Example works fine for me everytime i start it. but i will check again for you.
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

acristo

Thank you Trucidade, I appreciate it... I was thinking if this could have something to do with SP2/3 updates of XP... what do you think ?  I didn't tried this on other platforms so I can't really say.

Best Regards

trucidare

i wrote the chat on sp2. a friend uses sp3 and says many network application like torrent clients doesnt work.
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

acristo

well my torrent are fine with sp3.... :D you said that your chat example works without any problem on your machine ? no lags ? no hangs ? I hope some more investigation will be put in place about it... thx

trucidare

#6
Here a Screenshot.
Works like a charm :)



[attachment deleted by admin]
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Moru

Any chance of us others getting a look at the code to see what we are doing wrong? :-)

trucidare

Here is the Post.

Code (glbasic) Select
http://www.glbasic.com/forum/index.php?topic=1975.msg14491#msg14491

feel free to use it. its only a proof of cencept. to chat over lan or internet change the address in code.

MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Moru

That one was quite hidden in some german post, mabe put it up in the network area? :-) And some comments would help too, what are those inline things for example? I don't see anything in the manual about network and inline commands?

trucidare

the inline thing in hawknl.gbas is no part of the chat. its only some wrapped funktion for use sockets in glb.
please show in the code its very simple code.

have fun
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

MrTAToad

I'm having the same problem too - using "" or "0.0.0.0" wont search for hosted machines - the only way to get it working is to use a qualified IP address.

The program occurs both with my code and with the HelloNet demo program.  I'm using a mixture of Vista and XP machines

Moru

I figured what it was that made my program slow, when I call this command: num = NETNUMPLAYERS()

It takes between 250 and 450 ms to complete and this ofcourse makes the program realy slow. Is there something I should know about this command?

Hemlos

#13
Quote from: Moru on 2008-Oct-12
NETNUMPLAYERS() Is there something I should know about this command?
The client side doesnt need it..

Server/Client MMO Network setup:
1. Server side: do these around 1 per second, and the program will run lightning fast:
The NETNUMPLAYERS is sending a packet through directplay, they are waiting in line to be read and thus will slow things down if they get too much traffic. I think thats how it works...Gernot reading this thread? Is this correct about the packet flow pileup?
NETNUMPLAYERS
NETGETPLAYERID$
NETPLAYERNAME$

2. Serverside: use the NETGETMSG$/NETSENDMSG commands at a realtime pace in main loop. Setup the server as a radiating message hub. let server distribute them appropriately to all the clients because the server should be running really fast with LIMITFPS -1...this is how you eliminate the need for NETNUMPLAYERS command from a client side.

3. CLientside : Make the clients send all msgs to the server as data strings to be read serverside, and handled appropriately.

4. serverside: use autopause FALSE for a server, and use the server to send all player list information from the server to the clients, so the clients get a player list. Also, Use systempointer TRUE...you dont want to lock the mouse in the server window.

5. serverside: This is how i set it up every second:
PLATFORMINFO$("TIME") changes once per second..good for checking FPS too, btw
Code (glbasic) Select
LastHeartBeat$=HeartBeat$
HeartBeat$=PLATFORMINFO$("TIME")
IF LastHeartBeat$<>HeartBeat$ THEN CHECKNETPLAYERS()


With this setup the server is running 450-470 fps.

Heres the basic structure for my server..as you can see its pretty much bare bones with no game attached...
but it will let tons of players join over the internet
The player[][] array is 2d....i think i need to make it 1 dimension so the server runs faster...im not happy with 450 fps hehe  :S


Code (serverside main loop) Select
WHILE TRUE
DRAWSPRITE 0,0,0 //background window
//network
MASTERHUB() //this is making sure the server is always running, it only posts the host command once as needed.
CHECKNETPLAYERS() //the heartbeat is here for NETNUMPLAYERS NETGETPLAYERID$ NETPLAYERNAME$
PLAYERLIST() //this is reading player array and printing PLAYER list to screen
RCVMSG() //this is listening for messages dynamically,  realtime speed
//need to add send msg routines function here
//need to add a function for the game: player in-game processor here, for controling players positions, actions, and responses to actions etc

//2d gui:
MOUSESTATE MOUSEX, MOUSEY, MB1, MB2
CLOSEBUTTON()  //redundant but looks pretty :)
PRINT "FPS: "+HF_FPS(),400,20  //fps is being tested here using platforminfo$ time
SHOWSCREEN
WEND



Hope this helps everyone, sorry about the belated response, i didnt see this thread till yesterday.
-Hem

PS.
LOL check this remark header out....6 years old haha....
....this is one of the command sets that evolved Doctor DiNgs, turn into Mr. "GLBasic" Hyde:  GLBasic. ver 1

im going to need a few hours to work on it to get it working like it did originally.
I will let you know, and ill post the code in networking when im done.
Its a  - MMO Client/Server Network
Code (a relic of glbasic giving birth) Select

// Project: HUB SERVER
// Start: Tuesday, October 01, 2002
// Compiler Version: 1.20821

Bing ChatGpt is pretty smart :O

acristo

that's really cool Hemlos.. !!!