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)
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?!?


