🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
7 messages
7 total messages Started by AlexB Fri, 30 Nov 2007 12:45
MailSlots and messages longer than 424 bytes
#820
Author: AlexB
Date: Fri, 30 Nov 2007 12:45
11 lines
1085 bytes
Hi all.

Mailslot (on Win2k, XP) ignores messages longer than 424 if I specify
computer name (even on the same computer): \\ComputerName\maislot\box

But MSDN says that I can send messages up to 64K if they are not
broadcast.

What is the matter?
-- 
Alex
Re: MailSlots and messages longer than 424 bytes
#828
Author: AlexB
Date: Sun, 02 Dec 2007 10:31
16 lines
1287 bytes
AlexB wrote:

> Mailslot (on Win2k, XP) ignores messages longer than 424 if I specify
> computer name (even on the same computer): \\ComputerName\maislot\box
> But MSDN says that I can send messages up to 64K if they are not
> broadcast.
> What is the matter?

I've found the answer:
messages with length>424 bytes need installation of NetBEUI.

XP (unlike W2k) doesn't support this old protocol but driver is still
available for manual installation (search on microsoft.com for
'NetBEUI').
-- 
Alex
Re: MailSlots and messages longer than 424 bytes
#835
Author: AlexB
Date: Mon, 03 Dec 2007 12:33
10 lines
1048 bytes
AlexB wrote:

> I've found the answer:
> messages with length>424 bytes need installation of NetBEUI.

