this is some code that ianm wrote for me ages agoi changed it and now it doesnt work. and i cant see why
This is the Host which creates a game called Chat and your player name is Server and there is a maximum of 2 players on the 127.0.0.1 address. This works fine. Ready for connections and sends packets fine.
IsServer$ = "y" : IP$ ="127.0.0.1"
sync on : sync rate 0 : cls
perform checklist for net connections : Connection=SearchChecklist("TCP/IP") : if Connection = 0 then Abort("No TCP/IP connection found");
set net connection Connection, IP$
if lower$(IsServer$) = "y"
create net game "Chat", "Server", 8
print "Ready for connections"
else
perform checklist for net sessions
Session=SearchChecklist("Chat")
if Session = 0 then Abort("Cannot locate Chat on the server")
print "Joining..."
sync
join net game Session, "Client"
print "Connected"
endif
sync
` repeat until f12 is pressed
do
`collect data
x#=111
y#=222
z#=333
`compile and transmit all packets
send net message string 0,str$(x#)+"|"+str$(y#)+"|"+str$(z#)
`recieve all packets
get net message
select net message type()
case 3
Datapack$=net message string$()
`decode packet string
pl#=len(datapack$)
for value=1 to pl#
cr$=mid$(datapack$,value)
if cr$="|" then tv#=1
vp$=vp$+cr$
if tv#=1
if dw#=1 then rx#=val(vp$)
if dw#=2 then ry#=val(vp$)
if dw#=3 then rz#=val(vp$)
tv#=0
vp$=""
cr$=""
dw#=dw#+1
endif
next t
endcase
endselect
set cursor 0,0
print "sending packet",str$(x#)+"|"+str$(y#)+"|"+str$(z#)
print "recieved x packet",rx#
print "recieved y packet",ry#
print "recieved z packet",rz#
loop
end
`Search the checklist for a specific search string
function SearchChecklist(Search as string)
local i as integer
local result as integer
result=0
for i=1 to checklist quantity()
if SearchString( checklist string$(i), Search ) then exitfunction i
next i
endfunction result
` Search a string for a specific search string
function SearchString(Source as string, Search as string)
local result as integer
local r as integer
local s as string
result=0
r=len(Source)
while r >= len(Search)
s=left$(right$(Source,r), len(Search))
if s = Search then exitfunction 1
dec r
endwhile
endfunction result
function Abort(prompt as string)
print prompt
sync
sync
wait key
end
endfunction
This is the Client which looks for a game called Chat and your player name is Client and you fill up the maximum of 2 players on the 127.0.0.1 address. This doesnt work. Says it "Cannot locate Chat on the server". Cant see whats wrong.
IsServer$ = "n" : IP$ ="127.0.0.1"
sync on : sync rate 0 : cls
perform checklist for net connections : Connection=SearchChecklist("TCP/IP") : if Connection = 0 then Abort("No TCP/IP connection found");
set net connection Connection, IP$
if lower$(IsServer$) = "y"
create net game "Chat", "Server", 2
print "Ready for connections"
else
perform checklist for net sessions
Session=SearchChecklist("Chat")
if Session = 0 then Abort("Cannot locate Chat on the server")
print "Joining..."
sync
join net game Session, "Client"
print "Connected"
endif
sync
` repeat until f12 is pressed
do
`collect data
x#=111
y#=222
z#=333
`compile and transmit all packets
send net message string 0,str$(x#)+"|"+str$(y#)+"|"+str$(z#)
`recieve all packets
get net message
select net message type()
case 3
Datapack$=net message string$()
`decode packet string
pl#=len(datapack$)
for value=1 to pl#
cr$=mid$(datapack$,value)
if cr$="|" then tv#=1
vp$=vp$+cr$
if tv#=1
if dw#=1 then rx#=val(vp$)
if dw#=2 then ry#=val(vp$)
if dw#=3 then rz#=val(vp$)
tv#=0
vp$=""
cr$=""
dw#=dw#+1
endif
next t
endcase
endselect
print "sending packet",str$(x#)+"|"+str$(y#)+"|"+str$(z#)
print "recieved x packet",x#
print "recieved y packet",y#
print "recieved z packet",z#
loop
end
`Search the checklist for a specific search string
function SearchChecklist(Search as string)
local i as integer
local result as integer
result=0
for i=1 to checklist quantity()
if SearchString( checklist string$(i), Search ) then exitfunction i
next i
endfunction result
` Search a string for a specific search string
function SearchString(Source as string, Search as string)
local result as integer
local r as integer
local s as string
result=0
r=len(Source)
while r >= len(Search)
s=left$(right$(Source,r), len(Search))
if s = Search then exitfunction 1
dec r
endwhile
endfunction result
function Abort(prompt as string)
print prompt
sync
sync
wait key
end
endfunction
soooo.....
wadoidowidis
Reset