GetData does not receive the data

Posted on 2008-10-08
Medium Priority
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 (http://www.gurgensvbstuff.com/index.php?ID=27), 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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
LVL 86

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? http://www.geocities.com/anshoku/CSocketMaster13_CSocketPlus12_alfa.zip
anyone able to compile the ocx?
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users


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 86

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

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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This video teaches viewers about errors in exception handling.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

801 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