Winsock in eVB
I'm porting a winsock application in VB6 to eVB. However, I'm having a serious problem with winsock in eVB. I get no errors or anything-it seems to be working correctly, but it does not. I will explain:
In normal VB6, I send a login command to a server and it responds with 10 bytes of data. In the dataarrival event, it says bytestotal is 10, and len(strData) yields also 10. This works fine. The rest of the login sequence works perfectly.
In eVB, with *identical code* with the VB6 version, I send the login command and it responds just like vb6. Bytestotal is 10, but len(strData) is 4! Some -of the packet is missing! My login sequence will not complete. I cannot figure out how to make this work. I have tried everything I can think of and I am going insane. Can anyone help?
I tried that c++ dll winsock wrapper called cesockets or whatever, and with similar results as normal eVB. It returns 10 bytestotal but len(strData) returns 5. What the heck is going on?
It's imperative that I get this working. I don't have access to the server source so I cannot modify this. I will reiterate: the code in eVB and VB6 is now identical. It works in VB6 and not eVB. C++ DLL doesnt work either so please no "vb sucks" flames.
Has anyone experienced similar problems? Workarounds? or I would like even any sort of info on the eVB winsock control, or links to other c++ wrappers. I really need to get this to work and I can't see a solution.
Can you help me?
Thanks,
Dogpoop on a soda can.
VB isn't my thing at all (never touch the stuff), but UNICODE may be an issue. The eVB strings should be unicode, so if you are reading 10 ascii chars into a unicode string there may be problems.
Dan East
Of course, minutes after I post, I find out the reason. For those that are curious:
It is a known MS bug that the windows ce winsock control (and I think the winsock.dll also) will have problems receiving binary data. It may not receive all of it; it stops at the first ascii value of 0. This was my problem.
Even though I know what my problem is, I still need to fix it. I am wondering, is it possible to receive it as a byte array and then put it back together as a string?
dogpoop wrote:
I tried that c++ dll winsock wrapper called cesockets or whatever, and with similar results as normal eVB. It returns 10 bytestotal but len(strData) returns 5. What the heck is going on?
I'm not that familiar with winsock or eVB, but here's my wild guess.
From the GetData help page:
"If you receive data as a string, the bytes are converted from ASCII characters to Unicode characters."
It takes two bytes to store one Unicode character. So, you've got 5 characters in the string, which takes 10 bytes.
Pam
Oops, Dan beat me to it.
I see your point with the unicode thing, but if the VB6 version is returning 10 characters, then the eVB version, (if it is working properly) should return 10 characters as well but 20 bytes. Anyway, doesn't matter because it was the error described in my above post. Now I have run into what I think is a dead end. Maybe Dan can help me since he knows c++.
Does C++ have the "fragmentation" bug? In eVB, if I send the string "hello" it will actually send 2 strings of "h" and then "ello" to the server. Because of this (I think), I cannot proceed with my login sequence. Its an acknowledged bug but of course no fix :(. Dan, or anyone else, does this occur in c++ for wince?
Thanks again,
-Dogpoop on celery.
Heres the dea you were right about the winsock control and packet loss the control just suck ass for eVB.
www.devbuzz.com has an article about transferring with NO packet loss using a dll the guy wrote in c with winsock.dll for vb.
RWGast, is it the cesockets dll?
I find it weird to call the receive function rather than having an event raised...do I just set a loop with doevents and call the receive?
Well, there is not "fragmentation bug" with eVC++. When using sockets you have to keep in mind that the TCP protocol will break your data up into whatever individual chunks it deems necessary. I think it usually breaks them up at a few hundred bytes. However, you should not assume that your chunk of data will make it through in one piece. If your protocol specifies a fixed length (ie you are expecting 10 chars), then just keep reading until you get all 10 chars or until you reach a realistic time-out threshold you specify. If you do not know the size of the data you are going to send / receive, then use a simple protocol such as sending the size of the data that is to come, followed by the actual data. You can write a simple subroutine that you pass a buffer, a socket handle, and a length to. It will then return once it has filled the buffer with the target amount of data or a timeout occurred. Even with the "fragmentation bug" your code will still work. I have written TCP/IP code that worked fine on Win NT/ME, etc, but I had to tweak on CE because my packets were getting chopped up into smaller pieces. The reason was my socket routines were not flexible enough to handle my data being broken up into multiple pieces. When you start talking about irSock and wireless networking the issue is even greater, because the transport medium for the data is very unreliable, and the protocol may have to revert to extremely small packets. Same thing if you develop your code while testing over Ethernet and then try it over a slow dialup connection.
Dan East
Well I am in a very difficult situation. The "fragmentation" bug is extremely annoying because I need to send 1 word to start the login sequence. If it sends the first character of this word, and then the rest of the word on the 2nd transmission, it simply won't work. The server I am connecting to is not mine nor do I have source to it etc. I could use the cesockets.dll, except that it appears I need to receive data in a byte array. I cannot figure out how to do this or even if its possible with the dll.
So Im stuck 2 ways:
1)I can use the winsock control (which I greatly prefer), but the fragmentation bug keeps me from logging in properly.
2)I can use the cesockets.dll and while I can send the info properly (I think), I cannot receive data properly (in a byte array) to process it. If I receive it as a string I still have the bug which stops the string at the first ascii 0 character.
At this point, my only hope is to figure out how to use cesockets with byte arrays.
Okay, you're talking about sending. I very seriously doubt the server is expecting a unicode string, which is what you are trying to send. Try creating a Byte array, set each char one at a time with the numerical ascii values, and send it. You may need to stick a null terminator byte on the end if the server is expecting it.
Dan East
Dan that isnt the probelm

