471,319 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Sending ASCII character string / stream to an IP address

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
Feb 17 '06 #1
5 8687
Hi,

ASCIIEncoding.GetBytes will help you
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Paul Aspinall" <pa**@aspy.co.uk> wrote in message
news:Cp*******************@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

Feb 17 '06 #2
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.

Feb 17 '06 #3
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

"JustinC" <ju***********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.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.

Feb 17 '06 #4
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
Feb 17 '06 #5
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.

Feb 17 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Danny Tuppeny | last post: by
7 posts views Thread by Bob Garbados | last post: by
4 posts views Thread by Robert McNally | last post: by
19 posts views Thread by ... | last post: by
9 posts views Thread by Miro | last post: by
2 posts views Thread by luchyloo | last post: by
10 posts views Thread by Markgoldin | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.