Virtual channel noise

G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.terminalserver.misc (More info?)

I have been experiencing some problems in virtual channel
communications. One activex in the server initiates de write to the
client, and sometimes the client receives noise inserted in the chunks
(noise is about 200-300 bytes of random bytes). This only occurs then I
write a buffer bigger than CHANNEL_CHUNK_SIZE. The client receives all
the chunks and compose the original. When I examine the result, I see
sometimes noise inserted.

And I mean inserted not replaced. And it only occurs sometimes.

Any help?

Thanks.
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.terminalserver.misc (More info?)

You have to break the packet into several smallers packets with Max size =
CHANNEL_CHUNK_SIZE
I have used Virtual Channel since many years, there is no problem like that,
it's very reliable .
(I used VD developped with C++)

"R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
news:eesdQdp4EHA.2016@TK2MSFTNGP15.phx.gbl...
> I have been experiencing some problems in virtual channel
> communications. One activex in the server initiates de write to the
> client, and sometimes the client receives noise inserted in the chunks
> (noise is about 200-300 bytes of random bytes). This only occurs then I
> write a buffer bigger than CHANNEL_CHUNK_SIZE. The client receives all
> the chunks and compose the original. When I examine the result, I see
> sometimes noise inserted.
>
> And I mean inserted not replaced. And it only occurs sometimes.
>
> Any help?
>
> Thanks.
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.terminalserver.misc (More info?)

Do you mean that I cannot use in WTSVirtualChannelWrite a chunk bigger
than CHANNEL_CHUNK_SIZE? I have made some tests and it works well with
big chunks. Not with WTSVirtualChannelRead where I have to read all the
smaller chunks and concatenate them.


Thomas T. wrote:
> You have to break the packet into several smallers packets with Max size =
> CHANNEL_CHUNK_SIZE
> I have used Virtual Channel since many years, there is no problem like that,
> it's very reliable .
> (I used VD developped with C++)
>
> "R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
> news:eesdQdp4EHA.2016@TK2MSFTNGP15.phx.gbl...
>
>>I have been experiencing some problems in virtual channel
>>communications. One activex in the server initiates de write to the
>>client, and sometimes the client receives noise inserted in the chunks
>>(noise is about 200-300 bytes of random bytes). This only occurs then I
>>write a buffer bigger than CHANNEL_CHUNK_SIZE. The client receives all
>>the chunks and compose the original. When I examine the result, I see
>>sometimes noise inserted.
>>
>>And I mean inserted not replaced. And it only occurs sometimes.
>>
>>Any help?
>>
>>Thanks.
>
>
>
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.terminalserver.misc (More info?)

I write a buffer bigger than CHANNEL_CHUNK_SIZE with
WTSVirtualChannelWrite. The problem happens sometimes in the client, not
in the server (so WTSVirtualChannelRead is OK). In the client, when I
concatenate the chunks received, finally the result has noise inserted.
This is the code I use to concatenate the chunks:

BSTR ConcatenateBSTR (BSTR a, BSTR b) {
int ca = SysStringLen (a); // Does not include terminating '\0'
int cb = SysStringLen (b);

BSTR c = SysAllocStringLen (NULL, ca + cb); // Accounts for
terminating '\0'

if (! c)
return NULL;

memcpy ((WCHAR *)c, a, ca * sizeof(WCHAR));
memcpy (((WCHAR *)c) + ca, b, (cb+1) * sizeof(WCHAR)); // copies
b AND '\0'

return c;
}

