Sign in to follow this  
Followers 0
Rad

TCP is confusing me

6 posts in this topic

#1 ·  Posted (edited)

http://www.autoitscript.com/forum/index.ph...mp;#entry222573

I didnt even know you could do that with autoit!! i was messing around with it trying to make my own (to learn how it works better) and was trying to send to an edit on the server, but it only worked for the first message... I really dont understand the way he coded it above, with chr()'s and all the variables :P

Could someone explain how to better use the TCP Recv and TCP Send a little bit better? Its not working and I just dont understand why... Heres what I have now, just run this and the Client in your au3\beta\helpfile folder... It doesnt really work though.... id really like to get this to work

EDIT: This works a little bit better, except it doesnt recieve the first character (the client accepted: 1/2 is for testing)

#Include <GUIConstants.au3>

Dim $IPAddress
Dim $Port
Dim $Users[8]
Dim $UserView[8]
Dim $RecieveMsg
$UserSlots = "12345678"

$Temp = InputBox("Server","Enter your IP",@IPAddress1,"",200,128)
If Not @error Then 
    $IPAddress = $Temp
Else
    Exit
Endif

$Temp = InputBox("Server","Enter a port (0-65535)","2048","",200,128)
If Not @error Then 
    $Port = $Temp
Else
    Exit
Endif

TCPStartup()

$Listen = TCPListen($IPAddress, $Port, 8)
$Window = GUICreate("Server",384,256)
$Edit = GUICtrlCreateEdit("",2,2,380,252)
;~ $ListView = GUICtrlCreateListView("   Username   |   IP Address   |  Socket   ",2,2,254,252,BitOr($LVS_SHOWSELALWAYS,$LVS_NOSORTHEADER))
;~ For $i = 0 to 7
;~  $UserView[$i] = GUICtrlCreateListViewItem("Empty|192.168.101.10" & $i & "|Null",$listView)
;~ Next

GUISetState()

If $Listen = -1 Then 
    Msgbox(0,"Error","Invalid IP or Port!")
    Exit
Endif
    
$temp = $Users[StringLeft($UserSlots,1)]
    
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    If StringLen($UserSlots) > 0 Then 
        $Users[StringLeft($UserSlots,1)] = TCPAccept($Listen)
        If $temp <> $Users[StringLeft($UserSlots,1)] Then msgbox(0,"Client Accepted","Accepted Client: " & StringLeft($UserSlots,1))
        $temp = $Users[StringLeft($UserSlots,1)]
    Else
        $Temp = TCPAccept($Listen)
        TCPSend($Temp,"Server is full")
        TCPCloseSocket($Temp)
    Endif
    
    If $Users[StringMid($UserSlots,1,1)] >= 0 Then
        msgbox(0,"","Client Connected")
        If StringLen($UserSlots) <> 0 Then 
            $UserSlots = StringMid($UserSlots,2,StringLen($UserSlots))
        Else
            $UserSlots = ""
        Endif
    EndIf
    If TCPRecv($Users[1],1) <> "" Then msgbox(0,"",TCPRecv($Users[1],1000))
;~  For $i = 0 to 7
;~      If StringInStr($UserSlots,$i) = 0 Then 
;~          $Temp = TCPRecv($Users[$i],1)
;~          If $Temp <> "" Then 
;~              msgbox(0,"",$temp)
;~              $RecieveMsg = $RecieveMsg & $Temp
;~              GUICtrlSetData($Edit,$RecieveMsg)
;~          Endif
;~      Endif
;~  Next
Wend
Edited by Rad

Share this post


Link to post
Share on other sites



I have a thread about TCP. Check my signature for many examples.

Specifically TCP Internal Server Update 1 which allows you to customize the Stream and Funciton prefixes. (Aka Chr(X))

Share this post


Link to post
Share on other sites

:P

Why cry?

Share this post


Link to post
Share on other sites

No it is TCP Made Easy because it explains it in a scripters mind. Set's errors and returns values according to the actual function. That way you can understand it more instead of using the helpfile.

The only function I recommend is TCPStartServer

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