Jump to content

[SOLVED] TCP Chat Problem


 Share

Recommended Posts

Hello Every One

I tried many of the TCP Chat programs

which worked flawlessly between my computer and my moms computer in the same WiFi Network

Then I decided to give the program to my friends and do chat with them

But, that didnt work

After a lot of searching I found that PORT FORWARDING would be required for Private networks

My friends were not aware of any of this, therefore i chose to make a program that could do the

PORT FORWARDING by itself.

I finally chose the NAT-PMP for this,

But I'm not able to find anything to do it.

Please Guide my in the Right Direction

Thanks for your Time :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

:guitar: I always prefer UPnP. See http://www.codeproject.com/Articles/27237/Easy-Port-Forwarding-and-Managing-Router-with-UPnP. A good place where I got started...

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

Thanks.

Topic Solved

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Why not use the UDP protocol? Since from your initial post both your Mum and you are on the same local area network.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

nullschritt,

this code worked for me

I got it from the Forum and modified it as per my needs

;Port Forwarding
Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling.
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler
Global $debuglog = "Chat Debug.log"
Global $debug = 0 ; 1 = Log , 0 = no log
Global $console = 0 ;1=ConsoleWrite , 0= No ConsoleWrite

If is_privateIP(@IPAddress1) Then PortForward('TCP')
If @error Then Exit -1

Func PortForward($nProtocol='UDP',$nInternalPort=6800,$nExternalPort=$nInternalPort,$nIPAddress=@IPAddress1,$nDescription='PortForward')
If FindDevice() Then
Return SetError(0,0,UpnpPortMap($nIPAddress, $nInternalPort, $nExternalPort, $nProtocol, $nDescription))
EndIf
Return SetError(1,0,0)
EndFunc

Func UpnpPortMap($InternalIP, $InternalPort, $ExternalPort, $Protocol, $Description)
Local $theNatter = ObjCreate("HNetCfg.NATUPnP")
If IsObj($theNatter) Then
DebugMsg("HNetCfg.NATUPnP.StaticPortMappingCollection now")
Local $mappingPorts = $theNatter.StaticPortMappingCollection
DebugMsg("HNetCfg.NATUPnP.StaticPortMappingCollection.Add now")
$mappingPorts.Add($InternalPort, $Protocol, $ExternalPort, @IPAddress1, 1, $Description)
; at this point we know that we have IGD device and we was unable to open port via HNetCfg.NATUPnP StaticPortMappingCollection.Add
; so lets try with MiniUPnP Project link to site http://miniupnp.free.fr/
; many distribution use this project
If $g_eventerror = 1 Then
If miniupnpcaddstatic($InternalIP, $InternalPort, $ExternalPort, $Protocol) Then
DebugMsg("ok port is open on router")
Return 1
EndIf
Else
DebugMsg("ok port is open on router")
Return 1
EndIf
EndIf
DebugMsg("fail to open on router")
Return 0
EndFunc ;==>UpnpPortMap


; this is taken from forum :)
Func FindDevice()
Dim $deviceFinder
Dim $DeviceType
Dim $Devices
Dim $Device
Dim $strDescDocURL
$deviceFinder = ObjCreate("UPnP.UPnPDeviceFinder")
$DeviceServices = ObjCreate("UPnP.UPnPServices")
$DeviceService = ObjCreate("UPnP.UPnPService")
$Device = ObjCreate("UPnP.UPnPDevice")
; we need any version of IGD device curently there only 1 and 2 :)
$DeviceType = "upnp:rootdevice"
$Devices = $deviceFinder.FindByType($DeviceType, 0)

DebugMsg('strDescDocURL:' & $strDescDocURL)
DebugMsg("Found # :" & $Devices.Count & " Devices")
If $Devices.Count = 0 Then
DebugMsg("Unable to find Device.")
EndIf
For $DeviceObj In $Devices
$deiceDescription = "Children " & $DeviceObj.Children & @CRLF & "Description " & $DeviceObj.Description & @CRLF & "FriendlyName " & $DeviceObj.FriendlyName & @CRLF & "HasChildren " & $DeviceObj.HasChildren & @CRLF & "IsRootDevice " & $DeviceObj.IsRootDevice & @CRLF & "ManufacturerName " & $DeviceObj.ManufacturerName & @CRLF & "ManufacturerURL " & $DeviceObj.ManufacturerURL & @CRLF & "ModelName " & $DeviceObj.ModelName & @CRLF & "ModelNumber " & $DeviceObj.ModelNumber & @CRLF & "ModelURL " & $DeviceObj.ModelURL & @CRLF & "ParentDevice " & $DeviceObj.ParentDevice & @CRLF & "PresentationURL " & $DeviceObj.PresentationURL & @CRLF & "RootDevice " & $DeviceObj.RootDevice & @CRLF & "SerialNumber " & $DeviceObj.SerialNumber & @CRLF & "Services " & $DeviceObj.Services & @CRLF & "Device URN Type " & $DeviceObj.Type & @CRLF & "UniqueDeviceName " & $DeviceObj.UniqueDeviceName & @CRLF & "Product Code - UPC " & $DeviceObj.UPC & @CRLF
DebugMsg("Found The Following Device(s)" & @CRLF & $deiceDescription)
Next
If $Devices.Count > 0 Then Return 1
Return 0
EndFunc ;==>FindDevice

