Sign in to follow this  
Followers 0
theguy0000

cannot recieve messages via tcp

14 posts in this topic

#1 ·  Posted (edited)

;CWM SERVER: VERSION 0.0.1:ALPHA
Opt("TrayAutoPause", 0)
#include <Constants.au3>
#include <GUIConstants.au3>

If ProcessExists(RegRead ("HKCU\Software\CWMessenger\Server", "version")&".exe") Then ProcessClose (RegRead ("HKCU\Software\CWMessenger\Server", "version")&".exe")

$tray_config = TrayCreateItem ("Server Configuration")
$tray_about = TrayCreateItem ("About CWM Server v0 Alpha")
TrayCreateItem ("")
$tray_disconn = TrayCreateItem ("Disconnect Server")

$CWMdir = RegRead ("HKCU\Software\CWMessenger", "CWMdir")
If $CWMdir = "" Then
    MsgBox (16, "CodeWiz Messenger Server", "Error: Could not read CWMdir from registry HKEY_CURRENT_USER\Software\CWMessenger")
    Exit
EndIf
$Port = 44844
Global $MaxConc = 100
Global $MainSocket = TCPStartServer($Port, $MaxConc)
If @error <> 0 Then Exit MsgBox(16, "Error", "Server unable to initialize.")
MsgBox (64, "CodeWiz Messenger Server", "Server started successfully at "&@IPAddress1)
IniWrite ($CWMdir&"\info.ini", "connected", "connected", 1)
Global Const $MaxLength = 512
Global $ConnectedSocket[$MaxConc]
Global $CurrentSocket = 0
Local $Track = 0
Global Const $MaxConnection = ($MaxConc - 1)
For $Track = 0 To $MaxConnection Step 1
    $ConnectedSocket[$Track] = -1
Next
While 1
    $ConnectedSocket[$CurrentSocket] = TCPAccept($MainSocket)
    If $ConnectedSocket[$CurrentSocket] <> - 1 Then
        $CurrentSocket = SocketSearch()
    EndIf
    $Track = 0
    For $Track = 0 To $MaxConnection Step 1
        If $ConnectedSocket[$Track] <> - 1 Then
            $Data = TCPRecv($ConnectedSocket[$Track], $MaxLength)
            If @error Then
                IniWrite ($CWMdir&"\info.ini", "connected", "disconnected", 0)
                MsgBox (48, "CodeWiz Messenger Server", "The CWM server has been disconnected.")
                ProcessClose (@AutoItPID)
            Else
                IniWrite ($CWMdir&"\info.ini", "connected", "connected", 0)
            EndIf
            If $Data <> "" Then
               ;CWM_msg_interp($Data, $ConnectedSocket[$Track])
                MsgBox (0, "CodeWiz Messenger Server", $Data)
            EndIf
        EndIf
    Next
    $tray_msg = TrayGetMsg()
    If $tray_msg = $tray_about Then CWM_about()
    If $tray_msg = $tray_config Then MsgBox ( 0, "CodeWiz Messenger Server", "Configuration is not ready yet." )
    If $tray_msg = $tray_disconn Then Exit
    If $tray_msg = $TRAY_EVENT_PRIMARYDOWN Then MsgBox ( 0, "CodeWiz Messenger Server", "Configuration is not ready yet." )
WEnd

;----------------
#region functions---------------------------------------------------------------------------------------------------------------------
;----------------

Func SocketSearch()
    Local $Track = 0
    For $Track = 0 To $MaxConnection Step 1
        If $ConnectedSocket[$Track] = -1 Then
            Return $Track
        Else
       ; Socket In Use
        EndIf
    Next
EndFunc ;==>SocketSearch
Func TCPSendMessageAll($ConnectionLimit, $Data)
    Local $Track = 0
    For $Track = 0 To $ConnectionLimit Step 1
        If $ConnectedSocket[$Track] <> - 1 Then TCPSend($ConnectedSocket[$Track], $Data)
    Next
EndFunc ;==>TCPSendMessageAll
Func TCPStartServer($Port, $MaxConnect = 1)
    Local $Socket
    $Socket = TCPStartup()
    If $Socket = 0 Then
        SetError (@error)
        return -1
    EndIf
    Global $Socket = TCPListen(@IPAddress1, $Port, $MaxConnect)
    If $Socket = -1 Then
        SetError(@error)
        Return 0
    EndIf
    SetError(0)
    Return $Socket