vb does auto formating of its strings no need for a null terminator. MS has admited there control is shit. The guy ran benchmarks and it took 512ms to send his data using the vb control his C dll took 2ms or something. The control looses data sending and reciving its full of alot of bugs

. I would recommend this person write his own winsock functions in C using winsock.h or get the dll file i mentioned at
www.devbuzz.com, if you search that site for winsock youll find the article im reffering too it is very intresting.
yep rwgast, I did read the article and got the cesockets.dll from it. I need to receive in binary mode though as it is still plagued by the "binary bug". AFAICT (as far as I can tell) it only sends strings. I tried to do what Dan said by splitting it into a byte array but I was getting errors and so I gave up for the evening

I will have a fresh look at it tomorrow but things don't look to good

You would think MS would have caught these completely obvious bugs before they released it. Anyone know when the next eVB (or winsock control) is coming out?
BTW thanks for all your help and insight guys...I am confident I can do this eventually, Im just not sure how.
You would think wouldnt you. I was pretty disapointed with vb's winsock support you try using strait winsock api in vb yet?
That Anonymous was of course me above, didnt login sorry. I read somewhere that you can't use Winsock API from eVB. I will nonetheless give it a try.
I found an activeX winsock control from ip works that looks good. Its based on the winsock API. Only problem is I can't figure out how to make the program run in the emulator. When I try to run it says it cant create the activex component. I guess I need to register it somehow but I don't know how to do this. I'm new to pocket pc and i dont have a device yet (only emulator). Does someone know how to do this?
in the palm300\windows dir there is a file called regservc or something like that just drop the component on top of it using file explorer or somthing along those lines.
ugggh I have such bad luck- error 7b when it tries to register. I cannot find a regedit type program anywhere either to add it manually.
Dan East, I noticed your dexterous file explorer has full registry editor. Is there a way to run it through an emulator?
When I try to run the installer it says windows ce services not found and it exits.
To edit the registry use the remote registry editor that's in eVC. It's under the tools menu. I believe you have to set up the emulator as a target, but I can't remember how. I'm pretty sure it's possible, though.
Of course, this is all futile if there isn't an emulator version of the ActiveX control as part of the package. For any other program, this would be quite unlikely, but ActiveX controls are mostly used directly by developers, and they would have a high likelyhood of needing an emulator version.
Error 7b happens when you try to register a compent compiled for a proccesor other than what you are using so u tried to register the arm, mip, sh3 version of the control but u need to register the x86em version.
I seem to be getting one strange problem after another.
I was trying to register the x86emu version, but the regsvrce program loads up the old pocketpc2000 emulator and not the 2002 emulator. It then says error 7b. Any way to change it to the pocketpc 2002 emulator?
Found the problem- it will not load the control in PPC2k2, only in PPC2K. I was able to install it this way thru the control manager in the tools menu of eVB. Now I dont know what to do again...Anyone with PPC2k2 will not be able to use my program this way. ugh.
It doesn't sound like you need it now, but no, an x86 build of DEXplor is not available.
Dan East