10-24-2022, 04:25 AM
It looks like you're trying to make an open host connection. Can I help?
Well, Halloween is coming, so forgive me for channeling Clippy. On second though, douse me with Holly water, and call the fire dept.
Anyway, compile both programs. Call the first one whatever you want, but name the second one Pete2.bas. Save and compile it as Pete2.exe before running the first (host) app, which SHELLs to Pete2.exe.
Host - This is where you will make input choices.
Now the client window where your choices will be displayed...
Pete
Well, Halloween is coming, so forgive me for channeling Clippy. On second though, douse me with Holly water, and call the fire dept.
Anyway, compile both programs. Call the first one whatever you want, but name the second one Pete2.bas. Save and compile it as Pete2.exe before running the first (host) app, which SHELLs to Pete2.exe.
Host - This is where you will make input choices.
Code: (Select All)
_SCREENMOVE 0, 0
WIDTH 60, 25
DO
CLS
DO UNTIL x
x = _OPENCLIENT("TCP/IP:1234:localhost")
IF x = 0 THEN
x = _OPENHOST("TCP/IP:1234")
a$ = "Opening as host."
ELSE
a$ = "Opening as client." ' Should not go here for this demo.
END IF
PRINT a$
LOOP
IF initiate = 0 THEN
SHELL _HIDE "start pete2.exe" ' Open the client window.
initiate = -1
END IF
' Send data
IF z = 0 THEN
DO
z = _OPENCONNECTION(x)
LOOP UNTIL z
PRINT "Connection established."
END IF
LOCATE 3, 1
INPUT "Input a number for letter of the alphabet 1, 2, or 3: "; choice
_KEYCLEAR
PUT #z, , choice
DO
GET #z, , a
LOOP UNTIL a = -1
PUT #z, , a
CLS
LOOP
Now the client window where your choices will be displayed...
Code: (Select All)
_SCREENMOVE 600, 0
WIDTH 50, 25
x = _OPENCLIENT("TCP/IP:1234:localhost")
PRINT "Opened as client.": PRINT
DO UNTIL x = 0 ' Prevents running if this app is opened without using host.
DO
_LIMIT 30
GET #x, , receive
LOOP UNTIL receive > 0
PRINT "You chose the letter: ";
SELECT CASE receive
CASE 1
PRINT "A"
CASE 2
PRINT "B"
CASE 3
PRINT "C"
CASE ELSE
PRINT "Wrong input!"
END SELECT
PRINT
task_complete = -1
PUT #x, , task_complete
LOOP
Pete