Sending ASCII character string / stream to an IP address

P

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
 
J

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.
 
P

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
 
V

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
 
J

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top