Getting a client to beep through telnet can be a very complicated task. Pragma TelnetServers Advanced Console and wrapper technology have allowed a system beep from a server application to pass to the client without any customization. Also with a slight modification a echo of beep to the console can also be passed.
Besides using Advanced Console or the wrapper technology in Full
Console, there are other ways to get a client to beep.
One is to implement access to our Mutex Semaphores in your application. There is a description of how to do this Programming for TelnetServer.
Included with the programming examples is a program to send the beep. A system call to "telwrite 7" to an application will take control of the socket, using the Mutex Sempahores mentioned above, and send a beep to the client. Telwrite should then be included with any distributed program. This is less efficient than the above, but is available for users who do not have the option to use the Mutex Semaphores directly.
Here is some sample code to beep from an application
VB
Imports System
Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Module Module1
Private
welcomeMessage As
String
= "Welcome
VBBeep"
Private Declare Function
GetStdHandle Lib "kernel32" _
(ByVal
nStdHandle As Long)
As Long
Private Declare Function _
SetConsoleMode Lib "kernel32" _
(ByVal
hConsoleOutput As
Long,
_
ByVal
dwMode As Long)
As Long
Private Const
ENABLE_PROCESSED_OUTPUT As Long
= &H1
Private Const
STD_OUTPUT_HANDLE As Long
= -11&
Private Const
WAIT_INFINITE As Long
= -1&
Private Const
SYNCHRONIZE As Long
= &H100000
Private Declare Function
OpenProcess Lib "kernel32" _
(ByVal
dwDesiredAccess As
Long,
_
ByVal
bInheritHandle As
Long,
_
ByVal
dwProcessId As Long)
As Long
Private Declare Function
WaitForSingleObject Lib "kernel32" _
(ByVal
hHandle As Long,
_
ByVal
dwMilliseconds As
Long)
As Long
Private Declare Function
CloseHandle Lib "kernel32" _
(ByVal
hObject As Long)
As Long
Private Sub BeepToClient()
Dim
hProcess As Long
Dim
taskId As Long
Dim
cmdline As String
hProcess = OpenProcess(SYNCHRONIZE, 1, taskId)
Call WaitForSingleObject(hProcess, WAIT_INFINITE)
CloseHandle(hProcess)
Dim inTelnet As Boolean = True
Dim inetDSock As String
Try
inetDSock = System.Environment.GetEnvironmentVariable("PRAGMASYS_INETD_SOCK")
Catch ex As ArgumentNullException
inTelnet = False
End Try
If (inTelnet) Then
Dim TelnetDPid As String = System.Environment.GetEnvironmentVariable("PRAGMASYS_TELNETD_PID")
Dim MutexName As String =
"TelnetDOutput" + TelnetDPid
Dim retMutex As Mutex
retMutex = Mutex.OpenExisting(MutexName)
retMutex.WaitOne()
Dim sock As Socket = CObj(inetDSock) As Socket
sock.Send("7")
retMutex.ReleaseMutex()
End If
End Sub
Sub
'
These are 3 ways to beep
Console.WriteLine(welcomeMessage)
'
System beep calls with Advanced Console or Wrapper
Console.Beep(200,
300)
Console.Beep(500, 300)
Console.Beep(700, 300)
' Character 7 echo to console with Advanced Console or Wrapper
SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), Not (ENABLE_PROCESSED_OUTPUT))
Console.WriteLine(Chr(7))
' Taking control of the Mutex Semaphore in any screen mode
BeepToClient()
' Using the included telwrite program in any screen mode
cmdline
= "telwrite.exe
7"
taskId = Shell(cmdline)
Console.WriteLine("Beeped")
End Sub
End Module
In VC:
#include <stdio.h>
#include <windows.h>
#include netio.h
void
main( int
argc, char
**argv )
{
DWORD Mode;
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
//
System beep calls with Advanced Console or Wrapper
Beep(2128,12);
Beep(1824,4);
Beep(2128,12);
//
Character 7 echo to console with Advanced Console or Wrapper
GetConsoleMode( hOutput, &Mode );
Mode &= ~ENABLE_PROCESSED_OUTPUT;
SetConsoleMode( hOutput, Mode );
putchar(7);
printf("%c",7);
putchar(7);
printf("%c",7);
putchar(7);
printf("%c",7);
//
Taking control of the Mutex Semaphore in any screen mode
CommInit(); //
included in the example directory\netio.c
CommWrite(7, 2);
CommUnInit(); //
included in the example directory\netio.c
//
Using the included telwrite program in any screen mode
System(telwrite.exe 7);
}
.