Re: Banging my head against the wall - urgent help needed!
- From: "Bob Butler" <tiredofit@xxxxxxxxxxx>
- Date: Mon, 31 Jul 2006 15:34:06 -0700
"Steven Davidson" <steve.davidson@xxxxxxxxxxxxxx> wrote in message
news:%238Fa55OtGHA.1224@xxxxxxxxxxxxxxxxxxxx
Here's how I've got it coded: (BTW, the code I am using, at least for
retrieving the data from the Winsock control, were all lifted out of a
technet article...which, although I was able to find it yesterday, I
am no longer able to find today...gotta love it!)
I've got just a single Form so everything in the general section is
declared private
I've copied and pasted the CopyMemory function from the API Viewer
applet that comes with VB 6.0
I've defined a number of user-defined types
Private Type PLAYERINFO
id as integer
pname as string * 40
I did not look over the code in detail bit one possible problem I see there
is that VB inserts padding to make some things align properly on a
double-word boundary. Since an Integer is 2 bytes there will be a pair of
bytes in between those two entries in memory that are "extra". The same
thing occurs elsewhere in your UDTs. If you have control over both ends of
the connection then the simplest option is to try changing all "as integer"
to "as long" so that everything lines up on the dword boundaries and no
padding gets inserted. If you don't have control of both ends then you may
need to move things into the various fields individually. If you are going
VB to VB and using LenB and the moon is in the right phase then this may not
be causing a problem since you may just be copying padding back and forth.
<cut>
There are times when I can compile the programs (SERVER.EXE and
CLIENT.EXE) and everything works fine. Then I make a tiny little
change to just the UDTs (for instance, I'll increase pname from 40
characters to 42 characters, making sure to make the change in both
programs), and BAM!, the program crashes.
Another possible issue is that network packets can be broken up and/or
appended together during transmission. If your UDT length is just under the
size that the network decides is the splitting point then the data will go
through in one piece. if you add a couple of bytes it may go over the limit
and get split into 2 or more pieces and show up as 2 DataArrival events. If
your DATAGRAM is smaller than the maximum packet size and you send several
one after the other the network will append them one after each other and
then send as few packets as it can to send all the data. It will be in
order (assuming tcp/ip for all of this) but the number of DataArrival events
on the receiving end will not always match the number of Send methods called
by the sender.
If you haven't coded for these possibilities then you will get garbage. You
have to know how many bytes you expect and how many were received and either
wait for the next event or put the extra aside for the next pass.
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
.
- References:
- Banging my head against the wall - urgent help needed!
- From: Steven Davidson
- Re: Banging my head against the wall - urgent help needed!
- From: Bob Butler
- Re: Banging my head against the wall - urgent help needed!
- From: Steven Davidson
- Banging my head against the wall - urgent help needed!
- Prev by Date: Re: Banging my head against the wall - urgent help needed!
- Next by Date: Re: WINAPI function for setting screen saver?
- Previous by thread: Re: Banging my head against the wall - urgent help needed!
- Next by thread: Re: Banging my head against the wall - urgent help needed!
- Index(es):
Relevant Pages
|