emiltor
asked on
Send message to another computer API calls
How can i send message to another computer to remind the person about something? Is this API Calls ( Do you have some code ) Thanks!!
Odd - I always thought the U in UDP was for Unreliable in that the protocol does not in fact gurantee delivery of the packet. (at least it is in the Unix world...)
Cheers,
Raymond.
Cheers,
Raymond.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Raymond!
So did I, until I got corrected by Andrew S. Tannenbaum in his book "Computer Networks"
BlackMan is right, I guess. This must be the easiest way to do this.
Cheers,
Williams
So did I, until I got corrected by Andrew S. Tannenbaum in his book "Computer Networks"
BlackMan is right, I guess. This must be the easiest way to do this.
Cheers,
Williams
ASKER
I have Delphi 3.0.1 Client/Server
You can also use NetMessageBufferSend, this is really easy, but works only in NT.
/// John
/// John
ASKER
Excelent !! I only use NT , Do you have any code or something ?
I guess this might work. You have to declare the function first!
Like this:
interface
...
Function NetMessageBufferSend (
pServername,
pMsgName,
pFromname: PWideChar;
buf: pChar;
buflen: DWORD): UINT; stdcall;
external 'netapi32.dll' name 'NetMessageBufferSend';
implementation
{$R *.DFM}
procedure DoSendMessage(ServerName,H eadline,Fr om: String; Message: TStringList);
var
i,count: Integer;
begin
count:= 0;
For i:= 0 to message.Count-1 do Inc(Count,length(message.s trings[i]) +1);
If From='' then From:= #0; //uses the default loginName
NetMessageBufferSend(PWide Char(Serve rName),
PWideChar(Headline),
PWideChar(From),
Message.GetText,
count);
End;
..
end.
Does that work? ..I'm sorry, that I cannot test it myself, I haven't got two computers, but the app seemed to be busy doing something hehe. :-)
Cheers,
Williams
Like this:
interface
...
Function NetMessageBufferSend (
pServername,
pMsgName,
pFromname: PWideChar;
buf: pChar;
buflen: DWORD): UINT; stdcall;
external 'netapi32.dll' name 'NetMessageBufferSend';
implementation
{$R *.DFM}
procedure DoSendMessage(ServerName,H
var
i,count: Integer;
begin
count:= 0;
For i:= 0 to message.Count-1 do Inc(Count,length(message.s
If From='' then From:= #0; //uses the default loginName
NetMessageBufferSend(PWide
PWideChar(Headline),
PWideChar(From),
Message.GetText,
count);
End;
..
end.
Does that work? ..I'm sorry, that I cannot test it myself, I haven't got two computers, but the app seemed to be busy doing something hehe. :-)
Cheers,
Williams
Do you need further help, or is Williams comment enough?
The drawback with this method is: you can't handle the message yourself on the receiver end, unless you substitute the messenger service.
/// John
The drawback with this method is: you can't handle the message yourself on the receiver end, unless you substitute the messenger service.
/// John
ASKER
I'm glad if you have any code John....
Williams have to explane his answer better - i don't understand it enought
thanks..... williams & John
(/Ho is better)
Williams have to explane his answer better - i don't understand it enought
thanks..... williams & John
(/Ho is better)
If you go for Williams / johns answer, I think you should reject my answer...
ASKER
Sorry Blackman, when i go to the page you send me it doesn't work and now when i test again it works. and there is lots of stuff about my question ( "allright" )
Thanks...
Thanks...
Hi again,
Here's a simple unit with the functions supplied by Williams and some sample code:
unit NetMsg;
{ Example unit for sending messages over the network }
{ For users at experts-exchange, use freely at own risk }
{ created 1998-12-10 by John Johansson (erajoj) }
interface
uses Windows, Classes;
function NetMessageBufferSend(
pServername,
pMsgName,
pFromname,
pBuf: PWideChar;
dwBufLen: DWORD): UINT; stdcall;
external 'netapi32.dll' name 'NetMessageBufferSend';
{ Send strings to single recipient at optional server and with optional signature }
function DoSendMessage( pServerName, pFrom, pReceiver: PWideChar; rgsMsg: TStrings ): Boolean;
{ Send strings to multiple recipients at optional server and with optional signature }
function DoSendMessageEx( pServerName, pFrom: PWideChar; rgsReceiver, rgsMsg: TStrings ): Boolean;
{ Lightweight send strings to single recipient }
function SendMsg( sReceiver, sMessage: string ): Boolean;
implementation
function DoSendMessage( pServerName, pFrom, pReceiver: PWideChar; rgsMsg: TStrings ): Boolean;
var
sMsg: WideString;
begin
sMsg := rgsMsg.Text; { autoconvert from ansi to wide string }
Result := NetMessageBufferSend(
pServerName,
pReceiver,
pFrom,
PWideChar( sMsg ),
SizeOf( WideChar ) * ( Length( sMsg ) + 1 ) { 2 byte per char + zero terminator }
) = 0;
end;
function DoSendMessageEx( pServerName, pFrom: PWideChar; rgsReceiver, rgsMsg: TStrings ): Boolean;
var
sMsg: WideString;
iIndex: Integer;
begin
Result := True;
for iIndex := 0 to rgsReceiver.Count - 1 do
begin
sMsg := rgsReceiver[ iIndex ]; { autoconvert from ansi to wide string }
Result := Result and DoSendMessage( pServerName, pFrom, PWideChar( sMsg ), rgsMsg );
end;
end;
function SendMsg( sReceiver, sMessage: string ): Boolean;
var
sRec, sMsg: WideString;
begin
sRec := sReceiver; { autoconvert from ansi to wide string }
sMsg := sMessage; { autoconvert from ansi to wide string }
Result := NetMessageBufferSend(
nil,
PWideChar( sRec ),
nil,
PWideChar( sMsg ),
SizeOf( WideChar ) * ( Length( sMsg ) + 1 ) { 2 byte per char + zero terminator }
) = 0;
end;
Samples:
uses ..., netmsg;
...
procedure TMainForm.Button1Click(Sen der: TObject);
begin
SendMsg( 'john', 'Hello! Let''s go out to lunch!' );
end;
procedure TMainForm.Button2Click(Sen der: TObject);
begin
DoSendMessageEx( '\\DEVSRV', nil, ColleagueListBox.Items, MessageListBox.Items );
end;
procedure TMainForm.Button3Click(Sen der: TObject);
begin
DoSendMessage( nil, nil, 'myonlyfriend', InfoStringList );
end;
procedure TMainForm.Button4Click(Sen der: TObject);
begin
if not SendMsg( 'emiltor', 'Enough?' ) then
ShowMessage( 'Not good enough. Didn''t get through!' );
end;
end.
Can't really do any better than this right now...
Points go to Williams if this solution is sufficient.
/// John
Here's a simple unit with the functions supplied by Williams and some sample code:
unit NetMsg;
{ Example unit for sending messages over the network }
{ For users at experts-exchange, use freely at own risk }
{ created 1998-12-10 by John Johansson (erajoj) }
interface
uses Windows, Classes;
function NetMessageBufferSend(
pServername,
pMsgName,
pFromname,
pBuf: PWideChar;
dwBufLen: DWORD): UINT; stdcall;
external 'netapi32.dll' name 'NetMessageBufferSend';
{ Send strings to single recipient at optional server and with optional signature }
function DoSendMessage( pServerName, pFrom, pReceiver: PWideChar; rgsMsg: TStrings ): Boolean;
{ Send strings to multiple recipients at optional server and with optional signature }
function DoSendMessageEx( pServerName, pFrom: PWideChar; rgsReceiver, rgsMsg: TStrings ): Boolean;
{ Lightweight send strings to single recipient }
function SendMsg( sReceiver, sMessage: string ): Boolean;
implementation
function DoSendMessage( pServerName, pFrom, pReceiver: PWideChar; rgsMsg: TStrings ): Boolean;
var
sMsg: WideString;
begin
sMsg := rgsMsg.Text; { autoconvert from ansi to wide string }
Result := NetMessageBufferSend(
pServerName,
pReceiver,
pFrom,
PWideChar( sMsg ),
SizeOf( WideChar ) * ( Length( sMsg ) + 1 ) { 2 byte per char + zero terminator }
) = 0;
end;
function DoSendMessageEx( pServerName, pFrom: PWideChar; rgsReceiver, rgsMsg: TStrings ): Boolean;
var
sMsg: WideString;
iIndex: Integer;
begin
Result := True;
for iIndex := 0 to rgsReceiver.Count - 1 do
begin
sMsg := rgsReceiver[ iIndex ]; { autoconvert from ansi to wide string }
Result := Result and DoSendMessage( pServerName, pFrom, PWideChar( sMsg ), rgsMsg );
end;
end;
function SendMsg( sReceiver, sMessage: string ): Boolean;
var
sRec, sMsg: WideString;
begin
sRec := sReceiver; { autoconvert from ansi to wide string }
sMsg := sMessage; { autoconvert from ansi to wide string }
Result := NetMessageBufferSend(
nil,
PWideChar( sRec ),
nil,
PWideChar( sMsg ),
SizeOf( WideChar ) * ( Length( sMsg ) + 1 ) { 2 byte per char + zero terminator }
) = 0;
end;
Samples:
uses ..., netmsg;
...
procedure TMainForm.Button1Click(Sen
begin
SendMsg( 'john', 'Hello! Let''s go out to lunch!' );
end;
procedure TMainForm.Button2Click(Sen
begin
DoSendMessageEx( '\\DEVSRV', nil, ColleagueListBox.Items, MessageListBox.Items );
end;
procedure TMainForm.Button3Click(Sen
begin
DoSendMessage( nil, nil, 'myonlyfriend', InfoStringList );
end;
procedure TMainForm.Button4Click(Sen
begin
if not SendMsg( 'emiltor', 'Enough?' ) then
ShowMessage( 'Not good enough. Didn''t get through!' );
end;
end.
Can't really do any better than this right now...
Points go to Williams if this solution is sufficient.
/// John
ASKER
Thanks
Blackman,Williams,John,Ray mond
Now i can send message
Keep the smile high..............
Blackman,Williams,John,Ray
Now i can send message
Keep the smile high..............
You're welcome
Thanx to John for his corrections :-)
Regards,
Williams
Thanx to John for his corrections :-)
Regards,
Williams
If you are to setup a server through a Local Area Network, you should use either DCOM (Distributed COM) or UDP (User Datagram Protocol)
Another and more secure way, is to make the client do a TCP/IP connection to the server at startup. Afterwards, it's very easy to control events and dataparsing. I can give you bright examples of this.
Which version of Delphi have you got?
regards,
Williams