Jump to content

MailSlot


trancexx
 Share

Recommended Posts

This is great trancexx, but one of the most interesting things that you didn't mention is that this works across a network.

There's another good link here which explains some of this. If you use this over a network then pay attention to the caveats in that link.

Thanks for this thread. ;)

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi, Trancexx !

I had played with Mailslot, in past.

Your functions are better than my "hardcoded" tests.

(your) mailslot is compatible with the waitfor command-line from Windows, or my others libs (i.e. in Python) (I tested the two cases).

Thanks (and sorry for my bad english).

Two little things:

- read a Mailslot without data give, on my 7, a "Autoit memory allocation error".

- your functions are OK with ASCII messages, but, when I tested messages in UTF-8 or CP1252, with diacritics, there are some worries (not very important)

@-salutations

--

Michel Claveau

Edited by Michel Claveau
Link to comment
Share on other sites

Hi, Trancexx !

I had played with Mailslot, in past.

Your functions are better than my "hardcoded" tests.

(your) mailslot is compatible with the waitfor command-line from Windows, or my others libs (i.e. in Python) (I tested the two cases).

Thanks (and sorry for my bad english).

Two little things:

- read a Mailslot without data give, on my 7, a "Autoit memory allocation error".

- your functions are OK with ASCII messages, but, when I tested messages in UTF-8 or CP1252, with diacritics, there are some worries (not very important)

@-salutations

--

Michel Claveau

No, thank you.

"Autoit memory allocation error" is my mistake. I've located a mistake and will correct it... eventually. The problem is _MailSlotCheckForNextMessage() function. Corrected would be:

If $aCall[3] = -1 Or Not $aCall[4] Then
        Return 0
    Else
        Return $aCall[3]
    EndIf

instead of current:

If $aCall[3] = -1 Then
        Return 0
    Else
        Return $aCall[3]
    EndIf

Same thing can be done with _MailSlotGetMassageCount(), but it shouldn't strictly be necessary.

Unicode problem is likely not related to these functions.

You can always read binary and interpret it the way you like it, as I'm sure you are aware of.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

This is great. I found only one nitpicking issue:

_MailSlotGetMassageCount()

Perhaps you meant:

_MailSlotGetMessageCount()

Just a typo, good work though.

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

Hi, all !

Here a very simplist example, who show dialog/drive (with) a Batch.

#include "MailSlot.au3"

writebat()

run("C:\MStest.bat")

Sleep(2000)

Global $sMailSlotName = "\\.\MailSlot\waitfor.exe\SIGNAL"

_SendMail($sMailSlotName,"1")

Sleep(2000)

_SendMail($sMailSlotName,"2")

Sleep(4000)

_SendMail($sMailSlotName,"3")

Exit

Func _SendMail($sMailSlotName,$sDataToSend)

_MailSlotWrite($sMailSlotName, $sDataToSend, 1)

Switch @error

Case 1

MsgBox(48, "MailSlot error", "Account that you try to send to likely doesn't exist!")

Case 2

MsgBox(48, "MailSlot error", "Message is blocked!")

Case 3

MsgBox(48, "MailSlot error", "Message is send but there is an open handle left." & @CRLF & "That could lead to possible errors in future")

Case 4

MsgBox(48, "MailSlot error", "All is fucked up!" & @CRLF & "Try debugging MailSlot.au3 functions. Thanks.")

Case Else

;MsgBox(64, "MailSlot", "Sucessfully sent!")

EndSwitch

EndFunc ;==>_SendMail

Func writebat()

$b=""

$b &= "@echo off " & @CRLF

$b &= "echo Etape_1" & @CRLF

$b &= "waitfor /T 60 SIGNAL"& @CRLF

$b &= "echo Etape_2" & @CRLF

$b &= "waitfor /T 60 SIGNAL"& @CRLF

$b &= "echo Etape_3" & @CRLF

$b &= "waitfor /T 60 SIGNAL"& @CRLF

