10 T$="":IN$="":S%=SELECT("bluetooth","server","client","exit")
20 IF S%=2 THEN END
30 IF S%=0 THEN GOTO 50
40 IF S%=1 THEN GOTO 100
50 REM server
60 T$=T$+BTSH$("server","")
70 MM%=MESSAGEFORM("bluetooth","send","disconnect","server",T$)
80 IF MM%=-1 THEN GOTO 290
90 GOSUB 320:GOTO 60
100 REM clients
110 DIM BUF$(65536):N%=0
120 A$=BTSH$("clients","search")
130 IF A$="" THEN GOTO 170
140 BUF$(N%)=A$:N%=N%+1
150 A$=BTSH$("clients","")
160 GOTO 130
170 IF N%=0 THEN MM%=MESSAGEFORM("bluetooth","back","back","","devices not found!"):GOTO 10
180 DIM C$(N%)
190 FOR I%=0 TO N%-1
200 C$(I%)=BUF$(I%)
210 NEXT I%
220 MC%=CHOICEFORM("bluetooth","ok","disconnect","choose device:",C$)
230 IF MC%=-1 THEN GOTO 290
240 REM client
250 T$=T$+BTSH$("client",STR$(MC%))
260 MM%=MESSAGEFORM("bluetooth","send","back","client",T$)
270 IF MM%=-1 THEN GOTO 220
280 GOSUB 320:GOTO 250
290 REM disconnect
300 A$=BTSH$("disconnect","")
310 GOTO 10
320 REM send
330 ME%=EDITFORM("bluetooth","send!","back","send:",IN$,1000,0)
340 IF ME%=-1 THEN RETURN
350 T$=T$+BTSH$("send",IN$)
360 RETURN
