Solved

GetData does not receive the data

Posted on 2008-10-08
12
1,446 Views
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
 
 
Do
      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 & _
"</Orders>"
 
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
     objWS.CloseCon
     Wscript.Quit
 
End Sub
 
Sub objWS_DataArrival(bytesTotal)
      objWS.GetData strData, vbString
      Wscript.Echo "Received " & bytesTotal & " bytes."
      Wscript.Echo strData
End Sub

Open in new window

0
Comment
Question by:moonlight
[X]
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
12 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 22668967
0
 
LVL 3

Author Comment

by:moonlight
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.
0
 
LVL 3

Author Comment

by:moonlight
ID: 22677006
maybe I can use csocketmaster instead? http://www.geocities.com/anshoku/CSocketMaster13_CSocketPlus12_alfa.zip
anyone able to compile the ocx?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:moonlight
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?
0
 
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...
0
 
LVL 1

Expert Comment

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

Gurgen Alaverdian
0
 
LVL 3

Author Comment

by:moonlight
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.
0
 
LVL 1

Accepted Solution

by:
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)
0
 
LVL 3

Author Comment

by:moonlight
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.
IF ISCLEAR(CC2) THEN BEGIN
  CREATE(CC2);
END;
IF ISCLEAR(SBA) THEN BEGIN
  CREATE(SBA);
END;
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;
xmlout.save(OutStrm);

Open in new window

0
 
LVL 1

Expert Comment

by:4u2ges
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.
0
 
LVL 3

Author Comment

by:moonlight
ID: 22693168
Thanks Gurgen, I appreciate that you took the time helping me out.
0
 
LVL 3

Author Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

733 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