Sign in to follow this  
Followers 0
KickStarter15

[Solved] SendMsg() not showing to other users

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



@KickStarter15

What's the issue? :)


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@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

Share this post


Link to post
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

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