Jump to content

socket help


mkmcst
 Share

Recommended Posts

this is my mess lol i have had a real hard time scripting a simple server the client was easy :)

heres what i'm trying to do click a button server starts that part is fine but when i try to recv the only way i got it to work was to use a while loop witch is not good for what i'm trying to do i'm just not understanding the way to script a server its very basic i lookd at other posts evrything i have tryd to do will not work anyone have a hint that mite send me down the right path thank you

$Conected = GUICtrlCreateLabel("Conected", 40, 392, 126, 17)
$Isp = GUICtrlCreateLabel("Isp", 41, 410, 126, 17)
$Statu = GUICtrlCreateGroup("Statu", 18, 348, 185, 105)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Icon2 = GUICtrlCreateIcon("C:\Users\creepy\Desktop\mikes fast blast chat\applications_internet.ico", -1, 418, 33, 79, 64)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;---------------dim----------------------------------------------------
dim $recv,$ConnectedSocket


While 1
    $Msg = GUIGetMsg()
If $Msg = $GUI_EVENT_CLOSE Then ExitLoop    
    
    If $msg = $Send Then sendd()
    If $msg = $Start Then startt()
        If $msg = $Stop Then diss()
            
WEnd

;--------------------send--------------------------
Func sendd()
$n=GUICtrlRead($nnnn)
$eeeeee=GUICtrlRead($senput)
GUICtrlSetData($Edit,$eeeeee&">"&$n&@CRLF,1)
TCPSend( $ConnectedSocket,$eeeeee&">"&$n&@CRLF)
EndFunc



;-------------start server----------------------------
Func  startt()
Local $szIPADDRESS = @IPAddress1
    Local $nPORT = 33891
    Local $MainSocket,$ConnectedSocket, $szIP_Accepted
    Local $msg, $recv

TCPStartup()
$MainSocket = TCPListen($szIPADDRESS, $nPORT)
If $MainSocket = -1 Then Exit
    $ConnectedSocket = -1
    Do
        $ConnectedSocket = TCPAccept($MainSocket)
    Until $ConnectedSocket <> -1
    
    ;--------------------socket recive--------------------------------------
    while 2 ;------------this is my main prob can this be done without a loop?  
                
    $recv = TCPRecv($ConnectedSocket,2048)
        If $recv <> "" Then GUICtrlSetData($edit, _
                $szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($edit))        
            
    
    
    WEnd
    EndFunc
Edited by mkmcst
Link to comment
Share on other sites

$Conected = GUICtrlCreateLabel("Conected", 40, 392, 126, 17)
$Isp = GUICtrlCreateLabel("Isp", 41, 410, 126, 17)
$Statu = GUICtrlCreateGroup("Statu", 18, 348, 185, 105)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Icon2 = GUICtrlCreateIcon("C:\Users\creepy\Desktop\mikes fast blast chat\applications_internet.ico", -1, 418, 33, 79, 64)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;---------------dim----------------------------------------------------
dim $recv,$ConnectedSocket





;------------------------
;------------------------
;------------------------
;------------------------
Global $SOCKET
AdlibRegister ('recieve')
;------------------------
;------------------------
;------------------------
;------------------------







While 1
    $Msg = GUIGetMsg()
If $Msg = $GUI_EVENT_CLOSE Then ExitLoop

    If $msg = $Send Then sendd()
    If $msg = $Start Then startt()
        If $msg = $Stop Then diss()

WEnd

;--------------------send--------------------------
Func sendd()
$n=GUICtrlRead($nnnn)
$eeeeee=GUICtrlRead($senput)
GUICtrlSetData($Edit,$eeeeee&">"&$n&@CRLF,1)
TCPSend( $ConnectedSocket,$eeeeee&">"&$n&@CRLF)
EndFunc





;------------------------
;------------------------
;------------------------
;------------------------
Func receive ()
    $recv = TCPRecv($ConnectedSocket,2048)
    If $recv <> "" Then GUICtrlSetData($edit, $szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($edit))
EndFunc
;------------------------
;------------------------
;------------------------
;------------------------






;-------------start server----------------------------
Func  startt()
Local $szIPADDRESS = @IPAddress1
    Local $nPORT = 33891
    Local $MainSocket,$ConnectedSocket, $szIP_Accepted
    Local $msg, $recv

    TCPStartup()
    $MainSocket = TCPListen($szIPADDRESS, $nPORT)
    If $MainSocket = -1 Then Exit
    $ConnectedSocket = -1
    Do
        $ConnectedSocket = TCPAccept($MainSocket)
    Until $ConnectedSocket <> -1
    
    
    
    
    
    
    
    
    
    
    
    
    ;------------------------
    ;------------------------
    ;------------------------
    ;------------------------
    Global $SOCKET = $ConnectedSocket
    Return
    ;------------------------
    ;------------------------
    ;------------------------
    ;------------------------
    
    
    
    
    
    
    
    
    
    
    
    
