Null Over Network?

Just starting out? Need help? Post your questions and find answers here.
RTmich
New User
New User
Posts: 2
Joined: Mon May 28, 2007 1:21 am

Null Over Network?

Post by RTmich »

Hi, new to PB and my problem is I'm trying to communicate with a server over the net, and need to send chr(0), or null. I've look at SendNetworkString;

Code: Select all

SendNetworkString(ConnID, chr(12) + chr(0) + chr(143))
A quick sniff shows its not communicating correctly because its sending everything except the null character.
I looked into SendNetworkData after I figured out chr(0) wouldn't send, but cant quit grasp it, or how I could use it to send packets like above. Could someone guide me through this please?
JCV
Enthusiast
Enthusiast
Posts: 580
Joined: Fri Jun 30, 2006 4:30 pm
Location: Philippines

Post by JCV »

you can use SendNetworkData

sample on my client emulator and poke it with zero.

Code: Select all

Procedure injectMapMark(id, clear, x, y, Red, Blue, Green)
  Protected pBufNew
  pBufNew = AllocateMemory(23)
  PokeW(pBufNew, $0144)
  PokeL(pBufNew+2, id)
  PokeL(pBufNew+6, clear)
  PokeL(pBufNew+10, x)
  PokeL(pBufNew+14, y)
  PokeC(pBufNew+18, 0) ; <--- zero
  PokeC(pBufNew+19, Green)
  PokeC(pBufNew+20, Blue)
  PokeC(pBufNew+21, Red)
  PokeC(pBufNew+22, 0) ; <--- terminating with zero
  SendNetworkData(Client, pBufNew, 23)
  FreeMemory(pBufNew)
EndProcedure

[Registered PB User since 2006]
[PureBasic 6.20][SpiderBasic 2.2]
[RP4 x64][Win 11 x64][Ubuntu x64]
RTmich
New User
New User
Posts: 2
Joined: Mon May 28, 2007 1:21 am

Post by RTmich »

Yea, I kinda figured that, and after that in depth explanation Ive spent the last couple hours sorting it out. Is there a way to append to the end of the block? Im keeping track of where Im writing using an integer that saves the last, makes a lengthy function to send a simple 60 character packet. . .
JCV
Enthusiast
Enthusiast
Posts: 580
Joined: Fri Jun 30, 2006 4:30 pm
Location: Philippines

Post by JCV »

Sorry I dont get you.
Try CopyMemory function.

[Registered PB User since 2006]
[PureBasic 6.20][SpiderBasic 2.2]
[RP4 x64][Win 11 x64][Ubuntu x64]
User avatar
manu
User
User
Posts: 32
Joined: Tue May 13, 2003 12:40 pm
Location: Germany
Contact:

SendNetworkString is for sending strings...

Post by manu »

RTmich, SendNetworkString is for sending strings. Strings are some characters terminated by a null character. This cannot be changed.
You really need to use SendNetworkData.
There are several ways to get the data in place in memory like you need it.
One way would be to Poke it to memory like in the other example.
Another way would be to make a structure and a variable of that type. Then assign the values to the fields of the structure and send the whole structure.
If it is 60 bytes of constant data, you could also use a DataSection and Data.b, so the data is already perfectly prepared and you only have to call SendNetworkData(id,?label_packet_start,?label_packet_end-?label_packet_start)

--manu
Post Reply