Jump to content
Sign in to follow this  

Error 10049 with TCPListen

Recommended Posts

Hey all

I'm writing my first server/client program for practice and I've run into a bit of a wall.

I think I've done everything correctly but no matter what I do I always get error 10049 which is WSAEADDRNOTAVAIL

I know that the value that is being sent for the IP and port is and 12030, of which is the valid address of the machine I'm on and an unused port.

It's line 31 (in the serverStart function) where the bad call happens

Heres my code, sorry if it's terrible spaghetti code by I'm on my own and a rookie:

#include <GUIConstantsEx.au3>

$ip = @IPAddress1;sets the variable $ip to the first ip address in the adapter. Sometimes this is but we want the local IP
$port = 12030;sets the port to a random number between 12000 to 13000
Dim $socketdata[4][4]
$switchbit = 0
$flag1 = 0 

;Checks to make sure that the function to automatically set the IP address did not return
if $ip = "" Then ;and if it did, then set it to the next IP in the list (as some machines have localhost first)
    $ip = @IPAddress2  

;Create a GUI for setting the various settings
GUICreate("Server Properties", 280, 200)
$ipcontrol = GUICtrlCreateInput($ip, 35, 25, 150)
GUICtrlCreateLabel ("IP:", 15, 25)
$portcontrol = GUICtrlCreateInput($port, 35, 50, 50)
GUICtrlCreateLabel ("Port:", 5, 50)
GUICtrlCreateLabel ("Don't forget to forward your port in your routers settings", 10, 80)
$start = GUICtrlCreateButton("Start Server", 50, 120, 75, 50)
$stop = GUICtrlCreateButton("Stop Server", 150, 120, 75, 50)

Func serverStart();Start TCP Services and listen on a port 
$ip = GUICtrlGetState($ipcontrol)
$port = GUICtrlGetState($portcontrol)
$TCPListen = TCPListen ($ip, $port, 1)
If $TCPListen = -1 Then
    MsgBox(1,"TCP Error", @error )

while 1
    $msg = GUIGetMsg()
    Case $msg = $start
        $switchbit = 0
    Case $msg = $GUI_EVENT_CLOSE
    Case $msg = $stop
        $switchbit = 0 

Func acceptConnection()
    if $switchbit = 0 Then Return
$Accept = TCPAccept($TCPListen)

Func serverStop()

Func Leave()
Edited by centizen

Share this post

Link to post
Share on other sites

Thanks for your help Andreik, it cleared up the issue I posted about. Unfortunately however, I am now getting a different error code, 10048. Apparently this one means that the port I'm trying to listen on is already in use, but no matter which port I try, (All forwarded in the router beforehand) the error still persists. This is true no matter which computer I run it on as well. I really don't want to give up on this but I can't figure out this new problem either. Is there anything else you can see that might be causing this issue?

And thanks very much for your help in the first place.

Share this post

Link to post
Share on other sites

Thank you so much andreik, the last thing you said was the clicker. I realized that in my If/Else for checking to see if TCPListen returned an error, it would only notify me if the function returned -1, and say nothing if it worked, making me double click the button. I added Elseifs for possible error return values and then made an else congratulating me on getting it to work.

It worked!!

Thanks again, you've been a great help.

Edited by centizen

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  

  • Create New...