Home All Groups Group Topic Archive Search About

Sending ASCII character string / stream to an IP address

Author
17 Feb 2006 1:42 PM
Paul Aspinall
Hi
I want to send an ASCII character string / stream to an IP address.

I basically have 6 barcode printers, and a web interface.
Depending on what is entered on the web page, will determine which printer
the label is printed on (ie. which IP address the ASCII string / stream is
sent to).

How can I send an ASCII string / stream to an IP address??

Thanks

Author
17 Feb 2006 2:03 PM
Ignacio Machin ( .NET/ C# MVP )
Hi,

ASCIIEncoding.GetBytes will help you


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Show quote
"Paul Aspinall" <p***@aspy.co.uk> wrote in message
news:CpkJf.15953$YJ4.13771@fe2.news.blueyonder.co.uk...
> Hi
> I want to send an ASCII character string / stream to an IP address.
>
> I basically have 6 barcode printers, and a web interface.
> Depending on what is entered on the web page, will determine which printer
> the label is printed on (ie. which IP address the ASCII string / stream is
> sent to).
>
> How can I send an ASCII string / stream to an IP address??
>
> Thanks
>
>
Author
17 Feb 2006 2:20 PM
JustinC
Paul,

I'm going to assume that you already have some way to pass information
worked out, either TCP, UDP, or something else. If this isn't so just
respond and I can help with that, but for now, to keep this short,
here's how to do what you want.

You want to parse your ASCII string into a byte array. Try this

byte[] data = Encoding.ASCII.GetBytes(yourASCIIstring);

Now you have your ASCII string in a byte array that can be written to
the network anyway you choose. Does this help? If you wanted to know
how to actually send this byte array let me know.
Author
17 Feb 2006 2:48 PM
Paul Aspinall
Hi Justin,

Thanks for the help

Yes - do you have some code (any, but C# preferred), that will send this
string to an IP address??

Thanks


Paul

Show quote
"JustinC" <justin.cre***@gmail.com> wrote in message
news:1140186005.489488.16570@g44g2000cwa.googlegroups.com...
> Paul,
>
> I'm going to assume that you already have some way to pass information
> worked out, either TCP, UDP, or something else. If this isn't so just
> respond and I can help with that, but for now, to keep this short,
> here's how to do what you want.
>
> You want to parse your ASCII string into a byte array. Try this
>
> byte[] data = Encoding.ASCII.GetBytes(yourASCIIstring);
>
> Now you have your ASCII string in a byte array that can be written to
> the network anyway you choose. Does this help? If you wanted to know
> how to actually send this byte array let me know.
>
Author
17 Feb 2006 4:01 PM
Vadym Stetsyak
Hello, Paul!

PA> How can I send an ASCII string / stream to an IP address??

TcpClient tcpClient = new TcpClient ();
IPAddress ipAddress = Dns.GetHostEntry ("www.contoso.com").AddressList[0];

tcpClient.Connect (ipAddress, 11003);

NetworkStream netStream = tcpClient.GetStream ();

if (netStream.CanWrite)
{
    Byte[] sendBytes = Encoding.UTF8.GetBytes ("Is anybody there?");
    netStream.Write (sendBytes, 0, sendBytes.Length);
}

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Author
17 Feb 2006 8:02 PM
JustinC
Paul,

The wau Vadym shows here is exactly the way you want to do it, provided
that your webservice is running on port 11003 and accepting TCP
connections. As for TCP, it probably is, but it could be running UDP.
As for the port, that's different for every web service, and your
webservice may also be accepting transmissions from several ports. Try
what he showed, but with using ASCII instead of UTF8, and if it doesn't
work just reply to this and we'll try something else.

AddThis Social Bookmark Button