Jump to content

[Solved] SendMsg() not showing to other users


Recommended Posts

Hi Experts,

I have this old script from my former colleague and when trying to modify it, it will no longer working. I was task to modify this code for the production to use it but can't figured it out why it was not sending the message after inputting my message in inputbox.

So far from my modification:

#include <GuiConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <ColorConstantS.au3>

Global $hGui, $hEdit, $hInp, $hBtn, $rsock, $ssock, $recv, $UserInput
Global $port = 1018
Global $Broadcast = @IPAddress1

;start main function
GUICtrlSetBkColor($hGui, $COLOR_RED)

_main()

Func _main()
    ;create gui
    $hGui = GUICreate("",300,239)
    GUISetOnEvent($GUI_EVENT_CLOSE, "hGuiClose")
    $hEdit = GUICtrlCreateEdit("Welcome, Visitors",0,0,316,220,BitOR($ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL,$ES_AUTOVSCROLL))
    _GUICtrlEdit_SetLimitText($hEdit,99999999999999)
    $hInp = GUICtrlCreateInput("",0,219,250,20)
    $hBtn = GUICtrlCreateButton("Send",310,220,30,20,$BS_DEFPUSHBUTTON)

    ;display gui
    GUISetState()

    ;start winsock for udp
    UDPStartup()
    
    ;bind a socket to the port for listening
    $rsock = UDPBind(@IpAddress1,$port)
    
    If @error <> 0 Then Exit
    ;send message informing of online status
    SendMsg("-"&@UserName&" is online.")
    
    ;start gui loop
    Do
        $recv = UDPRecv($rsock,1024)
        If $recv <> "" Then
            Print($recv)
            _WinAPI_FlashWindowEx($hGui, 2)
        EndIf
        $msg = GUIGetMsg()
        If $msg = $hBtn Then
            $buffer = GUICtrlRead($hInp)
            If $buffer <> "" Then
                GUICtrlSetData($hInp,"")
                SendMsg("<"&@UserName&">: "&$buffer & " (" & @HOUR & ":" & @MIN & ":" & @SEC & ")")
             EndIf
        EndIf
     Until $msg = $GUI_EVENT_CLOSE
    Exit
EndFunc ;==> _main

Func SendMsg($txtMsg)
        $ssock = UDPOpen($Broadcast,$port)
        If @error = 0 Then
            UDPSend($ssock,$txtMsg)
        EndIf
        UDPCloseSocket($ssock)
EndFunc ;==> SendMsg

Func Print($txtMsg)
    _GUICtrlEdit_AppendText($hEdit,@CRLF&$txtMsg)
EndFunc ;==> Print

Func hGuiClose()
    ;send message informing of offline status
    SendMsg("-"&@UserName&" has gone offline.")
    UDPShutdown()
EndFunc ;==> OnAutoItExit

Can't locate the working code from our former colleague who resigned a while ago and I'm having hard time modifying it.

 

Need you help with this Experts, thanks in advance.

KS15

 

 

Edited by KickStarter15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

Mabe because you use the wrong broadcast IP?

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

@FrancescoDiMuro,:D I think the issue was when other user use this program, they can type-in their message but their message is not showing to another user that is also using the program.

When trying it in my own PC same thing as the other user could not see my message. I tried checking it and testing it but still could not locate the cause.

 

@funkey, I think broadcast IP is good and i think there's no problem with it. This program is already used in production and is working fine. But when I modified it with some thing to add like, change username to full name, get their ID, and other things (which is my task right now) and it's no longer working.:(

 

Here is the scenario with this issue: "The program was saved at the server where all users can call it and run it."

Now, I am the user1 with IP of 172.0.0... opening the program and at the same time other user which user2 was using it as well with IP 172.0.1.... then user2 type-in a message to that program and enter to send. But me as the user1 could not see his/her message. In return, he/she could not also see mine as well.

This program is like a chat group but localized usage only (which is for production use only).

Edited by KickStarter15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

Hi Guys,

I got it, @funkey was right. It's my braodcast IP that has issue... Below is the code that fixes the issue..:lol:

$Broadcast = StringLeft(@IPAddress1, StringInStr(@IPAddress1, ".", 0, 3)) & "255"

Thank you for checking on my post guys...:D

KS15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

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