PDA

View Full Version : Code: Networking



ErosOlmi
16-10-2008, 18:56
Hi all,

I was quite busy recently but in reality I was working on the networking area.
I'm finishing to implement few new functions in TcpUdp module and improving some already there.

I'm also finishing a prototype script that will show a possible implementation of the networking side of the game.
The script is composed of 2 parts: server and clients.
A server application starts and wait for clients to connect.
When a client starts, it sends a broadcast message on the LAN asking if a server is available.
If a Server reply, they exchange few info for next data exchange.

So far I've tested with 1 server and 10 clients.
For the moment data exchanged is the window position and size of the clients. So every time the client window is moved or resized, those data is sent to the server that collect them and show in a ListView.

Exchanged data can be whatever. For the moment I've just implemented few ideas.

ADDED: 2008.10.19
Attached to this post a demo of what I've so far. You will find a server application and a client application.

File attached contains a Server and a Client application
Server can be executed on any computer in your network, if you have a network. But if you have not a network it will be fine either. Important is to have a TcpIp stack installed but if you are reading this post it should be all ok :D
Client can be executed on the same computer of the server or in any other computer you can have on your local LAN
When Client and Server are executed nothing will happen.
Click on "I'm a Server" button in the server window. Server will start listening for clients to connect.
Click on "Find server" button on the Client side. If all ok, client will find the server and they will exchange few data for handshaking
If they seems connected, TRY TO MOVE client window around and see.
If you started more clients, move them around

Forgot to say that if you have a personal firewall active, you will have to authorize those applications to work on the net.
This is exact and normal because those applications try to act as server on UDP ports from 5000 to 5010. 5000 is Server, from 5001 to 5010 clients.

Added: 2008.12.17

added full source code for client and server. thinBasic 1.7.0.0 needed!


Ciao
Eros

Petr Schreiber
16-10-2008, 19:02
Nice surprise Eros,

I am happy you are working on it.
Networking was always "that complicated thing" for me, I hope new commands will change my mind :)


Petr

Michael Hartlef
16-10-2008, 22:01
NICE! THANK YOU!!!! :)

kryton9
17-10-2008, 04:58
Thanks Eros, nice of you to tackle this one for us!

ErosOlmi
19-10-2008, 00:28
Attached to first post of this thread a demo of what I've so far. You will find a server application and a client application.

File attached contains a Server and a Client application
Server can be executed on any computer in your network, if you have a network. But if you have not a network it will be fine either. Important is to have a TcpIp stack installed but if you are reading this post it should be all ok :D
Client can be executed on the same computer of the server or in any other computer you can have on your local LAN
When Client and Server are executed nothing will happen.
Click on "I'm a Server" button in the server window. Server will start listening for clients to connect.
Click on "Find server" button on the Client side. If all ok, client will find the server and they will exchange few data for handshaking
If they seems connected, TRY TO MOVE client window around and see.
If you started more clients, move them around


Programs are still under heavy change.
Many things are still missing. I'm improving all the functionalities and deciding what to transfer from source code to compiled module functions.
Very soon a final example with full thinBasic source code that will let you inspect it and suggest changes or whatever.

Let me know.
Ciao
Eros

Petr Schreiber
19-10-2008, 00:42
Hi Eros,

very nice!
Worked well, just had to confirm I really do not want to block the program from doing networking :)
To launch multiple clients I had to launch them from different directories, could be related to de-bundling process.

Thanks a lot!,
Petr

ErosOlmi
19-10-2008, 00:47
Forgot to say that if you have a personal firewall active, you will have to authorize those applications to work on the net.
This is exact and normal because those applications try to act as server on UDP ports from 5000 to 5010. 5000 is Server, from 5001 to 5010 clients.

Yes, Petr. I confirm that to run multiple copies of the client requires to place them in different directories. This is the bundling process that fails when it try to "explode" bundled exe because in the same directory are already present expanded thinbasic and modules.

Ciao
Eros

kryton9
19-10-2008, 06:45
That worked really well on single machine acting as both server and client. Thanks again Eros!

Michael Hartlef
19-10-2008, 07:55
Yes, worked very well here too. Good job!

ErosOlmi
17-12-2008, 23:43
Attached to first post of this thread please find full source code of Client/Server example previously release as executable.
thinBasic 1.7.0.0 is needed in order to execute the examples.

How to use them?

Run the Server script and click on "I'm a server" button
Run the Client script and click on "Find server" button
Move around client window and you will see Server window following your movements
Run more than one client script and move them around


Client and Server scripts can be executed on different machines providing used UDP ports are not firewalled.

Many things can be improved. Have fun with it.

Ciao
Eros

Michael Hartlef
18-12-2008, 00:48
Thanks for the sources! :)

Petr Schreiber
18-12-2008, 10:40
Thanks Eros,

very elegant code as usual :)


Petr