Jump to content

Need some help in TCp


Recommended Posts

Hi all

i had posted before my first try (which was terrible) that must detect if the other side is online or not 

i'm trying to make a script that i can know if the other PC is connected to the internet or not

here's my second try

sender

TCPStartup()
$TCPcon = TCPConnect (@IPAddress1, 1234)
TCPSend($TCPcon, "on")

receiver 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("Form1", 615, 227)
$Mainlist = GUICtrlCreateList("", -1,-1, 615, 1)
GUISetState()

TCPStartup()
$MainSocket = TCPListen(@IPAddress1, 1234)

While 1
    $TCPAccept = TCPAccept($MainSocket)
    $TCPRecv = TCPRecv($TCPAccept, 9999999)
    If $TCPRecv = "on" Then GUICtrlSetData($Mainlist , $TCPRecv)
    If $TCPRecv <> "on" Then GUICtrlSetData($Mainlist , "")
WEnd

this is working fine if i runned the sender code multiple times and fast enough i'll see it in my list

but i can't get it to always send the "on" message

i tried this 

TCPStartup()
$TCPcon = TCPConnect (@IPAddress1, 1234)
While 1
TCPSend($TCPcon, "on")
WEnd

but it doesn't worked

any ideas ?

Link to comment
Share on other sites

Try

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("Form1", 615, 227)
$Mainlist = GUICtrlCreateList("", -1, -1, 615, 227)
GUISetState()
Global $TCPAccept
TCPStartup()
$MainSocket = TCPListen(@IPAddress1, 1234)

_TCPAccept()

While 1
    $TCPRecv = TCPRecv($TCPAccept, 9999999)
    If @error Then
        GUICtrlSetData($Mainlist, "Off")
        _TCPAccept()
    EndIf
    GUICtrlSetData($Mainlist, $TCPRecv)
    Sleep(200)
WEnd
Func _TCPAccept()
    Do
        $TCPAccept = TCPAccept($MainSocket)
    Until Not @error
EndFunc   ;==>_TCPAccept

server

TCPStartup()

Do
    $TCPcon = TCPConnect(@IPAddress1, 1234)
Until Not @error

While 1
    TCPSend($TCPcon, "on")
    Sleep(200)
WEnd
Link to comment
Share on other sites

 

Try

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("Form1", 615, 227)
$Mainlist = GUICtrlCreateList("", -1, -1, 615, 227)
GUISetState()
Global $TCPAccept
TCPStartup()
$MainSocket = TCPListen(@IPAddress1, 1234)

_TCPAccept()

While 1
    $TCPRecv = TCPRecv($TCPAccept, 9999999)
    If @error Then
        GUICtrlSetData($Mainlist, "Off")
        _TCPAccept()
    EndIf
    GUICtrlSetData($Mainlist, $TCPRecv)
    Sleep(200)
WEnd
Func _TCPAccept()
    Do
        $TCPAccept = TCPAccept($MainSocket)
    Until Not @error
EndFunc   ;==>_TCPAccept

server

TCPStartup()

Do
    $TCPcon = TCPConnect(@IPAddress1, 1234)
Until Not @error

While 1
    TCPSend($TCPcon, "on")
    Sleep(200)
WEnd

 

ya so nice piece of code it is working but it is giving 2 lines when i run the sender 1 time

temp.png

 

thank you so much i'll try to fix it

Link to comment
Share on other sites

:)   have fun!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("Form1", 615, 227)
$Mainlist = GUICtrlCreateList("", -1, -1, 615, 227)
GUISetState()
Global $TCPAccept
TCPStartup()
$MainSocket = TCPListen(@IPAddress1, 1234)

_TCPAccept()

While 1
    $TCPRecv = TCPRecv($TCPAccept, 9)
    If @error Then
        GUICtrlSetData($Mainlist, "")
        _TCPAccept()
        ContinueLoop
    EndIf
    If $TCPRecv <> "" Then GUICtrlSetData($Mainlist, $TCPRecv)
    Sleep(100)
WEnd
Func _TCPAccept()
    GUICtrlSetData($Mainlist, "Off")
    Do
        $TCPAccept = TCPAccept($MainSocket)
    Until $TCPAccept <> -1
    GUICtrlSetData($Mainlist, "")
EndFunc   ;==>_TCPAccept
Link to comment
Share on other sites

 

:)   have fun!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("Form1", 615, 227)
$Mainlist = GUICtrlCreateList("", -1, -1, 615, 227)
GUISetState()
Global $TCPAccept
TCPStartup()
$MainSocket = TCPListen(@IPAddress1, 1234)

_TCPAccept()

While 1
    $TCPRecv = TCPRecv($TCPAccept, 9)
    If @error Then
        GUICtrlSetData($Mainlist, "")
        _TCPAccept()
        ContinueLoop
    EndIf
    If $TCPRecv <> "" Then GUICtrlSetData($Mainlist, $TCPRecv)
    Sleep(100)
WEnd
Func _TCPAccept()
    GUICtrlSetData($Mainlist, "Off")
    Do
        $TCPAccept = TCPAccept($MainSocket)
    Until $TCPAccept <> -1
    GUICtrlSetData($Mainlist, "")
EndFunc   ;==>_TCPAccept

 

Thanks a lot buddy i really appreciate your help

your script is perfect

but may i ask a little question ?

when i remove the  _TCPAccept() from line 11 nothing change 

if i removed it wont affect anything right ?

and also the ContinueLoop is useless here  ?

please correct me if i'm wrong

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...