|
From: andrewb on 3 Jul 2008 06:39 Hi all, Having some trouble using named pipes and Visual Basic .NET and would appreciate and help you could offer. Essentially I am trying to develop a simple client/server application that exchanges text messages using named pipes. The internet resources seem a bit scarce and the only Microsoft resource I can find is http://support.microsoft.com/kb/871044. I have managed to get the above KB example working but I am struggling to convert it to just use string data between the client & server. Anyone done this already using Visual Basic .NET? Cheers.
From: kimiraikkonen on 3 Jul 2008 10:04 On Jul 3, 1:39 pm, andrewb <ajba...(a)deloitte.co.uk> wrote: > Hi all, > > Having some trouble using named pipes and Visual Basic .NET and would > appreciate and help you could offer. > > Essentially I am trying to develop a simple client/server application > that exchanges text messages using named pipes. The internet resources > seem a bit scarce and the only Microsoft resource I can find ishttp://support.microsoft.com/kb/871044. > > I have managed to get the above KB example working but I am struggling > to convert it to just use string data between the client & server. > > Anyone done this already using Visual Basic .NET? > > Cheers. Hi, I hope that provides better info for sending strings using pipes: http://msdn.microsoft.com/en-us/library/system.io.pipes.anonymouspipeserverstream.aspx or: http://msdn.microsoft.com/en-us/library/system.io.pipes.aspx However you can also consider using System.Net.Sockets. HTH, Onur Güzel
From: Tom Shelton on 3 Jul 2008 11:59 On 2008-07-03, andrewb <ajbaker(a)deloitte.co.uk> wrote: > Hi all, > > Having some trouble using named pipes and Visual Basic .NET and would > appreciate and help you could offer. > > Essentially I am trying to develop a simple client/server application > that exchanges text messages using named pipes. The internet resources > seem a bit scarce and the only Microsoft resource I can find is > http://support.microsoft.com/kb/871044. > > I have managed to get the above KB example working but I am struggling > to convert it to just use string data between the client & server. > > Anyone done this already using Visual Basic .NET? > > Cheers. > What version of VB are you using? If your using 2008, then you might want to take a look at System.IO.Pipes - they are now part of the framework. You can find documentation and examples here: http://msdn.microsoft.com/en-us/library/system.io.pipes.aspx If you must use the API example... Then the simple answer is to convert your strings to byte arrays before sending them accross the pipe: ' send data Dim dataBuffer() As Byte = Encoding.Default.GetBytes(stringData) WriteFile(......) ' receive data ReadFile(...dataBuffer...) .... Dim stringData As String = Encoding.Default.GetString(dataBuffer) -- Tom Shelton
From: Tom Shelton on 3 Jul 2008 12:00 On 2008-07-03, Tom Shelton <tom_shelton(a)comcastXXXXXXX.net> wrote: > On 2008-07-03, andrewb <ajbaker(a)deloitte.co.uk> wrote: >> Hi all, >> >> Having some trouble using named pipes and Visual Basic .NET and would >> appreciate and help you could offer. >> >> Essentially I am trying to develop a simple client/server application >> that exchanges text messages using named pipes. The internet resources >> seem a bit scarce and the only Microsoft resource I can find is >> http://support.microsoft.com/kb/871044. >> >> I have managed to get the above KB example working but I am struggling >> to convert it to just use string data between the client & server. >> >> Anyone done this already using Visual Basic .NET? >> >> Cheers. >> > > What version of VB are you using? If your using 2008, then you might want to > take a look at System.IO.Pipes - they are now part of the framework. You can > find documentation and examples here: > > http://msdn.microsoft.com/en-us/library/system.io.pipes.aspx > > If you must use the API example... Then the simple answer is to convert your > strings to byte arrays before sending them accross the pipe: > > ' send data > Dim dataBuffer() As Byte = Encoding.Default.GetBytes(stringData) > WriteFile(......) > > > ' receive data > ReadFile(...dataBuffer...) > ... > Dim stringData As String = Encoding.Default.GetString(dataBuffer) > I should probably mention... If all of your strings can be represented in ASCII then, you can actually use Encoding.ASCII on both ends. -- Tom Shelton
From: andrewb on 3 Jul 2008 12:47 Thanks for the help guys - appreciate it I am using Visual Studio 2005, still unable to get a string through - here is my code, hopefully you can spot my error(s) : Server code ========= Dim pipeName As String = "\\.\pipe\MServerPipe" Dim hPipe As Integer Dim openMode, pipeMode As Integer Dim stringIn As String Dim dataIn(256) As Byte Dim res, nChars As Integer openMode = PIPE_ACCESS_DUPLEX Or FILE_FLAG_WRITE_THROUGH pipeMode = PIPE_WAIT Or PIPE_TYPE_MESSAGE Or PIPE_READMODE_MESSAGE hPipe = CreateNamedPipe(pipeName, openMode, pipeMode, 10, 10000, 2000, 10000, IntPtr.Zero) res = ConnectNamedPipe(hPipe, 0) res = ReadFile(hPipe, dataIn, 256, nChars, 0) stringIn = System.Text.Encoding.ASCII.GetString(dataIn) CloseHandle(hPipe) Client code ======== Dim pipeName As String = "\\.\pipe\MServerPipe" Dim res, cbRead, numBytes As Integer Dim stringOut As String Dim dataOut(256), dataIn(256) As Byte stringOut = "This is a test" dataOut = System.Text.Encoding.ASCII.GetBytes(stringOut) res = CallNamedPipe(pipeName, dataOut, stringOut.Length, dataIn, numBytes, cbRead, 30000) API declarations ============ Public Declare Function CallNamedPipe Lib "kernel32" Alias "CallNamedPipeA" _ (ByVal lpNamedPipeName As String, _ ByRef lpInBuffer() As Byte, _ ByVal nInBufferSize As Integer, _ ByRef lpOutBuffer() As Byte, _ ByVal nOutBufferSize As Integer, _ ByRef lpBytesRead As Integer, ByVal nTimeOut As Integer) As Integer Declare Function WriteFile Lib "kernel32" _ (ByVal hFile As Integer, ByRef lpBuffer() As Byte, _ ByVal nNumberOfBytesToWrite As Integer, ByRef lpNumberOfBytesWritten As Integer, _ ByVal lpOverlapped As Integer _ ) As Integer Declare Function ReadFile Lib "kernel32" _ (ByVal hFile As Integer, ByVal lpBuffer() As Byte, _ ByVal nNumberOfBytesToRead As Integer, ByRef lpNumberOfBytesRead As Integer, _ ByVal lpOverlapped As Integer _ ) As Integer
|
Next
|
Last
Pages: 1 2 Prev: ODMA-Application Next: Get session cookies from webrequest and pass then to new request |