# TCP is confusing me

## Recommended Posts

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

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

##### 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))

Why cry?

##### Share on other sites

I dont really get this lol

http://www.autoitscript.com/forum/index.ph...c=18738&hl=

Do I use this as an include? and if I do... whats different? I mean ... TCPRecieve looks like TCPRecv

Plus, you made it easy but you didnt explain it to newbie status

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

## Create an account

Register a new account