Jump to content

TCP Receive


Recommended Posts

Due to me lending my psychic helmet out, your going to have to provide more information.

Maybe posting your whole script is a start. I'm not really sure how it can receive -1 unless you don't have an open connection to the server.

Edit: Plus previously you told us it was sending you a reply "unable to read data from the transport connection"

Edited by ChrisL
Link to comment
Share on other sites

You had stuck bits of code posted off here in all sorts of places that didn't make sense.

I have tried to sort it out for you but I don't fully understand what your trying to do.

I don't understand why half way through you changed port numbers, did you mean to do this?

With me not having access to the server I still can't tell you if it is working properly.

Your data string to send was invalid too, I have tried to change it to what I think you were trying to do.

Chris

;CLIENT! Start Me after starting the SERVER!!!!!!!!!!!!!!!
; see TCPRecv example
#include <GUIConstants.au3>

$i = 0
While $i <= 0

;=======TCP SEND - START =======================

; Start The TCP Services
; ==============================================
TCPStartUp()

; Set Some reusable info
; --------------------------
; Dim $szServerPC = @ComputerName
Dim $szServerPC = "66.66.66.66"
MsgBox(4096, "Server", $szServerPC) 

; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address
Dim $szIPADDRESS = TCPNameToIP($szServerPC)
Dim $nPORT = "6920" 
MsgBox(4096, "Port", $nPORT) 

; Initialize a variable to represent a connection
; ==============================================
Dim $ConnectedSocket = -1

; Attempt to connect to SERVER at its IP and PORT 
; =======================================================
$ConnectedSocket = TCPConnect($szIPADDRESS,$nPORT)



; If there is an error... show it
If @error Then
    MsgBox(4112,"Error","TCPConnect failed with WSA error: " & @error & @crlf & "Client will now exit")
    TCPShutdown()
    Exit    
EndIf

; If there is no error loop an inputbox for data to send to the SERVER.

; 

Dim $szData

#cs;;;; ***********************************************There is an issue with this string value***************************************************
$szData = '<?xml version="1.0" encoding="Windows-1252" ?>' & @CRLF & _
'<Signal xmlns="http://borsdata.se/TESSignal.xsd">' & @CRLF & _
'<Version>1.0</Version>' '</Signal>"' 
#ce

$szData = '<?xml version="1.0" encoding="Windows-1252" ?>' & @CRLF & _
'<Signal xmlns="http://borsdata.se/TESSignal.xsd">' & @CRLF & _
"'<Version>1.0</Version>' '</Signal>"""


Msgbox(4096,"Sträng till TCP", $szData) 


; We should have data in $szData... lets attempt to send it through our connected socket.

MsgBox(4096, "TCPSend gjord", $nPORT)


$szDataLen = StringLen($szData) 
$cnt = TCPSend($ConnectedSocket,$szData)
If @error Then ExitLoop
; If the send failed with @error then the socket has disconnected
; ----------------------------------------------------------------

If $szDataLen = $cnt Then 
    MsgBox(4096, "Sent the correct amount of data", $nPORT) 
    Else
        MsgBox(4096, "Didn't send the correct amount of data or there was an error", $nPORT) 
Endif 

TCPCloseSocket($ConnectedSocket);Close the connection as were changing ports?

;*************************************************Why are we changing the port and server connection here?*************************************************

; Skikcar på port 6921 frågor.
Dim $nPORT = "6921" 
MsgBox(4096, "Port", "We have now changed port to " & $nPORT) 

; Initialize a variable to represent a connection
; ==============================================
Dim $ConnectedSocket = -1

; Attempt to connect to SERVER at its IP and PORT 33891
; =======================================================
$ConnectedSocket = TCPConnect($szIPADDRESS,$nPORT)

If @error Then
    MsgBox(4112,"Error","TCPConnect failed with WSA error: " & @error & @crlf & "Client will now exit")
    TCPShutdown()
    Exit    
EndIf


; $szData = 'signal;RTest' 
$szData = 'info;RTest' 
Msgbox(4096,"Sträng till TCP", $szData) 

$szDataLen = StringLen($szData) 
$cnt = TCPSend($ConnectedSocket,$szData)

If $szDataLen = $cnt Then 
    MsgBox(4096, "Sent the correct amount of data", $nPORT) 
    Else
        MsgBox(4096, "Didn't send the correct amount of data or there was an error", $nPORT) 
Endif 


MsgBox(4096, "TCPSend gjord på port 6921", $nPORT)

$recv = ""
    While $recv = ""
        $recv &= TCPRecv($ConnectedSocket,2048)
        If @error Then
            exitloop
        Else
            Msgbox(4096,"Server Reply",$recv) 
        Endif 
    WEnd
;Msgbox(0,@error,$recv) 

Wend
Link to comment
Share on other sites

Thanks Chris.

Well, first i shall send a xml message at port 6920 (the stock-order), then i put in a new question which isn't xml just two letter

'info;RTest' and send it at port 6921 which give me the result from the transaction at port 6920. The result from port 6921 will be how many stocks do i have in total and so on.

My problem is that i don't get any result-message at port 6921. The box Server reply is empty??

muttley

Edited by jorgeng
Link to comment
Share on other sites

when you...I assume it sends a acknowledgment reply that you must receive to know that the request was accepted... only then do you communicate on 6921.

Lar.

Not really, the documentation says sending xml-string at port 6920 and port 6921 is a standalone check port.

But my problem is really i don't know how tcp works in autoit. I assumed that i would get some message from port 6921

and that it would come in the "Server reply " box, but i don't really know if this would work??

Msgbox(4096,"Server Reply",$recv)

muttley

Link to comment
Share on other sites

Not really, the documentation says sending xml-string at port 6920 and port 6921 is a standalone check port.

But my problem is really i don't know how tcp works in autoit. I assumed that i would get some message from port 6921

and that it would come in the "Server reply " box, but i don't really know if this would work??

Msgbox(4096,"Server Reply",$recv)

muttley

What I wrote above works OK with a simulated server (ie. I can send and receive data), but not having access to the proper server or information I can't really help you much.

Link to comment
Share on other sites

Link to comment
Share on other sites

Chris, i sent you the documenation as a message, two word-documents.

Regards

Unfortunately that document doesn't actually tell you very much.

All I ever get from the server is "unable to read data from the transport connection"

Link to comment
Share on other sites

Unfortunately that document doesn't actually tell you very much.

All I ever get from the server is "unable to read data from the transport connection"

Well, i don't know what to do now.

That's all information i has...

muttley

Link to comment
Share on other sites

Well, i don't know what to do now.

That's all information i has...

:)

I put in a message about connected socket and it changes every time i debug, it's now 552.

My support guy on receiving server says that i shall get message at the same socket at port 6921,

what that means...

How do you see the error message?

I saw an error in code, fixed it - the last line in send-string should be:

'</Signal>'

muttley

Edited by jorgeng
Link to comment
Share on other sites

I put in a message about connected socket and it changes every time i debug, it's now 552.

My support guy on receiving server says that i shall get message at the same socket at port 6921,

what that means...

How do you see the error message?

I saw an error in code, fixed it - the last line in send-string should be:

'</Signal>'

muttley

You can't do that. You cant have a single socket connected to 2 ports as far as I know.

Can't you ask the support guy what "unable to read data from the transport connection" means, also confirm they are expecting plain text as it is (or binary) with no other data or header/footer.

I get the error message because I checked the port "6920" for a reply before moving on to the next port and that is where I get the reply "unable to read data from the transport connection".

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...