Sign in to follow this  
Followers 0
Glyph

Changing TCP port?

5 posts in this topic

Case $msg = $savesets
            GUICtrlSetState($savesets,$gui_disable)
            _GUICtrlStatusBar_SetText($hStatus, "Busy...")
            Sleep(1000)         
            If GUICtrlRead($comport) = IniRead("untitled.db", "Server", "Port", "63336") Then
                ;do nothing
            Else
                $Port = GUICtrlRead($comport)
                TCPShutdown()
                $MainSocket = TCPStartServer($Port, $MaxConnection)
                _GUICtrlStatusBar_SetText($hStatus, "Port: " & $Port, 1)
                _GUICtrlStatusBar_SetText($hStatus, "Ready")
                IniWrite("untitled.db", "Server", "Port", GUICtrlRead($comport))
                GUICtrlSetData($serverport,GUICtrlRead($comport))
            EndIf

if the port changed and you hit savesets then it will shut down tcp and change the port to a new one and start listening o nthat port.

problem is, it works and all when you switch to a new port, but if you switch back to the original port, it won't work.

i also tested this, i changed ports then tried connecting to the last port on client and it connected, meaning the ports still open.

so how do i close the tcp port?? TCPShutdown() isn't working.


tolle indicium

Share this post


Link to post
Share on other sites



Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@

Try to analyze your problem using the "Netstat -an" command.

See if the previous port is not still in use ?

Changing a port might not be the same as closing it ?!

regards,

ptrex

thanks for helping,

already tried a netstat -n -b

no connections open.

i figured a tcpshutdown() would clear all of the tcp connections or ports that were open?

I do a tcpshutdown, then i reopen the tcp connection on a new port, with a function.

Is there a specific way to close the port??

Edited by BackStabbed

tolle indicium

Share this post


Link to post
Share on other sites

@BackStabbed

If the port is not listed anymore it should be free and released.

Try look afterwards again to see of the application or script is listed as listening to that port.

If not than the TCPStart did not register properly.

First of all you need to analyse. Wether it is a Port conflict or wether it is a TCPStart problem.

Regards

ptrex

Share this post


Link to post
Share on other sites

No connections relating to the application after running, after connecting to the server there is.

But basically, i run the program test the port, it works.

then i change ports, still works on the new port, but if i change it yet again to the original port, it fails to open a connection.

but the client can still connect to that port, but its not connecting to the server after that.... it's like it's connecting to nothing...

heres the tcp codes.

(note: i did try debugging this, but i can't figure anything out. i just dont see anything wrong with this...)

Global $Port = IniRead("untitled.db","Server","Port","63336")
Global $MainSocket = TCPStartServer($Port, $MaxConc)
If @error <> 0 Then Exit MsgBox(16, "Error", "Server unable to initialize.")




        Case $msg = $savesets
            GUICtrlSetState($savesets,$gui_disable)
            _GUICtrlStatusBar_SetText($hStatus, "Busy...")
            Sleep(1000)         
            If GUICtrlRead($comport) = IniRead("untitled.db", "Server", "Port", "63336") Then
                ;do nothing
            Else
                $Port = GUICtrlRead($comport)
                TCPShutdown()
                $MainSocket = TCPStartServer($Port, $MaxConnection)
                _GUICtrlStatusBar_SetText($hStatus, "Port: " & $Port, 1)
                _GUICtrlStatusBar_SetText($hStatus, "Ready")
                IniWrite("untitled.db", "Server", "Port", GUICtrlRead($comport))
                GUICtrlSetData($serverport,GUICtrlRead($comport))
            EndIf
            
            IniWrite("untitled.db", "Server", "Password", GUICtrlRead($serverpass))
            If BitAND(GUICtrlRead($btips), $GUI_CHECKED) = $GUI_CHECKED Then
                IniWrite("untitled.db", "Server", "BTips", "1")
            Else
                IniWrite("untitled.db", "Server", "BTips", "0")
            EndIf
            _GUICtrlStatusBar_SetText($hStatus, "Ready")
            GUICtrlSetState($savesets,$gui_enable)
            MsgBox(0,"Untitled "&$ver,"Settings have been saved!")

Func TCPStartServer($Port, $MaxConnect = 1)
    Local $Socket
    $Socket = TCPStartup()
    Select
        Case $Socket = 0
            SetError(@error)
            Return -1
    EndSelect
    $Socket = TCPListen(@IPAddress1, $Port, $MaxConnect)
    Select
        Case $Socket = -1
            SetError(@error)
            Return 0
    EndSelect
    SetError(0)
    Return $Socket
EndFunc   ;==>TCPStartServer

Port may not be changed back to a previous port

e.g. Changed to port 65 from 63336 then again to port 58.

You will not be able to use port 65 63336 or 58 over again, if you decide to change.

Must be a new port each time.


tolle indicium

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