hey there
I'm learning how to program a multiplayer/chat function in Hands ON Dark Basic Vol.2 right now
Setting up a TCP/IP connection works well but recieved messages arent displayed immediately after sending.
Only after the reciepient sends a new message to the other player, then the recieved message prompts.
The way the code looks like and so far i understand it, i did expect it to be displayed for the reciepient immediately the message has been sent.
To me as a beginner the code seems so pretty clear and logical
as well it isnt explained more in this book.
So i have to ask : is this the only way how a "chat" can be made
in dbpro? Or do i have to program it in another way?
Have to say: i use the IP: 127.0.0.1 to get access to the "host" on my own pc. (cant imagine but maybe thats the reason?)
so may i please you for help any advices or maybe tuts ?
(because i didnt found any else nowhere about programing a chat?
and i'm out of any idea how to change it)
previosly so many thx for your effords
hope to read you soon ]
Here's the code:
[Rem ***** Main Source File *****
#constant host 1
#constant client 2
set window on
set window size 500,900
set window position 0,0
set window title "host"
r = establishconnection()
rem *** send and recieve messages ***
do
rem *** sendmessages ***
input "choose number of player to recieve message ",playerno
input "enter your message ",mes$
send net message string playerno,mes$
rem *** display any recieved messages ***
get net message
while net message exists()
print net message string$()
get net message
endwhile
loop
end
function establishconnection()
tcpipno = gettcpipnumber()
ipadress$ = getipadress$()
rem *** select tcp/ip connection ***
set net connection tcpipno,ipadress$
option = hostorclient()
if option = host
rem *** host program ***
input "Enter the name you wish to use : ",name$
input "Enter maximum users : ",max
input "Enter session name : ",session$
create net game session$,name$,max,1
else
listnetsessions()
session = getsessiontojoin()
input "Enter the name you wish to use : ",name$
join net game session,name$
listplayerdetails()
endif
endfunction option
function gettcpipnumber()
result = 0
perform checklist for net connections
for c = 1 to checklist quantity()
if left$(checklist string$(c),8) = "Internet"
result = c
endif
next c
if result = 0
print "no connection available. press any key"
wait key
end
endif
endfunction result
function listnetsessions()
print "sessions available : "
perform checklist for net sessions
for c = 1 to checklist quantity()
print c,". ",checklist string$(c)
next c
print "list complete"
endfunction
function listplayerdetails()
print "players in session "
perform checklist for net players
for c = 1 to checklist quantity()
print c,"name : ",checklist string$(c),"local ID : ",checklist value a(c),"universal ID : ",checklist value b(c),"me ? : ",checklist value c(c),"host ? : ",checklist value d(c)
next c
endfunction
function hostorclient()
print "choose from the following options : "
print "1 _ host a new session"
print "2 - join an existing session"
input "enter option : ",option
while option < 1 or option >2
print "enter 1 or 2"
input "enter option : ",option
endwhile
endfunction option
function getipadress$()
input "enter the IP of the host machine : ",ipadress$
endfunction ipadress$
function getsessiontojoin()
input "enter session you wish to join : ",session
while session < 1
print "enter the session number from the list given"
input "enter option : ",session$
endwhile
endfunction session