Sign in to follow this  
Followers 0
Buffo

TCP connection

4 posts in this topic

Hello!

I am new to TCp connections and made my first attempts but something went wrong. Perhaps you can help me.

It's only for a test. Client and server are running on the same machine and the only thing that should happen is that filled in text in client app should be sent to the server app as long as the string "quit" is not used.

Have a look what I have done so far:

Server

TCPStartup()

$iMainSocket = TCPListen("127.0.0.1", 10372)
If $iMainSocket = -1 Then Exit

While 1
    $iConnectedSocket = TCPAccept($iMainSocket)
    If $iConnectedSocket <> -1 Then
        $sReceived = TCPRecv($iConnectedSocket, 1024)
        If $sReceived = "" Then
        ExitLoop
    Else
        MsgBox(0, "Received", $sReceived)
        EndIf
    EndIf           
WEnd

TCPShutdown()

Client

Do
    $sInput = Input()
    Sleep(100)
Until $sInput = "quit"

Func Input()
    TCPStartup()
    $iConnectedSocket = TCPConnect("127.0.0.1", 10372)
    If $iConnectedSocket = -1 Then Exit
    $sData = Inputbox("Input", "String to send")
    TCPSend($iConnectedSocket, $sData)
    TCPShutdown()
    Return $sData
EndFunc

I thin the problem will be the While...Wend part on server side, but I don't have an idea. I hope you can help :)

Thx in advance :D

Regards,

Buffo

Share this post


Link to post
Share on other sites



Here's your server revised. This is how I would do it, not saying that this is the only way to go.

Dim $iConnectedSocket = -1

TCPStartup()

$iMainSocket = TCPListen(@IPAddress1, 10372)
If @error Then
    MsgBox(0, "", "Server could not be started on " & @IPAddress1 & ":" & "10372")
    Exit
EndIf

While 1
    $iNewSocket = TCPAccept($iMainSocket)
    If $iNewSocket <> -1 Then 
        $iConnectedSocket = $iNewSocket
    EndIf
    If $iConnectedSocket <> -1 Then
        $sReceived = TCPRecv($iConnectedSocket,1024)
        ;If @error Then ExitLoop ;uncomment this if you want it to quit after the client has disconnected
        If $sReceived <> "" Then
            MsgBox(0,"Received data", $sReceived)
        EndIf
    EndIf
WEnd

TCPShutdown()

Share this post


Link to post
Share on other sites

@Manadar: Thx a lot for your reply :)

This works already a little bit :D

The problem here is that the first given input will be displayed but after that the MsgBox in server keeps quiet.

That can that be?

Regards,

Buffo

Share this post


Link to post
Share on other sites

@Manadar: Thx a lot for your reply :)

This works already a little bit :D

The problem here is that the first given input will be displayed but after that the MsgBox in server keeps quiet.

That can that be?

Regards,

Buffo

MsgBox is a so called 'Blocking function'. Whenever AutoIt displays a MsgBox it is unabled to perform any other commands. Try to close the MsgBox and resend. Alternately, use a ToolTip to display information from the server. ToolTip is not a blocking function.

Share this post


Link to post
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
Sign in to follow this  
Followers 0