Func miniupnpcaddstatic($InternalIP, $InternalPort, $ExternalPort, $Protocol)
Local $ResultMiniUpnp = Run(@ComSpec & " /c " & ' upnpc-static.exe -a ' & $InternalIP & " " & $InternalPort & " " & $ExternalPort & " " & $Protocol, @ScriptDir, @SW_HIDE, 0x2 + 0x4)
Local $upnpc_static_output
While 1
; read output from cmd command
$upnpc_static_output = StdoutRead($ResultMiniUpnp)
;exit on error
If @error Then ExitLoop
; send output to window
If $upnpc_static_output Then DebugMsg($upnpc_static_output)
WEnd
EndFunc ;==>miniupnpcaddstatic

; This is my custom error handler
; we don't want script to fail if HNetCfg.NATUPnP fails
Func MyErrFunc()
$HexNumber = Hex($oMyError.number, 8)
If @error Then Return
Local $msg = "!> COM Error with HNetCfg.NATUPnP!" & @CRLF & @CRLF & _
"err.description is: " & @TAB & $oMyError.description & @CRLF & _
"err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
"err.number is: " & @TAB & $HexNumber & @CRLF & _
"err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
"err.source is: " & @TAB & $oMyError.source & @CRLF & _
"err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
"err.helpcontext is: " & @TAB & $oMyError.helpcontext
DebugMsg($msg)
$g_eventerror = 1 ; something to check for when this function returns
Return
EndFunc ;==>MyErrFunc

Func DebugMsg($debugtext)
If $debug Then
Local $file = FileOpen(@ScriptDir & "" & $debuglog, 1)
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file." & $debuglog)
Return 0
EndIf
FileWriteLine($file, @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & "->" & $debugtext)
FileClose($file)
If $console Then ConsoleWrite($debugtext & @CR)
EndIf
Return 1
EndFunc ;==>DebugMsg


; #FUNCTION# ====================================================================================================================
; Name ..........: is_privateIP
; Description ...: Get if the IP is Private
; Syntax ........: is_privateIP($nIp)
; Parameters ....: $nIp - The IP to be checked
; Return values .: 1 - IP is Private
; 2 - IP is Public
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func is_privateIP($nIp)
Local $pri_addrs[5] = [ _
'10.0.0.0|10.255.255.255', _
'172.16.0.0|172.31.255.255', _
'192.168.0.0|192.168.255.255', _
'169.254.0.0|169.254.255.255', _
'127.0.0.0|127.255.255.255' _
];
Local $aAssign, $start, $end
Local $long_ip = ip2long($nIp)
If $long_ip = -1 Then Return SetError(1, 0, -1)
For $pri_addr In $pri_addrs
$aAssign = StringSplit($pri_addr, '|', 2);
$start = ip2long($aAssign[0])
$end = ip2long($aAssign[1])
; IF IS PRIVATE
If $long_ip >= $start And $long_ip <= $end Then Return True
Next

Return False;
EndFunc ;==>is_privateIP

; #FUNCTION# ====================================================================================================================
; Name ..........: ip2long
; Description ...: Convert the IPv4 into Long
; Syntax ........: is_privateIP($nIp)
; Parameters ....: $nIp - The IP to be checked
; Return values .:
; Author ........: Ptrex
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func ip2long($nIp)
$split = StringSplit($nIp, '.')
If $split < 4 Then Return -1
$long = ($split[1] * 16777216) + ($split[2] * 65536) + ($split[3] * 256) + ($split[4] * 1)
Return $long
EndFunc ;==>ip2long
Tell me if the code works for you too :)

Guinness,

Then I decided to give the program to my friends and do chat with them

But, that didnt work

This is the reason for port forwarding Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Ah, sorry PhoenixXL missed that point.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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