Now I see the next threshold: 1365 bytes.
It looks as impassable :-( 

-- 
Alex
Re: MailSlots and messages longer than 424 bytes
#839
Author: Bob Gonder
Date: Tue, 04 Dec 2007 03:59
5 lines
1060 bytes
AlexB wrote:

>It looks as impassable :-( 

Show your actual code ?
Re: MailSlots and messages longer than 424 bytes
#840
Author: AlexB
Date: Tue, 04 Dec 2007 05:01
69 lines
2903 bytes
Bob Gonder wrote:

> Show your actual code ?

It's part of JVCL's JvgMailSlot (slightly modified):

procedure TJvgMailSlotServer.Open;
begin
 <...>
// no matter what timeout I specify here (0 or MAILSLOT_WAIT_FOREVER)
  FHandle:=CreateMailSlot(PChar('\\.\mailslot\'+MailSlotName),0,0,nil);
  if FHandle=INVALID_HANDLE_VALUE then <Err...>
  FTimer.Enabled:=True;
end;

procedure TJvgMailSlotServer.OnTimer(Sender: TObject);
var
  MsgSize: DWORD;
  MsgNumber: DWORD;
  Read: DWORD;
  Buffer: Pointer;
begin
  // Determining if there's message
  if not GetMailSlotInfo(FHandle, nil, MsgSize, @MsgNumber, nil)
  then <Err...> 
  else
    if MsgSize<>MAILSLOT_NO_MESSAGE
    then begin
      FData.Size:=MsgSize; // Allocate memory
      Buffer:=FData.Memory;
      // Reading message
      if ReadFile(FHandle, Buffer^, MsgSize, Read, nil)
      then <OK...>
      else <Err...>
    end;        
end;

function TJvgMailSlotClient.Send
 (const MessageData; MessageLength: integer): Boolean;
var
  FHandle: THandle;
  Written: DWORD;
begin
  if FServerName='' then FServerName:='.\'; // the same computer
  FHandle:=CreateFile(PChar('\\'+FServerName+'\mailslot\'+
FMailSlotName), GENERIC_WRITE, FILE_SHARE_READ, nil, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);
  Result:=FHandle<>INVALID_HANDLE_VALUE;
  if Result then
  begin
    Result:=WriteFile(FHandle, MessageData, MessageLength, Written,
nil);
    CloseHandle(FHandle);
  end;
end;

Send works normally (always returns true).
Local messaging ('.\') with length up to 64K work without problems.
Network messaging (i.e. where name of computer was specified):
 - up to 425 bytes in any case
 - up to 1365 bytes after installation of NetBEUI.

Server never see network messages longer then 1365 bytes
(i.e. MsgSize=MAILSLOT_NO_MESSAGE).

MSDN says that for long messages (up to 64K) mailslots require "SMB
session". I have no idea how to check the presence of SMB session.
-- 
Alex
Re: MailSlots and messages longer than 424 bytes
#844
Author: Bob Gonder
Date: Tue, 04 Dec 2007 17:06
58 lines
3200 bytes
AlexB wrote:

>It's part of JVCL's JvgMailSlot (slightly modified):

First, I have to wonder why you are asking Java/VCL/Delphi questions in a C++ group...

>procedure TJvgMailSlotServer.OnTimer(Sender: TObject);

Why is this on a timer?
There are much better ways such as threads and Read Events.

>var
>  MsgSize: DWORD;
>  MsgNumber: DWORD;
>  Read: DWORD;
>  Buffer: Pointer;
>begin
>  // Determining if there's message
>  if not GetMailSlotInfo(FHandle, nil, MsgSize, @MsgNumber, nil)

I don't know Delphi, but that looks quite wrong.
I would expect
	GetMailSlotInfo(FHandle, nil, @MsgSize, @MsgNumber, nil)

>      FData.Size:=MsgSize; // Allocate memory
>      Buffer:=FData.Memory;
>      // Reading message
>      if ReadFile(FHandle, Buffer^, MsgSize, Read, nil)

Similarly
      if ReadFile(FHandle, Buffer^, MsgSize, @Read, nil)

>    Result:=WriteFile(FHandle, MessageData, MessageLength, Written,nil);
    Result:=WriteFile(FHandle, MessageData, MessageLength, @Written,nil);

>Send works normally (always returns true).
>Local messaging ('.\') with length up to 64K work without problems.
>Network messaging (i.e. where name of computer was specified):
> - up to 425 bytes in any case
> - up to 1365 bytes after installation of NetBEUI.

In other words, One Packet.
You need to prefix your message with a message size,
and have the server keep reading until it gets all of the message.
Then have the sender break up the message into packet size.

>Server never see network messages longer then 1365 bytes
>(i.e. MsgSize=MAILSLOT_NO_MESSAGE).
>
>MSDN says that for long messages (up to 64K) mailslots require "SMB
>session". I have no idea how to check the presence of SMB session.

<quote>
The data in a mailslot message can be in any form, but cannot
be larger than 424 bytes when sent between computers. To send
messages that are larger than 424 bytes between computers,
use named pipes or Windows Sockets instead.</quote>
http://msdn2.microsoft.com/en-us/library/aa365130.aspx
Re: MailSlots and messages longer than 424 bytes
#845
Author: AlexB
Date: Wed, 05 Dec 2007 07:17
62 lines
2988 bytes
Bob Gonder wrote:

> I have to wonder why you are asking Java/VCL/Delphi questions
> in a C++ group...

As you can see initially it was question about API problem (language
independent).

> > procedure TJvgMailSlotServer.OnTimer(Sender: TObject);
> 
> Why is this on a timer?
> There are much better ways such as threads and Read Events.

Yes, but timer is enough for beginning.

> > var
> >  MsgSize: DWORD;
> >  MsgNumber: DWORD;
> >  Read: DWORD;
> >  Buffer: Pointer;
> > begin
> >  // Determining if there's message
> >  if not GetMailSlotInfo(FHandle, nil, MsgSize, @MsgNumber, nil)
> 
> I don't know Delphi, but that looks quite wrong. I would expect
> 	GetMailSlotInfo(FHandle, nil, @MsgSize, @MsgNumber, nil)

No, code is correct. In windows.pas:

function GetMailslotInfo
 (hMailslot: THandle; lpMaxMessageSize: Pointer;
  var lpNextSize: DWORD; lpMessageCount, lpReadTimeout: Pointer):
    BOOL; stdcall;

lpNextSize (MsgSize in code) is 'var' (i.e. reference, not pointer).

> > Send works normally (always returns true).
> > Local messaging ('.\') with length up to 64K work without problems.
> > Network messaging (i.e. where name of computer was specified):
> > - up to 425 bytes in any case
> > - up to 1365 bytes after installation of NetBEUI.
> 
> In other words, One Packet.

Yes.

> You need to prefix your message with a message size,
> and have the server keep reading until it gets all of the message.
> Then have the sender break up the message into packet size.

No any packet at all if L>425 (or 1365). Manual chUnk by chUnk sending
is not so good (delivery is not guaranteed).

> The data in a mailslot message can be in any form, but cannot
> be larger than 424 bytes when sent between computers.
> http://msdn2.microsoft.com/en-us/library/aa365130.aspx

Thank you for this information. Here I see this explicit limitation for
the first time; there is no such limitation in my local (outdated) MSDN.

-- 
Alex
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads