hi,
Ich habe mit einen kleinen "TCP - IP Chat" angefangen nur leider komme ich nicht richtig weiter wie kann man z.B.
nachrichten abfangen ohne diese i-wo zu speichern?
Wie kann ich die ip von dem User bekommen gerade connected?
Vllt ein paar verbesserungsmöglichkeiten für meinen chat.
Spoiler anzeigen
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GuiIPAddress.au3>
#include <inet.au3>
#include <GuiStatusBar.au3>
dim $ip = @ipaddress1
dim $mitem[6]
$Username = iniread("config.ini","config","name","")
if $username = "" Then
#Region gui
$Namegui = GUICreate("Username", 316, 128)
$GroupBox = GUICtrlCreateGroup("", 8, 1, 297, 81)
$Input = GUICtrlCreateInput("", 24, 40, 265, 21)
$Label = GUICtrlCreateLabel("Geben Sie Ihren Username ein.", 24, 16, 152, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Buttonok = GUICtrlCreateButton("&OK", 65, 91, 75, 25, 0)
$Buttoncancel = GUICtrlCreateButton("&Cancel", 162, 91, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion gui
While 1
$Msg = GUIGetMsg()
switch $msg
Case $buttoncancel
exitloop
case $GUI_EVENT_CLOSE
exitloop
case $buttonok
$username = GUICtrlRead($input)
if $username = "" Then $username = "Defaultuser"
iniwrite("config.ini","config","name",$username)
exitloop
Endswitch
wend
GUISetState(@SW_hide,$namegui)
EndIf
#Region gui
$Form2 = GUICreate("Messenger", 531, 365)
$ListView1 = GUICtrlCreateListView("Name", 336, 8, 177, 305)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 173)
$Menu = GuiCtrlCreateMenu("Menu")
$mitem[1] = GUICtrlCreateMenuItem("Start server",$menu)
$mitem[2] = GUICtrlCreateMenuItem("connect",$menu)
$mitem[3] = GUICtrlCreateMenuItem("Kick User",$menu)
GUICtrlSetState ($mitem[3], $GUI_DISABLE)
$mitem[4] = GUICtrlCreateMenuItem("Ban User",$menu)
GUICtrlSetState ($mitem[4], $GUI_DISABLE)
$mitem[5] = GUICtrlCreateMenuItem("close",$menu)
$About = GuiCtrlCreateMenu("About")
$aitem = GUICtrlCreateMenuItem("About",$About)
$Help = GuiCtrlCreateMenu("Help")
$hitem = GUICtrlCreateMenuItem("?",$Help)
$Edit = GUICtrlCreateEdit("", 16, 8, 289, 265)
GUICtrlSetState ($edit, $GUI_DISABLE)
GUICtrlSetFont($edit, 10, 400, 0, "Courier New")
$Input = GUICtrlCreateInput("", 16, 288, 225, 21)
GUICtrlSetState ($input, $GUI_DISABLE)
$buttonsend = GUICtrlCreateButton("Send", 256, 288, 49, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetState ($buttonsend, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion gui
tcpstartup()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
case $mitem[1]
$MainSocket = TCPListen($ip,80,100)
$conSocket = TCPconnect($ip,80)
If $ConSocket >= 0 Then
msgbox(0,"","Client Connected")
GUICtrlSetState ($buttonsend, $gui_enable)
GUICtrlSetState ($edit, $gui_enable)
GUICtrlSetState ($input, $gui_enable)
GUICtrlSetState ($mitem[4], $gui_enable)
GUICtrlSetState ($mitem[3], $gui_enable)
GUISetState()
$ret = TCPSend($ConSocket, "- " & $username & " is online now.")
GUICtrlSetData($edit, "- " & $username & " is online now." & @CRLF)
Else
msgbox(0,"","Error Server Nicht erreichbar")
EndIf
while 1
$Msg = GUIGetMsg()
Switch $Msg
case $buttonsend
If $ConSocket > -1 Then
$ret = TCPSend($ConSocket, GUICtrlRead($input))
If @error Or $ret < 0 Then
TCPCloseSocket($ConSocket)
WinSetTitle($Form2, "", "my server - Client Disconnected")
$ConSocket = -1
ElseIf $ret > 0 Then
GUICtrlSetData($edit, GUICtrlRead($edit) & $username & ": " & GUICtrlRead($input) & @CRLF)
EndIf
EndIf
GUICtrlSetData($input, "")
case $GUI_EVENT_CLOSE
TCPCloseSocket ($mainSocket)
GUISetState(@SW_hide,$form2)
exit
endswitch
wend
case $mitem[2]
#Region gui
$connectgui = GUICreate("Connect", 316, 128)
$GroupBox = GUICtrlCreateGroup("", 8, 1, 297, 81)
$Label = GUICtrlCreateLabel("Geben Sie die ip des Servers ein.", 24, 16, 161, 17)
$IPAddress = _GUICtrlIpAddress_Create($connectgui, 24, 40, 257, 25)
_GUICtrlIpAddress_Set($IPAddress, "192.168.0.0")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Buttonok = GUICtrlCreateButton("&OK", 65, 91, 75, 25, 0)
$Buttoncancel = GUICtrlCreateButton("&Cancel", 162, 91, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion gui
While 1
$Msg = GUIGetMsg()
$conip = GUICtrlRead($IPAddress)
switch $msg
Case $Buttonok
$conSocket = TCPconnect($conip,80)
msgbox(0,"",$consocket&" "&@error)
If $ConSocket >= 0 Then
msgbox(0,"","Client Connected")
GUISetState(@SW_hide,$connectgui)
GUICtrlSetState ($buttonsend, $gui_enable)
GUICtrlSetState ($edit, $gui_enable)
GUICtrlSetState ($input, $gui_enable)
GUICtrlSetState ($mitem[4], $gui_enable)
GUICtrlSetState ($mitem[3], $gui_enable)
$ret = TCPSend($ConSocket, "- " & $username & " is online now.")
GUICtrlSetData($edit, "- " & $username & " is online now." & @CRLF)
while 1
$Msg = GUIGetMsg()
Switch $Msg
case $buttonsend
If $ConSocket > -1 Then
$ret = TCPSend($ConSocket, GUICtrlRead($input))
If @error Or $ret < 0 Then
TCPCloseSocket($ConSocket)
WinSetTitle($Form2, "", "my server - Client Disconnected")
$ConSocket = -1
ElseIf $ret > 0 Then
GUICtrlSetData($edit, GUICtrlRead($edit) & $username & ": " & GUICtrlRead($input) & @CRLF)
EndIf
EndIf
GUICtrlSetData($input, "")
case $GUI_EVENT_CLOSE
GUISetState(@SW_hide,$form2)
exit
endswitch
wend
Else
msgbox(0,"","Error Server Nicht erreichbar")
GUISetState(@SW_hide,$connectgui)
exit
EndIf
Case $buttoncancel
GUISetState(@SW_hide,$connectgui)
Exit
case $GUI_EVENT_CLOSE
GUISetState(@SW_hide,$connectgui)
exit
endswitch
wend
case $mitem[3]
exitloop
case $aitem
msgbox(0,"","Noch in Arbeit...")
case $hitem
msgbox(0,"","Noch in Arbeit...")
EndSwitch
WEnd