server code
rem setup the net connection for the server
set window on
sync on
backdrop on
dim msgString$(0)
perform checklist for net connections
nettotal = checklist quantity()
for i = 1 to nettotal
if checklist string$(i) = "Internet TCP/IP Connection For DirectPlay" then netsel=i
next a
add$ = "xx"
set net connection netsel,add$
create net game "Matt's Multiplayer Engine","Matt",8,2
while escapekey() = 0
get net message
while net message exists() = 1
netstring$ = net message string$()
`mtype = net message type()
`handle_message(mtype)
endwhile
print net buffer size()
perform checklist for net players
print checklist quantity();" Players Connected"
print netstring$
set cursor 0,0
sync
endwhile
free net game
function handle_message(tp)
select tp
case 3 : direct_message():endcase
endselect
endfunction
function direct_message()
netstring$ = net message string$()
set cursor 0,50
print netstring$
perform checklist for net players
for m = 1 to checklist quantity()
if m <> net message player from()
send net message string m, netstring$
endif
next m
endfunction
client code
Rem *** Include File: Client.dba ***
Rem Created: 30/04/2003 11:46:21 PM
Rem Included in Project: D:\DarkbasicPro\Projects\OnlineStuff\OnlineStuff.dbpro
sync on
set window on
dim mystring$(0)
perform checklist for net connections
nettotal = checklist quantity()
for i = 1 to nettotal
if checklist string$(i) = "Internet TCP/IP Connection For DirectPlay" then netsel=i
next a
add$ = "xx"
set net connection netsel,add$
perform checklist for net sessions
game = 1
join net game game, "MyNameHere"
do
sync
send_new_message()
get_new_message()
loop
function send_new_message()
if inkey$() > ""
mystring$(0) = mystring$(0) + inkey$()
endif
print mystring$(0)
wait 50
set cursor 0,0
if returnkey() = 1 then mymessage$ = mystring$(0) : mystring$(0) = ""
send net message string 1,mymessage$ : mymessage$=""
endfunction
function get_new_message()
get net message
if net message type() = 3
newmessage$ = net message string$()
print newmessage()
endif
endfunction