void WINAPI VirtualChannelOpenEvent(DWORD openHandle, UINT event, LPVOID
pdata, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{

....
switch(event)
{
case CHANNEL_EVENT_DATA_RECEIVED:
{
static int bBusy = 0;

while(bBusy);
bBusy = 1;

if (!(dataFlags & CHANNEL_FLAG_FIRST)) { BSTR bstrTmp =
SysAllocString(pdata);
BSTR bstrAux = gbstrMensaje;
gbstrMensaje = ConcatenateBSTR(gbstrMensaje, bstrTmp);
SysFreeString(bstrTmp);
SysFreeString(bstrAux);
} else {
gbstrMensaje = SysAllocString(pdata);
}

bBusy = 0;

if (dataFlags & CHANNEL_FLAG_LAST) {
.... }

}
break;
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.terminalserver.misc (More info?)

Sorry, you are right . I'am always use binary format, write and read into
byte array buffer,
when the whole buffer is read, I rebuild the string . I also use this to
transfer file, files are always well received .


"R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
news:O%23AdNcB5EHA.1452@TK2MSFTNGP11.phx.gbl...
> Do you mean that I cannot use in WTSVirtualChannelWrite a chunk bigger
> than CHANNEL_CHUNK_SIZE? I have made some tests and it works well with
> big chunks. Not with WTSVirtualChannelRead where I have to read all the
> smaller chunks and concatenate them.
>
>
> Thomas T. wrote:
> > You have to break the packet into several smallers packets with Max size
=
> > CHANNEL_CHUNK_SIZE
> > I have used Virtual Channel since many years, there is no problem like
that,
> > it's very reliable .
> > (I used VD developped with C++)
> >
> > "R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
> > news:eesdQdp4EHA.2016@TK2MSFTNGP15.phx.gbl...
> >
> >>I have been experiencing some problems in virtual channel
> >>communications. One activex in the server initiates de write to the
> >>client, and sometimes the client receives noise inserted in the chunks
> >>(noise is about 200-300 bytes of random bytes). This only occurs then I
> >>write a buffer bigger than CHANNEL_CHUNK_SIZE. The client receives all
> >>the chunks and compose the original. When I examine the result, I see
> >>sometimes noise inserted.
> >>
> >>And I mean inserted not replaced. And it only occurs sometimes.
> >>
> >>Any help?
> >>
> >>Thanks.
> >
> >
> >
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.terminalserver.misc (More info?)

I think, problem is in the logic of the code, you should use a global
buffer, cumulate
all arrived buffer , at the end (CHANNEL_FLAG_LAST) convert the buffer to
BSTR

Regards

"R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
news:ua$Z8eB5EHA.1452@TK2MSFTNGP11.phx.gbl...
> I write a buffer bigger than CHANNEL_CHUNK_SIZE with
> WTSVirtualChannelWrite. The problem happens sometimes in the client, not
> in the server (so WTSVirtualChannelRead is OK). In the client, when I
> concatenate the chunks received, finally the result has noise inserted.
> This is the code I use to concatenate the chunks:
>
> BSTR ConcatenateBSTR (BSTR a, BSTR b) {
> int ca = SysStringLen (a); // Does not include terminating '\0'
> int cb = SysStringLen (b);
>
> BSTR c = SysAllocStringLen (NULL, ca + cb); // Accounts for
> terminating '\0'
>
> if (! c)
> return NULL;
>
> memcpy ((WCHAR *)c, a, ca * sizeof(WCHAR));
> memcpy (((WCHAR *)c) + ca, b, (cb+1) * sizeof(WCHAR)); // copies
> b AND '\0'
>
> return c;
> }
>
> void WINAPI VirtualChannelOpenEvent(DWORD openHandle, UINT event, LPVOID
> pdata, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
> {
>
> ...
> switch(event)
> {
> case CHANNEL_EVENT_DATA_RECEIVED:
> {
> static int bBusy = 0;
>
> while(bBusy);
> bBusy = 1;
>
> if (!(dataFlags & CHANNEL_FLAG_FIRST)) { BSTR bstrTmp =
> SysAllocString(pdata);
> BSTR bstrAux = gbstrMensaje;
> gbstrMensaje = ConcatenateBSTR(gbstrMensaje, bstrTmp);
> SysFreeString(bstrTmp);
> SysFreeString(bstrAux);
> } else {
> gbstrMensaje = SysAllocString(pdata);
> }
>
> bBusy = 0;
>
> if (dataFlags & CHANNEL_FLAG_LAST) {
> ... }
>
> }
> break;
>
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.terminalserver.misc (More info?)

Yes, gbstrMensaje is a global buffer. I convert each chunk received to
BSTR and concatenates to the global buffer. The strange thing is that it
usually works well, but sometimes the global buffer have the complete
message but with small chunks of noise inserted at some points (notice:
if i remove the noise, the result BSTR is OK)

Thomas T. wrote:
> I think, problem is in the logic of the code, you should use a global
> buffer, cumulate
> all arrived buffer , at the end (CHANNEL_FLAG_LAST) convert the buffer to
> BSTR
>
> Regards
>
> "R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
> news:ua$Z8eB5EHA.1452@TK2MSFTNGP11.phx.gbl...
>
>>I write a buffer bigger than CHANNEL_CHUNK_SIZE with
>>WTSVirtualChannelWrite. The problem happens sometimes in the client, not
>>in the server (so WTSVirtualChannelRead is OK). In the client, when I
>>concatenate the chunks received, finally the result has noise inserted.
>>This is the code I use to concatenate the chunks:
>>
>>BSTR ConcatenateBSTR (BSTR a, BSTR b) {
>> int ca = SysStringLen (a); // Does not include terminating '\0'
>> int cb = SysStringLen (b);
>>
>> BSTR c = SysAllocStringLen (NULL, ca + cb); // Accounts for
>>terminating '\0'
>>
>> if (! c)
>> return NULL;
>>
>> memcpy ((WCHAR *)c, a, ca * sizeof(WCHAR));
>> memcpy (((WCHAR *)c) + ca, b, (cb+1) * sizeof(WCHAR)); // copies
>>b AND '\0'
>>
>> return c;
>>}
>>
>>void WINAPI VirtualChannelOpenEvent(DWORD openHandle, UINT event, LPVOID
>>pdata, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
>>{
>>
>>...
>> switch(event)
>> {
>> case CHANNEL_EVENT_DATA_RECEIVED:
>> {
>>static int bBusy = 0;
>>
>>while(bBusy);
>>bBusy = 1;
>>
>>if (!(dataFlags & CHANNEL_FLAG_FIRST)) { BSTR bstrTmp =
>>SysAllocString(pdata);
>>BSTR bstrAux = gbstrMensaje;
>>gbstrMensaje = ConcatenateBSTR(gbstrMensaje, bstrTmp);
>>SysFreeString(bstrTmp);
>>SysFreeString(bstrAux);
>>} else {
>>gbstrMensaje = SysAllocString(pdata);
>>}
>>
>>bBusy = 0;
>>
>>if (dataFlags & CHANNEL_FLAG_LAST) {
>>... }
>>
>> }
>> break;
>>
>
>
>
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.terminalserver.misc (More info?)

Don't convert right a way each chunk like that, cumulate them in a buffer
(use memcopy),
when the whole buffer is received then you convert it to BSTR. I never have
problem when using
this technic .


"R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
news:Ow0MdzF5EHA.2592@TK2MSFTNGP09.phx.gbl...
> Yes, gbstrMensaje is a global buffer. I convert each chunk received to
> BSTR and concatenates to the global buffer. The strange thing is that it
> usually works well, but sometimes the global buffer have the complete
> message but with small chunks of noise inserted at some points (notice:
> if i remove the noise, the result BSTR is OK)
>
> Thomas T. wrote:
> > I think, problem is in the logic of the code, you should use a global
> > buffer, cumulate
> > all arrived buffer , at the end (CHANNEL_FLAG_LAST) convert the buffer
to
> > BSTR
> >
> > Regards
> >
> > "R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
> > news:ua$Z8eB5EHA.1452@TK2MSFTNGP11.phx.gbl...
> >
> >>I write a buffer bigger than CHANNEL_CHUNK_SIZE with
> >>WTSVirtualChannelWrite. The problem happens sometimes in the client, not
> >>in the server (so WTSVirtualChannelRead is OK). In the client, when I
> >>concatenate the chunks received, finally the result has noise inserted.
> >>This is the code I use to concatenate the chunks:
> >>
> >>BSTR ConcatenateBSTR (BSTR a, BSTR b) {
> >> int ca = SysStringLen (a); // Does not include terminating '\0'
> >> int cb = SysStringLen (b);
> >>
> >> BSTR c = SysAllocStringLen (NULL, ca + cb); // Accounts for
> >>terminating '\0'
> >>
> >> if (! c)
> >> return NULL;
> >>
> >> memcpy ((WCHAR *)c, a, ca * sizeof(WCHAR));
> >> memcpy (((WCHAR *)c) + ca, b, (cb+1) * sizeof(WCHAR)); // copies
> >>b AND '\0'
> >>
> >> return c;
> >>}
> >>
> >>void WINAPI VirtualChannelOpenEvent(DWORD openHandle, UINT event, LPVOID
> >>pdata, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
> >>{
> >>
> >>...
> >> switch(event)
> >> {
> >> case CHANNEL_EVENT_DATA_RECEIVED:
> >> {
> >>static int bBusy = 0;
> >>
> >>while(bBusy);
> >>bBusy = 1;
> >>
> >>if (!(dataFlags & CHANNEL_FLAG_FIRST)) { BSTR bstrTmp =
> >>SysAllocString(pdata);
> >>BSTR bstrAux = gbstrMensaje;
> >>gbstrMensaje = ConcatenateBSTR(gbstrMensaje, bstrTmp);
> >>SysFreeString(bstrTmp);
> >>SysFreeString(bstrAux);
> >>} else {
> >>gbstrMensaje = SysAllocString(pdata);
> >>}
> >>
> >>bBusy = 0;
> >>
> >>if (dataFlags & CHANNEL_FLAG_LAST) {
> >>... }
> >>
> >> }
> >> break;
> >>
> >
> >
> >
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.terminalserver.misc (More info?)

That seems to be a better solution, but I don't see the real difference
between converting each chunk/cumulate and cumulate/convert... Any
suggestion?

Thx.

Thomas T. wrote:
> Don't convert right a way each chunk like that, cumulate them in a buffer
> (use memcopy),
> when the whole buffer is received then you convert it to BSTR. I never have
> problem when using
> this technic .
>
>
> "R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
> news:Ow0MdzF5EHA.2592@TK2MSFTNGP09.phx.gbl...
>
>>Yes, gbstrMensaje is a global buffer. I convert each chunk received to
>>BSTR and concatenates to the global buffer. The strange thing is that it
>>usually works well, but sometimes the global buffer have the complete
>>message but with small chunks of noise inserted at some points (notice:
>>if i remove the noise, the result BSTR is OK)
>>
>>Thomas T. wrote:
>>
>>>I think, problem is in the logic of the code, you should use a global
>>>buffer, cumulate
>>>all arrived buffer , at the end (CHANNEL_FLAG_LAST) convert the buffer
>
> to
>
>>>BSTR
>>>
>>>Regards
>>>
>>>"R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
>>>news:ua$Z8eB5EHA.1452@TK2MSFTNGP11.phx.gbl...
>>>
>>>
>>>>I write a buffer bigger than CHANNEL_CHUNK_SIZE with
>>>>WTSVirtualChannelWrite. The problem happens sometimes in the client, not
>>>>in the server (so WTSVirtualChannelRead is OK). In the client, when I
>>>>concatenate the chunks received, finally the result has noise inserted.
>>>>This is the code I use to concatenate the chunks:
>>>>
>>>>BSTR ConcatenateBSTR (BSTR a, BSTR b) {
>>>> int ca = SysStringLen (a); // Does not include terminating '\0'
>>>> int cb = SysStringLen (b);
>>>>
>>>> BSTR c = SysAllocStringLen (NULL, ca + cb); // Accounts for
>>>>terminating '\0'
>>>>
>>>> if (! c)
>>>> return NULL;
>>>>
>>>> memcpy ((WCHAR *)c, a, ca * sizeof(WCHAR));
>>>> memcpy (((WCHAR *)c) + ca, b, (cb+1) * sizeof(WCHAR)); // copies
>>>>b AND '\0'
>>>>
>>>> return c;
>>>>}
>>>>
>>>>void WINAPI VirtualChannelOpenEvent(DWORD openHandle, UINT event, LPVOID
>>>>pdata, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
>>>>{
>>>>
>>>>...
>>>> switch(event)
>>>> {
>>>> case CHANNEL_EVENT_DATA_RECEIVED:
>>>> {
>>>>static int bBusy = 0;
>>>>
>>>>while(bBusy);
>>>>bBusy = 1;
>>>>
>>>>if (!(dataFlags & CHANNEL_FLAG_FIRST)) { BSTR bstrTmp =
>>>>SysAllocString(pdata);
>>>>BSTR bstrAux = gbstrMensaje;
>>>>gbstrMensaje = ConcatenateBSTR(gbstrMensaje, bstrTmp);
>>>>SysFreeString(bstrTmp);
>>>>SysFreeString(bstrAux);
>>>>} else {
>>>>gbstrMensaje = SysAllocString(pdata);
>>>>}
>>>>
>>>>bBusy = 0;
>>>>
>>>>if (dataFlags & CHANNEL_FLAG_LAST) {
>>>>... }
>>>>
>>>> }
>>>> break;
>>>>
>>>
>>>
>>>
>
>