$b &= "echo Etape_4" & @CRLF

$b &= "pause Ended" & @CRLF

$f=FileOpen("C:\MStest.bat",2)

FileWrite($f,$;)

FileClose($f)

EndFunc

MStest.au3

Edited by Michel Claveau
Link to comment
Share on other sites

  • Moderators

trancexx,

Well up to your usual standard. ;) Thank you for sharing.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi, all !

Here a very simplist example, who show dialog/drive (with) a Batch.

I think that got a bit messed up! I think this is what you tried to post.

Code removed now that Michel has corrected his post.

I'll delete this post when you've corrected yours.

I decided not to delete this post or the next one makes no sense.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Congratulations to you!!!

I have successfully implemented your UDF across a network, and you Sir,

have enabled me to solve a problem I've had for a while now and you've

made me a very happy man! :evil:

Thanks for your work, and for sharing. :evil:

Five stars from me ;)

Edited by dmob
Link to comment
Share on other sites

hi trancexx,

you saved my ass ;)

i just thought about fifo buffering tcp packets and crawled the forum a bit, found the mmap udf but this wasn't the right thing :evil:

now with your udf i can go on with my project thank you very much.

Best regarrds,

JR.

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Link to comment
Share on other sites

  • 1 year later...

@trancexx

Hello,

I see that your UDF will solve my problem with function TCPConnect() it takes on average 20 seconds to return control to the program if no connection found (...) Send Broadcast messages (TCP does not support broadcast, UDP does, but not using NAT), simple to implement, there is no doubt that it is better than the TCC/UDP (at least for me).

Already solved 90% of my problems, but I have left some questions:

1 - Records smaller than 425 bytes?!? Why? No way around?

2 - Transferring files (binaries)?

Thank you for your attention.

Edited by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Wow! I had never paid attention to the item "NamedPipes Management " in the AutoIt help file!

And using NamedPipes we can transfer more than the 425 bytes of the mailslot...

Edit: http://www.codeproject.com/KB/threads/Win32IPC.aspx

@trancexx, you could create an example of using "NamedPipes" the same way that the mailslot?

Edited by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

@trancexx

Hello,

I see that your UDF will solve my problem with function TCPConnect() it takes on average 20 seconds to return control to the program if no connection found (...) Send Broadcast messages (TCP does not support broadcast, UDP does, but not using NAT), simple to implement, there is no doubt that it is better than the TCC/UDP (at least for me).

Already solved 90% of my problems, but I have left some questions:

1 - Records smaller than 425 bytes?!? Why? No way around?

2 - Transferring files (binaries)?

Thank you for your attention.

Well hello there.

There shouldn't be 425 byte limit. You are probably doing something wrong, maybe sending/reading as string with null terminator as 425th character.

You can transfer binary data, there is a flag for that, default even. Don't limit your self on my examples, they are there just to show the main principle of communication.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Well hello there.

There shouldn't be 425 byte limit. You are probably doing something wrong, maybe sending/reading as string with null terminator as 425th character.

You can transfer binary data, there is a flag for that, default even. Don't limit your self on my examples, they are there just to show the main principle of communication.

"...Mailslot messages can be of around 400 bytes only.", please check this link: http://www.codeproject.com/KB/threads/Win32IPC.aspx

"...cannot be larger than 424 bytes when sent between computers.", and this: http://msdn.microsoft.com/en-us/library/aa365130%28v=vs.85%29.aspx

Edited by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

  • Moderators

jscript,

If you look at the link martin provided in post #2, you read this:

"Boring technical note from Microsoft

Records smaller than 425 bytes are sent using datagrams. Records larger than 426 bytes are sent using a connection-oriented transfer over an SMB session. Connection-oriented transfers are limited to one-to-one communication from one client to one server. Note that Windows does not support records that are 425 or 426 bytes."

Certainly I have never had any trouble sending more than 425 bytes to multiple receiver scripts using the mailslot. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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