RE: Mondo confused on the TCPxxxxx commands...

<[email protected]>
Newsgroups gmane.comp.windows.autoit.user
Message-ID <C3339561D7B7F246B51D79A63BA14BEC01905DB9@drsse603.eu.infineon.com>
So I am not the only person who doesn't understand how this part works?

 

________________________________

From: [email protected] [mailto:[email protected]] On
Behalf Of Marx Keath (QNA IT GS ISA External)
Sent: Tuesday, January 23, 2007 6:55 AM
To: [email protected]; [email protected]
Subject: [AutoIt] Mondo confused on the TCPxxxxx commands...

 

Hey gang,

I have been banging my head on this for awhile now and have gotten no
where. I have been reading the help file and looking over the examples
included there and an example Valery sent the last time I inquired about
this stuff but I just don't get it obviously because it doesn't work
like I would expect it.

I am trying to write a client/server application that works basically
like this...

I want a central server that just sits waiting for incoming connections.
When it receives one it receives the data. In this case it will be a
one word request such as 'report' or 'update'. Once it gets this
message I want it to send back a response (basically "I heard you").
Then I want it to go back to listening to that port or process any
further pending incoming connections.

I have managed to get it to start up and listen on the port. It detects
the connections and receives the data packet. It sees the packet, reads
it properly and sends the response. But then it just loops. It doesn't
respond to anymore incoming connections.

This is the code I am using for the server side:

$StartCheck = TCPStartup()

If $StartCheck < 1 Then

_FileWriteLog($LogFile,"-- Error starting TCP Services..." &
@error & " *****")

Exit

EndIf

_FileWriteLog($LogFile,"-- TCP Services Online...")

_FileWriteLog($LogFile,"--- Creating Listening port")

$nMainSocket = TCPListen( $MasterIP, $MasterPort )

While 1

Detect()

Rcv()

Wend

Func Detect()

_FileWriteLog($LogFile,"--- Monitoring for incoming connections-" &
$nSocketRecv)

While $nSocketRecv = -1

ToolTip( "waiting for incoming file...", 0, 0 )

$nSocketRecv = TCPAccept( $nMainSocket )

WEnd

TCPCloseSocket($nSocketRecv)

EndFunc

;MsgBox(0,"test",$nSocketRecv)

Func Rcv()

While 1

_FileWriteLog($LogFile,"--- Receiving data...-" & $nSocketRecv & " - " &
$szRecvBuffer & "-=> " & @error)

$szRecvBuffer &= TCPRecv( $nSocketRecv, 2048 )

; MsgBox(0,"test",$szRecvBuffer)

If @error Then ExitLoop

_FileWriteLog($LogFile,"---- Buffer Length="&
StringLen($szRecvBuffer))

If StringLen($szRecvBuffer) Then

If $szRecvBuffer = "report" Then

_FileWriteLog($LogFile,"---- Detected Communication Request...")

Ohura()

ExitLoop

ElseIf $szRecvBuffer = "done" Then

_FileWriteLog($LogFile,"----- End Communication requested...")

TCPCloseSocket($nSocketRecv)

_FileWriteLog($LogFile,"------ Socket closed -" & @error & " -=> " &
$nSocketRecv)

$szRecvBuffer = ""

Return

EndIf

EndIf

WEnd

EndFunc

Exit

Func Ohura()

; _ArrayDisplay($AvailPorts,"test")

; MsgBox(0,"test","Spawn Listener")

_FileWriteLog($LogFile,"---- Responding to communication request")

TCPSend($nSocketRecv,"ohura-" & _ArrayPop($AvailPorts))

; TCPCloseSocket($nSocketRecv)

$szRecvBuffer = ""

; $nSocketRecv = -1

EndFunc

TCPSend($nSocketRecv,"go away")

[Non-text portions of this message have been removed]

 



[Non-text portions of this message have been removed]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.