Sign in to follow this  
Followers 0
Michael36

Sockets

3 posts in this topic

Hi all i been playing with the sockets i have everything working ok but seems to me there has to be a loop of some kind to keep Receiving the servers Messages ?

Any ideas on how to do this ? i'm use to gosub and goto so i'm kinda lost on how to do this

help would be apreshated

thank you

michael

#include <GuiConstants.au3>

dim$msg,$server,$port,$recv,$Edit_6 ,$socket,$Edit,$input

GuiCreate("MyGUI", 520, 370,(@DesktopWidth-520)/2, (@DesktopHeight-370)/2)

$Label_1 = GuiCtrlCreateLabel("Server", 10, 10, 40, 20)
$server = GuiCtrlCreateInput("66.54.152.7", 60, 10, 110, 20)
$Label_3 = GuiCtrlCreateLabel("Port", 190, 10, 30, 20)
$port = GuiCtrlCreateInput("110", 220, 10, 90, 20)
$ok1 = GuiCtrlCreateButton("connect", 320, 10, 100, 20)
$edit = GuiCtrlCreateEdit("", 0, 40, 520, 300,$WS_DISABLED)
$Input_7 = GuiCtrlCreateInput("Input7", 0, 340, 460, 30)
$send= GuiCtrlCreateButton("Send", 460, 340, 60, 30)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $ok1
    $g_IP = GUICtrlRead ($server)
    TCPStartUp()
    $socket = TCPConnect( $g_IP,GUICtrlRead($port )) 
If $socket= -1 Then MsgBox(0, "SERVER", "Cannot be reached")
Sleep(1000)
;--------------Recv-------------------------------------------
$recv = TCPRecv($socket, 512 )
   
    If $recv  <> "" Then
        GUICtrlSetData($edit, GUICtrlRead($edit) & $recv  & @CRLF)
    EndIf

;-----------send----------------------------------------------
Case $msg =$send
TCPSend( $socket, GUICtrlRead($Input_7))


                   
;---------------------------------------------------
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Do
    $recv = TCPRecv($socket, 512 )

    If $recv <> "" Then
        GUICtrlSetData($edit, GUICtrlRead($edit) & $recv & @CRLF)
     EndIf
Until @error

Edited by Raindancer

Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer

Share this post


Link to post
Share on other sites

perhaps you can start with the TCPRecv and TCPSend doc example they are working server/client examples.

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