Author Topic: Unable to send data from one QB64 program to another QB64 program  (Read 2362 times)

0 Members and 1 Guest are viewing this topic.

Offline KrashSmith81

  • Newbie
  • Posts: 2
    • View Profile
Hi, I'm new to the forums here. I'm currently trying to utilize Qb64 to make my own little mud. It won't be anything grand, but hopefully decent when all is said and done.  I can get the client I made to connect to the server I made, however, I can't seem to get the test string I send from Server to Client to say "Welcome to Euphoria" on the screen of the client.

Here is the server source code:
Code: [Select]
'Euphoria - server code for my first mud!
'by KrashSmith81@gmail.com, Krash Smith

cls

main:
server = _OPENHOST("TCP/IP:1981")
PRINT "Waiting for connection..."

DO
    HOST = _OPENCONNECTION(server)
LOOP UNTIL HOST <> 0

print
PRINT "A player has joined!"
SLEEP 2

'print #host, "Welcome to Euphoria!"

currMsg$ = "Welcome to Euphoria!"


PUT #host, , currMsg$


close #host


And here is the client code:

Code: [Select]

'Euphoria - client code for my first mud!
'by KrashSmith81@gmail.com, Krash Smith

cls

main:

client2server = _OPENCLIENT("TCP/IP:1981:127.0.0.1")
PRINT "Attempting connection to Euphoria Server..."

if client2Server = 0 then
print "Connection Failed!"
end
end if

print
PRINT "Connection Successful!"
SLEEP 2

'input #client2Server, serverMsg$


GET #client2server, ,serverMsg$

print serverMsg$


close client2Server


I've tried adding an amperstand to the end of the handle, and switching which handle I use, and I know I need some command to make sure the data is sent before I read it. I've tried using INPUT #(handle name), and PRINT #(handle name), also when that didn't work I tried using PUT and GET. The server says, "A player has joined", like it should, and the client says "Connection Successful" like it should. However, the message from the client to the server ("Welcome to Euphoria"), is never displayed. I know making my own mud will require a lot more than this, but right now I'm just trying to nail down the basic framework. Thanks in advance for any help you can provide, and should this little dream of mine ever come to fruition, anyone who helped me make it happen will be given GOD status on my MUD, lol :)

Thanks again for any and all help,

Krash
« Last Edit: May 29, 2019, 11:43:10 pm by KrashSmith81 »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Unable to send data from one QB64 program to another QB64 program
« Reply #1 on: May 30, 2019, 09:43:51 am »
Hi. Maybe something from this thread help you: https://www.qb64.org/forum/index.php?topic=779.0

FellippeHeitor

  • Guest
Re: Unable to send data from one QB64 program to another QB64 program
« Reply #2 on: May 30, 2019, 10:25:58 am »
You should GET data from the server until an *end message* you define yourself is received. Since this is your own server/client code, you can define anything as an *end message*. In this example I've changed your code to use <END> as an end marker, so the client GETs data until that is received, then it gets removed from the message before printing:

Server:
Code: QB64: [Select]
  1. 'Euphoria - server code for my first mud!
  2. 'by KrashSmith81@gmail.com, Krash Smith
  3.  
  4.  
  5. main:
  6. server = _OPENHOST("TCP/IP:1981")
  7. PRINT "Waiting for connection..."
  8.  
  9.     HOST = _OPENCONNECTION(server)
  10. LOOP UNTIL HOST <> 0
  11.  
  12. PRINT "A player has joined!"
  13.  
  14. 'print #host, "Welcome to Euphoria!"
  15.  
  16. currMsg$ = "Welcome to Euphoria!<END>"
  17.  
  18.  
  19. PUT #HOST, , currMsg$
  20.  
  21.  
  22. CLOSE #HOST
  23.  

Client:
Code: QB64: [Select]
  1. 'Euphoria - client code for my first mud!
  2. 'by KrashSmith81@gmail.com, Krash Smith
  3.  
  4.  
  5. main:
  6.  
  7. client2server = _OPENCLIENT("TCP/IP:1981:127.0.0.1")
  8. PRINT "Attempting connection to Euphoria Server..."
  9.  
  10. IF client2server = 0 THEN
  11.     PRINT "Connection Failed!"
  12.     END
  13.  
  14. PRINT "Connection Successful!"
  15.  
  16. 'input #client2Server, serverMsg$
  17.  
  18.  
  19. serverMsg$ = ""
  20.     GET #client2server, , serverData$
  21.     serverMsg$ = serverMsg$ + serverData$
  22.     IF RIGHT$(serverMsg$, 5) = "<END>" THEN EXIT DO
  23.  
  24. serverMsg$ = LEFT$(serverMsg$, LEN(serverMsg$) - 5)
  25.  
  26. PRINT serverMsg$
  27.  
  28.  
  29. CLOSE client2server
  30.  

Offline KrashSmith81

  • Newbie
  • Posts: 2
    • View Profile
Re: Unable to send data from one QB64 program to another QB64 program
« Reply #3 on: May 31, 2019, 03:53:20 pm »
Thanks to you both for your help, I'll be looking into it and I'll letcha know how things turned out.


Thanks again so much, for years I've entertained the notion of adding networking elements to my little text based adv. game/rpg's, but finally I think it's going to happen. :)