'Messages which we transfer of importance.
'[Connection Successful]
'[OK]
'[ERROR]
CONST DefaultPort$
= "7200" CONST True
= -1, False
= 0
Client = ConnectAsClient(DefaultPort, "localhost")
Send Client, junk$, False
Receive Client, what$
count = count + 1
temp
= _OPENCLIENT("TCP/IP:" + Port$
+ ":" + IP$
) 'attempt to join as client IF Verbose
THEN PRINT "Cannot connect to Host. Terminating program." ConnectAsClient = temp
SUB Send
(Who
, What$
, GetConfirmation
) attempt = attempt + 1
IF GetConfirmation
= False
THEN l
= -l
PUT #Who
, , l
'send the length PUT #Who
, , What$
'send the data l = CheckSum(What$) 'send a checksum to make certain the data we sent was recieved properly
count = count + 1
IF a$
<> "" THEN result$
= result$
+ a$
IF count
> 50 THEN result$
= "[ERROR]" IF Verbose
THEN PRINT "Error sending data. Trying again ("; attempt;
" of 5)." IF Verbose
THEN PRINT "Cannot Send Data. Terminating connection.]"
IF a$
<> "" THEN What$
= What$
+ a$
IF l
> 0 THEN 'the sender wants confirmation that the data received matches what we sent. count = 0
count = count + 1
IF a$
<> "" THEN What$
= What$
+ a$
IF count
> 30 THEN 'If we can't get the last 4 bytes in 3 seconds, we probably screwed up somewhere. 'Send a failure notice back to the user. We can't verify the data without a checksum, and that's
'what the last 4 bytes should be.
Send Who, "[ERROR]", False
What$ = "" 'don't return any value for what$. It wasn't properly received.
'at this point, we should have the data and the 4 digit checksum.
IF c
= CheckSum
(What$
) THEN 'we can confirm it. Send Who, "[OK]", False 'let them know we got the proper data
Send Who, "[ERROR]", False 'let them know we got the proper data
What$ = ""
'And if we've fallen through all the possible IF conditions, we're done!
CheckSum
= CheckSum
+ ASC(What$
, i
)