Beginner Network Problems

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by andyboy_uk.

Hi there,

We are trying to put together a simple client server program using pb, the server basically listens and displays any string that the client sends to it. We are using this on a single machine.

But as soon as we send data from the client, the server crashes and says that the memory pointer specified is of NULL length,

any suggestions

The code for the server is below..

Code: Select all

OpenConsole()

systemOn = 1

result = InitNetwork()

ClearConsole()

server = CreateNetworkServer(60001)

prt = Print("Server Created and listening")

*DataBuffer = AllocateMemory(0, 1024, 0)

While systemon = 1 
  result = NetworkServerEvent()
  Select result
    Case 0
    
    Case 1  ; -- New client on server -- 
      
    Case 2  ; -- Raw Data --
      input = ReceiveNetworkData(NetworkClientID(), *DataBuffer, DataBufferLength)

      Print(Chr(13) + Chr(10) + Str(*DataBuffer))
   Case 3  ; -- File Recd --
      
    Case 4  ; -- Disconnection --
    
    Default
  EndSelect
  

Wend

End


and the client is below

Code: Select all


OpenConsole()

systemOn = 1

result = InitNetwork()

ClearConsole()

ClientID = OpenNetworkConnection("127.0.0.1", 60001)

If clientID = 0 
  Print("ERROR CONNECTING")
  
Else


  Print("Client Created and ready to send ")
  Print(Chr(13) + Chr(10))



  While systemOn = 1
    Print("> ")
    strToSend$ = Input()

    SendNetworkString(clientID, strToSend$)
  Wend

EndIf


End


Thanks in advance,

Andy


Andy Driskell
andyboy_uk@http://www.com on MSN Messenger
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Change server to this:

Code: Select all

OpenConsole()
systemOn = 1
result = InitNetwork()
ClearConsole()
server = CreateNetworkServer(60001)
prt = Print("Server Created and listening")

*DataBuffer = AllocateMemory(0, 1024, 0)
databufferlength=1024  ; ")  ;
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

You might want to check out source to PBChat on the Resources Site.
It is a fully functional client/server chat program. :)


----------
Visit the PB Resources Site at http://www.reelmediaproductions.com/pb
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by andyboy_uk.

Thanks for all you're help Paul, I will give that a go now. :), also I will have a look at PBChat although, what this is goign to do is just allow us to run a program or a certain script on a remote server.

Thanks again,

andy


Andy Driskell
andyboy_uk@http://www.com on MSN Messenger
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by andyboy_uk.

THat worked a treat.. Im really starting to like this language..

What we are going to attempt now is to send a string from a com Object (written in VB) to the server on that port and see if PB can pick up the string.

:)

Thanks for you're help Paul,




Andy Driskell
andyboy_uk@http://www.com on MSN Messenger
Post Reply