Help with ReceiveNetworkData()

Just starting out? Need help? Post your questions and find answers here.
phunk
New User
New User
Posts: 6
Joined: Sun Jan 18, 2004 8:17 am

Help with ReceiveNetworkData()

Post 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
Proteus
Enthusiast
Enthusiast
Posts: 113
Joined: Wed Sep 17, 2003 8:04 pm
Location: The Netherlands

Post 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)
P4 2.4GHz, 256 MB, WinXP Pro, onboard video&audio.
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
Post Reply