GetData does not receive the data

Posted on 2008-10-08
Last Modified: 2013-12-20
Ok, I needed a socket solution fast for testing my code in Navision (MS Dynamics NAV). So I thought I make a client with vbscript. Said and done, 5 minutes of googling and I found Gurgen Alaverdians MsWinsck wrapper (, also downloaded the latest VB6SP6 and got the latest MSwinsck (winsock control v6.01.9782). Now it works great as matter of starting my code (server) and connecting to it locally and/or from another machine as a client from my vbscript. However, when my server processes the message sent from client and replies back, the vbscript client, in fact is triggered by dataarrival event, and it shows the correct number of bytes, but when I try to get the string strData, it is empty, length 0. See code snippet.

I've tried and tried, I cannot find anyway to make it work. For now I've put a proxy in between so I can actually see the answer, but if someone could  help me find out whats wrong, it would be great. Could this be a bug in the control, or in Gurgens wrapper? 250p for helping me to make it bugfree.
Dim wsError, objWS

Dim result

sckClosed = 0

sckClosing = 8

sckConnected = 7

sckConnecting = 6

sckConnectionPending = 3

sckError = 9

sckHostResolved = 5

sckListening = 2

sckOpen = 1

sckResolvingHost = 4


sckTCPProtocol = 0

sckUDPProtocol = 1


server = "localhost"



Set objWS = WScript.CreateObject("WinsckW.WinSock", "objWS_")

objWS.Protocol = sckTCPProtocol

objWS.Connect server, 189




      Wscript.Sleep 50

      Timeout = Timeout + 1

      If Timeout > 40 then trapError

Loop Until objWS.State = 7 


Wscript.Echo "Connection with server is established!..." & vbCrLf


str = _

"<Orders>" & vbCrLf & _

"  <Order> " & vbCrLf & _

"    <Head>" & vbCrLf & _

"      <UserName>0000</UserName>" & vbCrLf & _

"      <TransactionType>10</TransactionType>" & vbCrLf & _

"      <Status>0</Status>" & vbCrLf & _

"      <OrderNumber>3547560</OrderNumber>" & vbCrLf & _

"      <CustomerOrderNumber />" & vbCrLf & _

"      <CustomerName />" & vbCrLf & _

"      <CustomerNumber />" & vbCrLf & _

"      <DeliviryDate>1900-01-01T00:00:00</DeliviryDate>" & vbCrLf & _

"      <OrderDate>1900-01-01T00:00:00</OrderDate>" & vbCrLf & _

"      <InsertDateTime>1900-01-01T00:00:00</InsertDateTime>" & vbCrLf & _

"      <NumberOfRows />" & vbCrLf & _

"      <Selected>false</Selected>" & vbCrLf & _

"      <CarrierNumber />" & vbCrLf & _

"      <OptionalVarchar0 />" & vbCrLf & _

"      <OptionalVarchar1 />" & vbCrLf & _

"      <OptionalVarchar2 />" & vbCrLf & _

"      <OptionalVarchar3 />" & vbCrLf & _

"      <OptionalVarchar4 />" & vbCrLf & _

"      <OptionalVarchar5 />" & vbCrLf & _

"      <OptionalVarchar6 />" & vbCrLf & _

"      <OptionalVarchar7 />" & vbCrLf & _

"      <OptionalVarchar8 />" & vbCrLf & _

"      <OptionalVarchar9 />" & vbCrLf & _

"      <OptionalDecimal0>-1</OptionalDecimal0>" & vbCrLf & _

"      <OptionalDecimal1>-1</OptionalDecimal1>" & vbCrLf & _

"      <OptionalDecimal2>-1</OptionalDecimal2>" & vbCrLf & _

"      <OptionalDecimal3>-1</OptionalDecimal3>" & vbCrLf & _

"      <OptionalDecimal4>-1</OptionalDecimal4>" & vbCrLf & _

"      <OptionalDateTime0>1900-01-01T00:00:00</OptionalDateTime0>" & vbCrLf & _

"      <OptionalDateTime1>1900-01-01T00:00:00</OptionalDateTime1>" & vbCrLf & _

"      <OptionalDateTime2>1900-01-01T00:00:00</OptionalDateTime2>" & vbCrLf & _

"      <OptionalDateTime3>1900-01-01T00:00:00</OptionalDateTime3>" & vbCrLf & _

"      <OptionalDateTime4>1900-01-01T00:00:00</OptionalDateTime4>" & vbCrLf & _

"    </Head>" & vbCrLf & _

"  </Order>" & vbCrLf & _



Wscript.Echo "Sending: data"

objWS.SendData str

Wscript.Sleep 1000


Sub objWS_Error(Number, Description, Scode, Source, HelpFile, HelpContext, CancelDisplay)

       wsError = "Error connecting... Number: " & Number & " Description: " & Description

End Sub


Sub trapError


     If not wsError = "" then 

           Wscript.Echo wsError

     Else: Wscript.Echo "Cannot Connect.. Unknown Error."

     End If




End Sub


Sub objWS_DataArrival(bytesTotal)

      objWS.GetData strData, vbString

      Wscript.Echo "Received " & bytesTotal & " bytes."

      Wscript.Echo strData

End Sub

Open in new window

Question by:moonlight
  • 7
  • 3
  • 2
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 22668967

Author Comment

ID: 22670586
It kinda exludes the wrapper as the problem then.
Could it be a bug in "winsock control" then not handling some kind of streams? What would be needed to make the same small application with the real winsock ? or some other alternative?

I'm just looking for easiest possible client sending and reading xml.

Author Comment

ID: 22677006
maybe I can use csocketmaster instead?
anyone able to compile the ocx?

Author Comment

ID: 22686024
Hello, I discovered I have problem running it on win server 2008 anyway, so even stronger motive to try out an alternative. Anyone able to compile the csocketmaster.ocx for me?
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 22687006
I haven't fired up my VB6 IDE in sooooo long.  (It's on my other slooooow computer).

