473,799 Members | 3,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Net.Sockets and encoding.ascii

Hi All,

I am trying to send information from my vb.Net
app to a piece of hardware with an embedded
TCP/IP controller using sockets.

I can send information so the sockets are working
but the data is garbage!!!

It works if the ascii of the character I am sending
is less than 127, however, if I send ascii 128 or
above (up to 255, obviously) then things start to
go wrong.

I am sure it is to do with the encoding of the
byte and thee fact that it seems to be signed
as oppossed to unsigned.

Decimal 1 in binary is
00000001

Decimal 127 in binary is
011111111

In an unisgned int, decimal 128 is
100000000

and decimal 255 is
11111111

How can I get this to be outputted to my
embedded controller using sockets???

Please help.

This is what I have used for my output stream to the
socket.

Dim writer As New IO.StreamWriter (m_Client.GetSt ream(),
System.Text.Enc oding.ASCII)

Regards,

Jason.
Nov 21 '05 #1
3 2007
Hi,

Encoding.Ascii supports only ASCII (characters with values between 0 and
127, as you have observed). You should use a binary Writer, not Text.

Dim writer As New BinaryWriter(St ream)

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004.
Nov 21 '05 #2
Hi,

Encoding.Ascii supports only ASCII (characters with values between 0 and
127, as you have observed). You should use a binary Writer, not Text.

Dim writer As New BinaryWriter(St ream)

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004.
Nov 21 '05 #3
Thanks DIck,

that works great.

Jason.
On Thu, 23 Sep 2004 10:27:25 -0600, "Dick Grier"
<di************ **@msn.com> wrote:
Hi,

Encoding.Asc ii supports only ASCII (characters with values between 0 and
127, as you have observed). You should use a binary Writer, not Text.

Dim writer As New BinaryWriter(St ream)

Dick


Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3799
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for pending connections every 500ms. I also have a vb6 application that uses the WinSock control at the other end of the communication tunel. I have to work with vb6 here because it uses less memory than .NET.
1
1377
by: Dave | last post by:
I'm have an app the opens a socket and I want the socket to stay open till the user clicks a button. I pass a string of "m_start" to start a listener, and "m_end" to the function listen_func to stop the code. The problem is when I try to compile the code I receive the error, "The type or namespace name 'myListener' could not be found." The code is as follows, public void listen_func(string m_s) { if (m_s=="m_start") {
7
14102
by: Rex Winn | last post by:
I've Googled until my eyes hurt looking for a way to issue Telnet commands from C# and cannot find anything but $300 libraries that encapsulate it for you. I don't want to be able to create a Telnet client. I just need to send a telnet request to a local IP address on a LAN issue a "c" then a "b" and stream back the text for internal use. The "c" changes sub-menus and the "b" is a switch to dump the status of a firewall. I need to issue...
1
1551
by: Brian Henry | last post by:
Hello, I was tring to learn socket's (being i never used them before) and have a simple question. I want to create a listner that will get any data recieved and print it out. I've been able to get it to recieve only one line of data, but the next one i send to it wont be printed like the 1st one. I had a listner running in a thread, does anyone have a simple listner code example that would show how to have a tcplistner thread running...
0
1541
by: Tim Wagaman | last post by:
I an having issuses with a loop I am running to keep checking for messages coming across our line. The goal: Listen for messages on port 5001 and print the messages into a text file. The port must stay open at all times and only close if no activity for 60 seconds. The problem: If I do a read on a networkstream and the connection is closed
0
323
by: Jason L James | last post by:
Hi All, I am trying to send information from my vb.Net app to a piece of hardware with an embedded TCP/IP controller using sockets. I can send information so the sockets are working but the data is garbage!!! It works if the ascii of the character I am sending
1
11304
by: Prasanta | last post by:
Hello, Please cnay one can tell me how to read mail as formatted.... i have made some code using that able to read but not able to serialize..... so am i need to parse the HTML, or is there any class using that i can directly get the full info ablt the mail, like TO,From,Subject,Body,Attachments, Below is the code which i develop, using System;
1
5689
by: Prasanta | last post by:
Hello, How to read a mail from the mail server as formatted. I am able to read the mail as row HTML, is there any class, or something method using that i can easily get the all info of that mail, like as TO,From,Subject,Body. here I am attaching my coe which i developed. using System; using System.Collections.Generic; using System.Text;
3
11043
by: shahla.saeed | last post by:
hi, plzz check my code and let me know where the problem is lying...becuase whenever i try to tansfer the file of 573KB(mp3) it just tranfer few Kb of file(Somtimes 5.2Kb,somtimes 32Kb..every time i run the program).....but when i watch the transfering of bytes by debuging it.(RED dot on while(nfs.CanRead) )..it shows that complete bytes are transfered.(in my case i-e 573Kb)....i am unable to understand whats going wrong in my program....
1
3796
by: =?Utf-8?B?RGFydGgtQ3ot?= | last post by:
Hi, I'm beginner in Visual C++ so I want to ask you a question. And I'm not good in English:D So I have the program which communicates over sockets. The program has to connect to the server and send and receive data. But when I start the program, there is one Socketexception - something like the program is unable to connect to the server or the server didn't answer... I apologize for my English... Thank you for advice...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.