Page 1 of 1

Help with ReceiveNetworkData()

Posted: Sun Feb 01, 2004 4:06 am
by phunk
I can't figure out this error... could someone help me?

Code: Select all

If OpenConsole()
  If InitNetwork() = 0
    End
  EndIf
  
  PrintN("TClient v0.1 by phunk")
  PrintN("")
  Print("What server would you like to connect to? ")
  server$ = Input()
  PrintN("")
  Print("What port would you like to connect to? ")
  port$ = Input()
  
  ClearConsole()
  PrintN("Connecting to "+server$+", port "+port$+"...")
  telnet = OpenNetworkConnection(server$,Val(port$))
  
  If telnet
    PrintN("Successfully connected!")
    Repeat
      rT = NetworkClientEvent(telnet)
      If rT = 2
        ; Error is here...
        If ReceiveNetworkData(telnet, TelnetBuffer, 4096)
        ; The error is: The specified memory buffer is null.
          PrintN("Read: "+PeekS(TelnetBuffer)+"")
        Endif
      EndIf
    Until Inkey() = "q"
  Else
    PrintN("Could not connect.")
  EndIf
  
EndIf
If you could help, thanks a lot. :P

Posted: Sun Feb 01, 2004 7:12 pm
by Proteus
You should allocate the memory first.

Code: Select all

If ReceiveNetworkData(telnet, TelnetBuffer, 4096)
Becomes

Code: Select all

*TelnetBuffer = AllocateMemory(0, 4096)
If ReceiveNetworkData(telnet, *TelnetBuffer, 4096)