PureNet; BlitzNet for PureBasic?!?

Developed or developing a new product in PureBasic? Tell the world about it.
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

PureNet; BlitzNet for PureBasic?!?

Post by LarsG »

Hi everybody.

BlitzNet Optica is an easy to use network library, for BlitzBasic, which takes all the hassle out of network implementation in your application or game.
It uses a different way of communicating over the network, using hubs and tubes..
I can't explain in detail how this works, but a sample Blitz code for a chat client would be something like this:

Code: Select all

;-Optica- Easy Example 1-
;--Optica Chat.A multi-user real-time chat application example.
;-(c)Freeware.
;-Coded by Antony Wells.
;-

Include "blitzGame.bb" ;Include BlitzGame.
;-[ Globals ]
Global Server,Client ;These are specific to this demo, you may use locals/Types if you so wish.
;--------

;--[ Ask user whether to start a server and join, or simply join ]
mode=Input("1=Server,2=Client>")

;--[ Set up Chatter Tube. This is the IO system for this example. You may use multiple tubes at once.

player=netTube("Chatter")
addString(player,"Name",dReliable) ;Name of the chatter(User), using reliable(perfect) transmission.
addString(player,"Say",dReliable) ;Say string, we 'talk' into this varable.
;--=-=- That's the template for IO created, we only do this once.


If mode=1 ;Create server
	serv =hubServer("Test 1","Net War")
	addTemplate(serv,player) ;We add all templates usable to the server.
EndIf ;-[That's it. Just two lines to set up and config the server with the player tube.]

;-Connect and set up Local client.
     client =hubClient("127.0.0.1",player) ;Spawn a client, and give it's        base tube template.
     addTemplate( client,player)  ;Add the template we created above.
;--[ Create our local client chatter, this is specific to the demo, not network lib.]
    cli.chatter =New chatter
    cli\tube =getNewTube(client,1) ;get our network connection 
    cli\name=Input("Enter your name>")


;----------------------
Type chatter ; this type is specific to this example, you may use arrays or locals to hold info.
	Field tube ;Chatters tube(Network connection)-This is returned by the network library.
	Field name$ ;chatters name 
      field say$,lastSay$
End Type

Repeat
	networkCycle();-Update the network.
	
	;- Client code. -Server is handled automatically.
	newClients =newTubesCount( client) ;Check if anyone's joined.
	If newClients>0 ;Yes?
		Print "New Client Joined"
		chat.chatter =New Chatter ;create chatter type. ;specific to thsi demo
		chat\tube=getNewTube( client,1) ;get it's tube.
      EndIf
;-- That's that done.

;-Now we just listen for chat messages to arrive.

for chat.chatter =each chatter ;Go through each client connected.
    chat\say=getValue( chat\tube,"Say")  ;Listen for chat.
    chat\name=getValue( chat\tube,"Name") ;Listen for name change.
    if newValue(chat\tube,"Say") print chat\name+">"+chat\say ;check if it's new data, if so print it the screen, including name.
next
;-
     setValue(cli\tube,"Say",input(">")) ;say something,
     ;the network will automatically broadcast this data to the server,
     ;and the server automatically updates all other clients.
Until KeyDown(1)
I've asked Antony, the author of BlitzNet, if he is willing to port his Network library to PureBasic.
He said that if there is enough people interrested in the library, that he'd be willing to port it.. (as he's also very fond of PB :))

The website for BlitzNet Optica can be found here: http://www.trandom.com/antony/

Would anybody be interrested in this?!?

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Sure. It would be a very useful addition to PB!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Antony used the bittorrent-like technology for this lib (for example.. if you're the server, you have 20 clients, and you must close the server for some reason, you close it and one of the 20 clients becomes a server, thats the first trick you'll see) half-life has this technology also (bought from the guy of bittorrent I suposse).. well anyway, the lib rocks, im just waiting for a game demo to test it, hehe i'll possibly buy this lib for blitz.
Post Reply