Link to home
Start Free TrialLog in
Avatar of moonlight
moonlight

asked on

GetData does not receive the data

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

Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Avatar of moonlight
moonlight

ASKER

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.
maybe I can use csocketmaster instead? http://www.geocities.com/anshoku/CSocketMaster13_CSocketPlus12_alfa.zip
anyone able to compile the ocx?
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?
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...
Hi guys,
Frankly, not tested wrapper on Vista yet.. Would do.. as soon as time permitted

Gurgen Alaverdian
*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.
ASKER CERTIFIED SOLUTION
Avatar of 4u2ges
4u2ges

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

>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.
Thanks Gurgen, I appreciate that you took the time helping me out.
Hello, I'm closing this question now since x64 seems out of scope, the original question is answered. Thanks Gurgen.