Page 1 of 1
Null Over Network?
Posted: Mon May 28, 2007 1:39 am
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?
Posted: Mon May 28, 2007 1:56 am
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
Posted: Mon May 28, 2007 5:20 am
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. . .
Posted: Mon May 28, 2007 5:48 am
by JCV
Sorry I dont get you.
Try CopyMemory function.
SendNetworkString is for sending strings...
Posted: Thu May 31, 2007 12:09 am
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