Re: How do I stop a Winsock from buffering characters?



Hi Paul,

Thanks for your help. So you have been able to send one character at a
time? I have set the property NoDelay on both my clent and server app and I
am not seeing this? Would I be able to have a copy of your test code? Maybe
I can figure it out like that?

Thanks in advance
--
Don


"Paul G. Tobey [eMVP]" wrote:

In case you're wondering, the NoDelay property *does* control the Nagle
algorithm (as I just verified). I have no problems with losing characters.
I'm using a BinaryReader on one end and a BinaryWriter on the other end...

Paul T.

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:uvYCOVbvHHA.4796@xxxxxxxxxxxxxxxxxxxxxxx
And? I'm unconvinced that that property controls the Nagle algorithm as
it's applied at the OS level to the socket. To be sure, you might try
doing client.Client.SetSocketOption( SocketOptionLevel.Tcp,
SocketOptionName.NoDelay, 1 ), just to be sure. If that doesn't seem to
be doing anything (not as far as what characters actually get through, but
as far as the delay), I don't know what to tell you; it should work.

Paul T.

"Don" <Don@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9656221D-D40F-408A-8F76-FF4BD8C2C615@xxxxxxxxxxxxxxxx
Hi Paul

I changed my code to the following:

try
{
client.NoDelay = true;
Stream s = client.GetStream();
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);
sw.AutoFlush = true;
//Console.WriteLine(sr.ReadLine());
Int32 var1 = 0x01;
Int32 var2 = 0x02;
string myString =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZzyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIH";
int iCounter = 1;
while (true)
{
/*
Console.Write("Name: ");
name = Console.ReadLine();
sw.WriteLine(name);
if (name == "") break;
Console.WriteLine(sr.ReadLine());
*/
if (iCounter != 0)
{
iCounter--;
sw.Write(myString);
sw.Flush();
}
// sw.Write(var2);
// sw.WriteLine("test string");
// Console.WriteLine(sr.ReadLine());
}
s.Close();
}
finally
{
// code in finally block is guranteed
// to execute irrespective of
// whether any exception occurs or does
// not occur in the try block
client.Close();
}


Notice I set
client.NoDelay = true;
This has no effect.
--
Don


"Paul G. Tobey [eMVP]" wrote:

"Right away" isn't going to happen easily. That's a function of TCP/IP.
There's a lot of data wrapped around any packet that's sent over the
network
and wrapping a single byte is a serious waste of bandwidth. The TCP
stack
will automatically stick bytes together into larger groups, if they are
sent
close to one another in time, attempting to avoid exactly what you're
trying
to do. You can turn that off, but, if this is part of your real design,
it's a bad design.

If you feel like this has to be done for testing, you want to set a
socket
option to turn off the Nagle algorithm. That should be documented in
whatever the socket option setting call for managed code is. It might
be
something like TCP_NODELAY, which is what it is in native code/WinSock.

Paul T.

"Don" <Don@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0B5F1EA6-459C-4EFE-B556-800FB22FA7F2@xxxxxxxxxxxxxxxx
Hi Paul,

Byte the way I am executing this code on the same PC. I did try
changing
the client to sent it like this:

try
{
Stream s = client.GetStream();

StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);
sw.AutoFlush = true;
//Console.WriteLine(sr.ReadLine());
Int32 var1 = 0x01;
Int32 var2 = 0x02;
string myString =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZzyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIH";
System.Text.ASCIIEncoding encoding = new
System.Text.ASCIIEncoding();
byte[] bCommand = encoding.GetBytes(myString);

int iCounter = 1;
while (true)
{
/*
Console.Write("Name: ");
name = Console.ReadLine();
sw.WriteLine(name);
if (name == "") break;
Console.WriteLine(sr.ReadLine());
*/
if (iCounter != 0)
{
iCounter--;
sw.Write(bCommand);
sw.Flush();
}
// sw.Write(var2);
// sw.WriteLine("test string");
// Console.WriteLine(sr.ReadLine());
}
s.Close();
}
finally
{
// code in finally block is guranteed
// to execute irrespective of
// whether any exception occurs or does
// not occur in the try block
client.Close();
}

