Jump to content
Sign in to follow this  
PhiHungTF

AutoIt & Socketio cannot receive and send messages

Recommended Posts

i'm trying to translate these Javascript codes into AutoIt codes but i don't know where are the problems, plz help

There is my Autoit Client code, it's not working:

#include <socketIO.au3>
_Io_DevDebug(True)

; Connect to server
Global $_socket = _Io_Connect("127.0.0.1", 8080, True)
If @error Then
    MsgBox(0, "Failed to connect", @error)
    Exit
EndIf

; Register io events
_Io_on("message", Message)


_Io_Emit($_socket, "message", "abc")
; Start the main loop
While _Io_Loop($_socket)
WEnd

; Io event Callbacks
Func Message(ByRef $socket, $message)
    MsgBox(0, 0, $message) ;### Debug MSGBOX
EndFunc

Func _quit()
    Exit
EndFunc

Im using this Autoit SocketIO.au3 library (i dont know it will work or not): https://www.autoitscript.com/forum/topic/188991-socket-io-an-event-driven-tcp-udf-realtime-chat-example/

SERVER (working):

var io = require('socket.io').listen(8080);

io.sockets.on('connection', function (socket) {
  socket.send('hi');
    socket.on('message', function (data) {
        io.sockets.send(data + 'cde');
        console.log(data);
    });
});

CLIENT (working):

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
    var socket = io.connect('http://localhost:8080');
    socket.on('message', function (message) {
        alert(message); 
    });

    socket.send('abc');

</script>

I dont know why my Autoit code didn't work, it ran but didn't do anything, plz tell how to fix it. P/s: Sorry about my stupid words, This is my first question and my first language isn't English. Thanks for reading :)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...