Jump to content

Recommended Posts

Posted (edited)

Hello

I try to understand how this works the problem I have is this I can not send over the string Hello World from the client to the server

What have I done wrong here?

The client have contact with the server but the messagebox message in the server pop up blank.

Client_Test.au3

Server_test.au3

Edited by Borje
Posted

First of all, in your server, to recieve data, you use the connected socket identifier(as returned by TCPAccept) not the main socket identifier(returned by TCPListen).

Also in your client-script, because of that the script exits instantly after sending the bytes, causing the connected socket to be invalid(causing the server to miss the message as the socket gets disconnected).

Modified your code a little:

Server:

TCPStartUp()

$sListenAddress = @IPAddress1
$iListenPort = 8084

$iMainsocket = TCPListen($sListenAddress, $iListenPort)
If $iMainsocket = -1 Then Exit(MsgBox(0, "Error", "Could not create the listening socket"))

While 1
    $ConnectedSocket = TCPAccept($iMainsocket)
    If $ConnectedSocket >= 0 Then
        $info=TCPRecv($ConnectedSocket,512)
        msgbox(0,"Display message !",$info)
    EndIf
    Sleep(250)
Wend

Client:

TCPStartUp()

$g_IP = @IPAddress1
$Message = "Hello World"

$socket = TCPConnect( $g_IP, 8084 )
TCPSend($socket,$message)
Sleep(2500); Sleep some to keep the connection open, allowing the server to parse the message

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
×
×
  • Create New...