Problem with SendNetworkString and ReceiveNetworkData

Just starting out? Need help? Post your questions and find answers here.
TimeSurfer
User
User
Posts: 22
Joined: Wed Jan 23, 2008 6:58 am

Problem with SendNetworkString and ReceiveNetworkData

Post by TimeSurfer »

Im having a problem using RecieveNetworkData on the serverside [so far] I send a string from the client via SendNetworkString and when i try to retrieve it using ReceiveNetworkData on the serverside it comes out all garbled except the last character. [basically it looks like null spaces to me or invalid chars cause its just a box lol] Im still new to pb too so this is a bit frustrating. I'm using pb4. [BTW the network client/server example in the pb4 help doc don't work either, i get the same effect]

Can anyone help me? I'm really confused.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

are you using unicode strings to be send over the network?
Tranquil
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

That is what I thought too!

Post some code for a test. Use the {code} {/code} commands (use [ for { and ] for } ) or click the Code button near the top white line and click it again when you have pasted your code. :D

We can see whats going on!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
TimeSurfer
User
User
Posts: 22
Joined: Wed Jan 23, 2008 6:58 am

Post by TimeSurfer »

i found a way around that issue using a combination of peeks and pokes but now i have run into another problem.

my server code seems to work fine. now its this thats being a pain, it connects, sends the string but its not recieving the string thats sent back and ive checked the connectionid's over and over in both the server and client. im completely lost. --note; the code will be adapted for a dll so u might see some commented out procedurereturns.

Code: Select all

If InitNetwork() = 0
  ;ProcedureReturn "Unable to initialize the network."
EndIf

Procedure.s ReceiveNetworkString(ConnectionID.l) 
  Length.l = ReceiveNetworkData(ConnectionID, *Buffered, 1000) 
  Text$ = PeekS(*Buffered, Length)
  ProcedureReturn Text$ 
EndProcedure

*Buffered = AllocateMemory(1000)
ConnectionID = OpenNetworkConnection("127.0.0.1", 6832)
If ConnectionID
  stext.s = "regkey"
  PokeS(*Buffered,stext,1000)
  SendNetworkData(ConnectionID, *Buffered, 1000)
  Repeat
    CEvent = NetworkClientEvent(ConnectionID)
    If CEvent
      ;do something
      Select CEvent
        Case 1
          MessageRequester("PureBasic - Server", "Server "+Str(ConnectionID)+" has send a packet !", 0)
          MessageRequester("Info", ReceiveNetworkString(ConnectionID), 0)
          If Text$ = "Invalid registration key"
            CloseNetworkConnection(ConnectionID)
            End
          EndIf
      EndSelect
    EndIf
  Until Quit = 1
EndIf
End
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

You have to clear the buffer and PARSE the buffer to sort the strings. Well you will eventually... you'll see.

Are you sending to the correct port?
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

Shouldn't "Case 1" be "Case 2"?
TimeSurfer
User
User
Posts: 22
Joined: Wed Jan 23, 2008 6:58 am

Post by TimeSurfer »

thanks guys, got it working lol my problem was with my if statements. But you were right too heathen case 1 should be case 2.
Post Reply