EndFunc

what i changed is in the comments... I could not test it out, because you did not give me a workable example, but ADLIB functions should be what you want

Link to comment
Share on other sites

hi thank you for the help but i could not get that AdlibRegister () to work in my script but thank you for pointing that out to me i could of used that in other scripts learn something new everyday :) it seems i need to learn more on Global dims etc but i took your Global moved it a few times and poof its working for me so i thought i would post my simple server script thanks again for the code bits

michael

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
Opt('MustDeclareVars', 1)
Local $szIPADDRESS = @IPAddress1
    Local $nPORT = 33892
    Local $MainSocket,$ConnectedSocket, $szIP_Accepted
    Local $msg, $recv

dim $Form1,$Server,$Chat,$Edit,$senput,$Send,$Icon1,$Admin,$Nick,$nnnn,$Start,$Stop,$Status,$Conected,$Isp,$Statu,$Icon2,$n
#Region ### START Koda GUI section ### Form=C:\Users\creepy\Desktop\mikes fast blast chat\Server.kxf
$Form1 = GUICreate("Michaels Fast Blast msg  Server (beta)", 552, 513, 225, 158)
$Server = GUICtrlCreateTab(0, 0, 545, 505, $TCS_BOTTOM)
$Chat = GUICtrlCreateTabItem("Chat")
$Edit = GUICtrlCreateEdit("", 8, 8, 529, 377 ,BitOR($ES_MULTILINE, $ES_READONLY,$WS_VSCROLL, $WS_BORDER))
_GUICtrlEdit_LineScroll($Edit, 0, _GUICtrlEdit_GetLineCount($Edit))
$senput = GUICtrlCreateInput("Input1", 8, 399, 401, 21)
$Send = GUICtrlCreateButton("Send", 424, 398, 75, 25)
$Icon1 = GUICtrlCreateIcon("C:\Users\creepy\Desktop\mikes fast blast chat\irc_protocol.ico", -1, 224, 432, 50, 40)
$Admin = GUICtrlCreateTabItem("Admin")
GUICtrlSetState(-1,$GUI_SHOW)
$Nick = GUICtrlCreateLabel("Nick", 72, 104, 26, 17)
$nnnn = GUICtrlCreateInput("Input2", 104, 104, 161, 21)
$Start = GUICtrlCreateButton("Start", 440, 424, 75, 25)
$Stop = GUICtrlCreateButton("Stop", 360, 424, 75, 25)
$Status = GUICtrlCreateLabel("Status", 40, 376, 126, 17)
$Conected = GUICtrlCreateLabel("Conected", 40, 392, 126, 17)
$Isp = GUICtrlCreateLabel("Isp", 41, 410, 126, 17)
$Statu = GUICtrlCreateGroup("Statu", 18, 348, 185, 105)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Icon2 = GUICtrlCreateIcon("C:\Users\creepy\Desktop\mikes fast blast chat\applications_internet.ico", -1, 418, 33, 79, 64)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
dim $recv,$ConnectedSocket,$MainSocket
;-------------------------server connect---------------------------------------
    Global $MainSocket = $ConnectedSocket



While 1
    $Msg = GUIGetMsg()
If $Msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $Send Then sendd()
    If $msg = $Start Then startt()
        If $msg = $Stop Then diss()
$recv = TCPRecv($ConnectedSocket,2048)
    If $recv <> "" Then GUICtrlSetData($edit, $szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($edit))
WEnd
;--------------------send--------------------------
Func sendd()
    dim $eeeeee
$n=GUICtrlRead($nnnn)
$eeeeee=GUICtrlRead($senput)
GUICtrlSetData($Edit,$eeeeee&">"&$n&@CRLF,1)
TCPSend( $ConnectedSocket,$eeeeee&">"&$n&@CRLF)
EndFunc
;-------------start server----------------------------
Func  startt()  
TCPStartup()
    $MainSocket = TCPListen($szIPADDRESS, $nPORT)
    If $MainSocket = -1 Then Exit
    $ConnectedSocket = -1

Do
        $ConnectedSocket = TCPAccept($MainSocket)
    Until $ConnectedSocket <> -1


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