怎样接受net send 发送的消息(100分)

  • 主题发起人 主题发起人 yabbi
  • 开始时间 开始时间
Y

yabbi

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在知道在 Win2K的 日志中可以看到该事件。
可是用程序怎么捕捉事件?
或者使用什么API
[:)]
 
只要是Win2K操作系统就能直接收到消息并用对话框显示出来.
 
是一个系统服务接受这个这个消息,
我想可能是采用的邮槽来处理的,如果知道这个邮槽名字就可能能接受到这个消息
 
WinPopup
This here started with me getting fed up with the way WinPopup was working. I
always had this big visible block in my taskbar in Windows 95, and therefore I
often did not use my WinPopup - which the others often thought irritateing.
Also the fact that I was using non English letters in my login name, which made
the Danish versions (not the English versions) of WinPopup ignore sending
messages to me, even I had started WinPopup.

So what do a programmer do? He deside to make his own version of WinPopup! Yes,
but how?

I looked around in the WIN32 API for functions which were meeting the
functionabillity of WinPopup, and found mailslots. Mailslots is a conection
less service, which is made directly accessible in Windows 95 and NT. The
mailslots create a kind of virtual file on your machine (when your are the
owner of a mailslot), where other machines can write into.

The mailslots should be tried out, so I implemented the functionallity in a
program, and it all looked like the functionallity of WinPopup, but I was
still not any further because a mailslot have a name, and what name did
Microsoft choose to there system messages (Printer notification and WinPopup
messages) - I could not guess :(

I created a usable mailslot object, and made it avalible on the Internet so
other could user my work now when I coudn't (wasn't that nice of me?). After
a week - or so - someone wrote to me and asked if I knew how he could send a
message to WinPopup :( - and ofcource I cound not help him. But this guy
started searching himself, and a few days later he mailed me the "secret"
mailslot name "messngr".

Next we were looking for the format of a message - that was not so difficult
to find out of by sending messages. A recieved block of data is threaded as
folow three NULL terminated strings after each other :


Sender

Reciever

Message

So 'MARTIN'#0'DON'#0'Hi'#0 is a message from Martin to Don with the message Hi.
In the next I'll tell how to use mailslots (the Windows - WinPopup one as example),
using examples in a Pascal-like code. The code parts is not fully explaining
(if you want to use mailslots in a program you have a compiler and a helpfile
where you can find the exact syntax) - I'll just tell you about what you need
for making use of this function.
If you are Delphi 2.0 developer then you can go to my VCL page where I have a
fully functional VCL, with all the source code, for free download. For writing
to an existing mailslot (send a message over the network), all you have to do
is to thread the mailslot as a file on the target machine, whith this filename :


"//"+Server_Name+"/mailslot/messngr"
To write to this file, first open it like this :


Handle := CreateFile("//THOR/mailslot/messngr",
GENERIC_WRITE,
FILE_SHARE_READ,
NIL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
-1)
The handle returned can then be used in a call to write to the file like this :


WriteFile(Handle,
Data,
Size(Data),
BytesWritten,
NIL)
It is wise to close the handle after user with a call like this :


CloseHandle(Handle)
That was easy - wasn't it?

To make a mailslot avalible for other to use, you have to create a mailslot
usong the CreateMailslot function like this :


Handle := CreateMailSlot("//./mailslot/messngr",
0,
$FFFFFFFF,
NIL)
The handle returned from the CreateMailSlot function should then be used for accessing the mailslot. Note the value $FFFFFFFF should also be called "MAILSLOT_WAIT_FOREVER", but my Delphi 2.0 does not reconize the name. The value is also said in the WIN32 API helpfile to make a read from the mailslot go into a blocked waitstate until something is arriving into it, but I can not make it do so :(.

For checking up anything is in the mailslot call the GetMailSlotInfo function


GetMailSlotInfo(Handle,NIL, NextSize, @Waiting, NIL)
where NextSize and Waiting is both defined as DWord's.
NextSize will after a call contain the size of the next message
(for allocation of buffer) and Waiting will contain the number of messages waiting.

For reading from a mailslot, all which is needed to be done, is to call the ReadFile function with the handle recieved from the CreatMailSlot function, like this :


ReadFile(Handle,Buffer^,NextSize,ReadSize,NIL)
After end use of the mailslot I'll advise you to close the handle with the CloseHandle function (as far as I have understood, it is not strictly necessary) like this :


CloseHandle(FHandle)
Before continuing to the next problem, I'll like to thank Don Hass for telleing me about the "messngr" mailslot.

 
@_@
先用中文简要解说一下思路吧,E文看得眼花 :-(
 
聽聽﹗﹗﹗
 
当发送信息的主机上Messager服务是开启的话,数据包以UDP的格式发送到目标主机的135端口; 若发送主机的Messager服务没有运行,则数据以TCP的格式被发送到目标主机的139端口中,你只要写一段程序监听这些端口就行了。
 
天下一兵,但是139端口已经被系统打开了,怎么监听?不要用原始套接字的情况下。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部