EndFunc ;==>TCPStartServer

;------------------------------------------

Func CWM_msg_interp ($inputmsg, ByRef $Track_br)
    $msg_split = StringSplit ($inputmsg, ",")
    If $msg_split[0] > 3 Then
        For $i=4 To $msg_split[0]
            $msg_split[3] &= $msg_split[$i]
        Next
    EndIf
    $IP = $msg_split[1]
    $Action = $msg_split[2]
    If $Action <> "CWM_SERVER_PING" Then $info = $msg_split[3]
    $temp_conn = TCPConnect ($IP, $Port)
    Switch $Action
        Case "CWM_ACT_REGISTER"
        ;[IP],CWM_ACT_REGISTER,[username] [password]
            $register_info = StringSplit ($info, " ")
            If IniRead ( $CWMdir&"\info.ini", "registered_users", $register_info[1], "" ) <> "" Then
                TCPSend ($temp_conn, @IPAddress1 & ",CWM_REGISTER_FAILED,Registration was unsuccessfull. The specified username already exists.")
            Else
                If IniWrite ($CWMdir&"\info.ini", "registered_users", $register_info[1], $register_info[2]) = 0 Then
                    TCPSend ($temp_conn, @IPAddress1 & ",CWM_REGISTER_FAILED,Registration was unsuccessfull. The server info file is mode R. please notify theguy0000@gmail.com.")
                    MsgBox ( 48, "CodeWiz Messenger Server", $IP & " tried to register with username "&$register_info[1]&" and password "&$register_info[2]&", but was unsuccessful because the info.ini file is Read-Only.")
                EndIf
            EndIf
        Case "CWM_ACT_LOGIN"
            $input = StringSplit ($info, " ")
            $username = $input[1]
            $password = $input[2]
            $user_ini = IniRead ($CWMdir&"\info.ini", "registered_users", $username, "")
            If $user_ini = "" Then
                TCPSend ($temp_conn, @IPAddress1 & ",CWM_LOGIN_FAILED,Incorrect username/Password")
            Else
                If $user_ini = $password Then
                    IniWrite ($CWMdir&"\info.ini", "logged_users", $username, $IP)
                    TCPSend ($temp_conn, @IPAddress1 & ",CWM_LOGIN_CONFIRM," & $username)
                Else
                    TCPSend ($temp_conn, @IPAddress1 & ",CWM_LOGIN_FAILED,Incorrect username/Password")
                EndIf
            EndIf
        Case "CWM_MSG_SEND"
            $input = StringSplit ($info, " ")
            If $input[0] > 3 Then
                For $i=4 To $input[0]
                    $input[3] &= $input[$i]
                Next
            EndIf
            $to = $input[1]
            $from = $input[2]
            $message = $input[3]
            $temp_conn2 = TCPConnect(CWM_User2Ip($to), $Port)
            TCPSend ($temp_conn2, @IPAddress1 & "CWM_MSG_RECV,"&$from&" "&$message)
        Case "CWM_SERVER_PING"
            TCPSend ($temp_conn, @IPAddress1&",CWM_SERVER_PONG")
        Case "CWM_CLIENT_BYE"
            TCPCloseSocket ($Track_br)
            $Track_br = -1
            $CurrentSocket = SocketSearch()
        Case "CWM_BOUNCEBACK"
            TCPSend ($temp_conn, $info)
        Case "CWM_SERVER_EXIT"
            MsgBox (16, "CodeWiz Messenger Server", $info)
            Exit
        Case "CWM_NOTIFY"
            MsgBox (0, "CodeWiz Messenger Server", $info)
    EndSwitch
EndFunc

Func CWM_User2Ip($user)
    Return IniRead ( $CWMdir&"\info.ini", "logged_users", $user, "")
EndFunc

Func CWM_about()
    MsgBox (0, "About CodeWiz Messenger", "CodeWiz Messenger Server v0 Alpha"&@CRLF&"Version 0.0.1-ALPHA"&@CRLF&"Coded by Matt Roth"&@CRLF&"Last Updated 1/22/2006"&@CRLF&""&@CRLF&"PLEASE NOTE: This software is state Alpha, and is subject to being unstable."&@CRLF&"Please send any bugs or other problems to Matt Roth <theguy0000@gmail.com>")
EndFunc
#cs
Func CWM_Config()
    Local $gui_msg, $status_label, $status
    GUICreate ("CWM Server Configuration")
    $status_label = GUICtrlCreateLabel ("CWM Server is:", 10, 10)
    If TCPSend(
#ce
Func OnAutoItExit()
    MsgBox (0, "CodeWiz Messenger Server", "AutoItExit requested. Click OK to disconnect.")
    TCPSendMessageAll ($MaxConnection, @IPAddress1 & ",CWM_MSG_RECV,Global_Server_Message Server has been disconnect due to server exit request.")
    TCPCloseSocket ($Socket)
EndFunc

as you can see, i took out the CWM_msg_interp() and instead made it so that it would msgbox any message recieved. A friend of mine is connected to me using telnet on port 44844, but I can't recieve his messages. Both of us have routers, and we both forwarded port 44844. The server just does...nothing, no messages recieved. What am I doing wrong here?

(I dont exactly remember, but i think this was based off of AutoItSmith's remote server beta...

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites



sorry but...BUMP

why wont anyone help me?


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

sorry but...BUMP

why wont anyone help me?

Eat me and drink me and all these things shall be given unto you.

Share this post


Link to post
Share on other sites

Don't listen to Uten. He is a deciever. He choseth the path which is unholy.Woe to him. He shall have no part in my kingdom.

Share this post


Link to post
Share on other sites

Don't listen to Uten. He is a deciever. He choseth the path which is unholy.Woe to him. He shall have no part in my kingdom.

I think this guy need banning.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Off the topic, but funny how this guy Airvent, joined at the same time as Guidosoft's little rant yesterday of leaving the forum forever.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I think this guy need banning.

agreed.

ok ill try that Uten, but i need to find a telnet client...

Edit: I tried with PuTTYtel but it wont connect to 127.0.0.1 or localhost. What should I put in for the ip? because i cant even connect (while my friend can using my public ip)

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

localhost and 127.0.0.1 with putty should work. Shure you used the telnet protocol and assigned the right port?

I dont have the time now but if I get the time later tonight I'll take a look at your project.

Share this post


Link to post
Share on other sites

localhost and 127.0.0.1 with putty should work. Shure you used the telnet protocol and assigned the right port?

I dont have the time now but if I get the time later tonight I'll take a look at your project.

nope. just get "Connection Refused".

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

I don't seem to get the time to do the test I wanted (AutoIt dont work so good on a *nix) but it just occured to me that you might run XP and the buildtin firewall? Any other firewall? I have experienced Norton internet security to be a bit to secure :)

Share this post


Link to post
Share on other sites

Found it. You return the Local $Socket and not your intended Global $Socket. Local has precedence inside the function.

Actualy using Global in a function is not so clever (my opinion). I also like to use some hungarian notation on Globals. But that is me, and I'm not a slave of it.

Change your Local $Socket and usage to Local $foo or somthing and you should be set. :)

Func TCPStartServer($Port, $MaxConnect = 1)
    Local $Socket; NOTE! UPS! SHIT!
    $Socket = TCPStartup()
    If $Socket = 0 Then
        SetError (@error)
        return -1
    EndIf
    Global $Socket = TCPListen(@IPAddress1, $Port, $MaxConnect); NOTE! UPS! SHIT!
    If $Socket = -1 Then
        SetError(@error)
        Return 0
    EndIf
    SetError(0)
    Return $Socket
EndFunc;==>TCPStartServer

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

you mean like this?

Func TCPStartServer($Port, $MaxConnect = 1)
    Local $SocketLoc
    $SocketLoc = TCPStartup()
    If $SocketLoc = 0 Then
        SetError (@error)
        return -1
    EndIf
    Global $Socket = TCPListen(@IPAddress1, $Port, $MaxConnect)
    If $Socket = -1 Then
        SetError(@error)
        Return 0
    EndIf
    SetError(0)
    Return $Socket
EndFunc;==>TCPStartServer
Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

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