Doing this causes the MessageService() to never get called no matter
howmany
characters I add to the string. I just wan to send one character at a
time
from the client code and have the server see it right away. How do I
do
it?
Thanks in advance

The

--
Don


"Paul G. Tobey [eMVP]" wrote:

A little too much code to read in-line...

I don't see the server reads that you're talking about as having
dropped
the
first character of the client send. You've sent a bunch of
server-side
code, (at least it *looks* like it might be server-side code), but
not
the
code in question. At a guess, you're probably sending Unicode from
the
Windows CE side and receive ASCII on the server side. Since most of
the
Unicode characters will be 0x00xy where xy makes up the ASCII
character,
that's probably the source of the problem. If you convert everything
to
bytes, and convert strings to ASCII before converting them to bytes,
if
ASCII is what you want to send, I think you'll find your problem.

Paul T.

"Don" <Don@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:865A7119-F69B-45F3-9C1D-045506172955@xxxxxxxxxxxxxxxx
HI

I have two apps one is a Winsock Client as in the following:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace SocketTestClient
{


class EmployeeTCPClient
{
public static void Main(string[] args)
{
//string name = (args.Length < 1) ? Dns.GetHostName() :
args[0];
string name = Dns.GetHostName();
try
{
IPAddress[] addrs = Dns.Resolve(name).AddressList;
foreach (IPAddress addr in addrs)
Console.WriteLine("{0}/{1}", name, addr);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}

TcpClient client = null;

do
{

try
{
//TcpClient client = new TcpClient(args[0],
2055);
client = new TcpClient(name, 2055);
}
catch (SocketException e)
{
Console.WriteLine(e.Message);
Thread.Sleep(500); // Try again in 0.5s
}
} while (client == null);

try
{
Stream s = client.GetStream();
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);

sw.AutoFlush = true;
//Console.WriteLine(sr.ReadLine());
Int32 var1 = 0x01;
Int32 var2 = 0x02;
string myString =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZzyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIH";
int iCounter = 1;
while (true)
{
/*
Console.Write("Name: ");
name = Console.ReadLine();
sw.WriteLine(name);
if (name == "") break;
Console.WriteLine(sr.ReadLine());
*/
if (iCounter != 0)
{
iCounter--;
sw.Write(myString);
sw.Flush();
}
// sw.Write(var2);
// sw.WriteLine("test
string");
// Console.WriteLine(sr.ReadLine());
}
s.Close();
}
finally
{
// code in finally block is guranteed
// to execute irrespective of
// whether any exception occurs or does
// not occur in the try block
client.Close();
}
}
}
}

and one is a Winsock Server as in the following


lType = sr.ReadInt32();
lSize = sr.ReadInt32();
}
.



Relevant Pages

  • Re: How do I stop a Winsock from buffering characters?
    ... it's applied at the OS level to the socket. ... Stream s = client.GetStream; ... from the client code and have the server see it right away. ... first character of the client send. ...
    (microsoft.public.windowsce.embedded)
  • Re: How do I stop a Winsock from buffering characters?
    ... from the client code and have the server see it right away. ... I don't see the server reads that you're talking about as having dropped ... first character of the client send. ... public delegate int MessageFn(long MessageType, ...
    (microsoft.public.windowsce.embedded)
  • Re: file transfer with sockets
    ... confirmation from client for each chunk before sending the next? ... to server, server interprets command, executes it, then simply returns ... files (hence the reading in chunks). ... sending the bytes over the stream. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I stop a Winsock from buffering characters?
    ... The client is just doing this to send: ... Stream s = client.GetStream; ... I just wan to send one character ... from the client code and have the server see it right away. ...
    (microsoft.public.windowsce.embedded)
  • Re: Client Server
    ... Otherwise, read a file in via a stream, make any required updates, and write ... > myself and compares it to the data that the client has sent to ... My response, though it was very general in nature, assumed exactly what you ... at some point you want the server to read this file in. ...
    (comp.lang.java.help)

Loading