I wonder if one of the many security fixes in windows has broken something.  =\

I'll fire up my old puter today and do some testing with some old code...

Expert Comment

ID: 22688442
Hi guys,
Frankly, not tested wrapper on Vista yet.. Would do.. as soon as time permitted

Gurgen Alaverdian
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline


Author Comment

ID: 22689038
*awed* Gurgen, you are here! Thanks so much. *bow* I'm trying it on a win server 2008 x64, so I guess something needs to be changed in order to make it work. Any idea about the empty getdata problem? I think that is due to the mswinsck.ocx though.

 Idle_Mind, thanks, I tried compiling csocketmaster on visual studio 2005 but it gave so many conversion warning/errors so I left that option unexplored.

Accepted Solution

4u2ges earned 250 total points
ID: 22689148
Well, I can confirm that the wrapper works fine on Vista and Win2008 x32.

moonlight, I'm a bit confused with the code you have posted. I assume it's a client routine. But then what are you getting  with DataArrival sub there? Can you post the server portion of the code? Does it send something back to the client after receiving original data? In any case, I see that you would NOT get anything with the way strData is bound. Try explicitly assigning the arriving data to a variable:

strData = objWS.GetData (strData)

Author Comment

ID: 22690985
Thanks, you were right, now it works on x32 now :)  I had seen getdata called both ways and thought they were equal..

I still have problem in x64 though, here are my observations:

If I try telnetting, both in x32 and x64 the server listens, I found out I can set the timeout between packets in my server code, so while it answered at the first keystike at beginning now I can actually test by telnetting and testing manually. SBA.ReceivingTimeout property in server code.

if I telnet to the proxy (MSSOAPT by Microsoft available in MS SOAP Toolkit for free), in x32, it behaves the same as if I were telnetting directly. if I telnet to the proxy in x64 it doesnt say rejected, but the command windows is cleard and the prompt comes back.

When I run the vbscript in x64 it says connected and sending data. But there is no sign in the other end that the data is received, i.e. the MesseageReceived event is not fired and nothing is sent back.

In x64 If I put the proxy in between and try connecting vbscript to it, the connection times out (Cannot Connect.. Unknown Error from the vbscript code)

The remote host is written in Dynamics NAV C/AL. I have a lot of code there, but the answer part is something like this code below. xmlout is a IXMLDOMNODE from MsXML v3.0

So, I think the conclusion is in x64 a connection is established but it is closed very quickly before the script can send the data. And the timeout I set has no impact on this. Probably a problem in the communcation object both the proxy and the vbscript use, since telnetting directly works just ok.






CC2.AddBusAdapter(SBA, 0);

SBA.ReceivingTimeout:= 1000; //maximum 1 sec between each keystroke

SBA.OpenSocket(MobileComputerSetup.Port, '');

//the event:

CommunicationComponent::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")

xmlout.loadXML := '<Transaction>Test</Transaction>';

OutMessage := InMessage.CreateReply();

OutStrm := OutMessage.GetStream;;

Open in new window


Expert Comment

ID: 22691187
>I had seen getdata called both ways and thought they were equal..
Actually it's due to the way I constructed the wrapper..
As to x64 behavior you'd probably need to wait for a NAV expert or someone who was dealing with winsock on x64. Cheers.

Author Comment

ID: 22693168
Thanks Gurgen, I appreciate that you took the time helping me out.

Author Comment

ID: 22700728
Hello, I'm closing this question now since x64 seems out of scope, the original question is answered. Thanks Gurgen.

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now