Jump to content
Sign in to follow this  

[Solved] Little help with TCP Server/Client

Recommended Posts



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.



Edited by Borje

Share this post

Link to post
Share on other sites

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:



$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
        msgbox(0,"Display message !",$info)



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

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

Share this post

Link to post
Share on other sites

Than you Free fry

I tested this and I understand little more thanks again for your help.

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.