Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Problem TCP Recieve Shows in a Textbox


  • Please log in to reply
6 replies to this topic

#1 Bernd

Bernd

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts
  • LocationGermany

Posted 12 October 2012 - 03:57 PM

Hello, I've got a problem with TCP Recieve data. I Recieve data's over TCP from a netduino plus. And now I want to write the data into a textbox. I send a request to the server (netuino) and Netduino sends three data packets back with the "socket.send" command back. Each packet I write into a Temporary String. And when I append the three packet to one string. Like this: clientsocket.Connect(serverEPoint) Dim messag() As Byte = Encoding.UTF8.GetBytes(SendMessage) clientsocket.Send(messag) While True If (clientsocket.Available > 0) Then Dim buffer(clientsocket.Available) As Byte clientsocket.Receive(buffer) TmpResponseMessage = New String(System.Text.Encoding.UTF8.GetChars(buffer)) Responsemessage = Responsemessage & TmpResponseMessage If (Responsemessage.IndexOf("EOF") >= 0) Then Responsemessage = Responsemessage.Replace("EOF", "") Exit While End If End If End While SocketExcept = False Catch ex As SocketException SocketExcept = True End Try 'SocketExcept = myEthernet.Ethernet_Senden("STATUS", RspMessage) TextBox1.Text = ResponseMessage Now the response message looks in the debug mode ok. It contents all three packets. But it write only the first packet into the Textbox. And the rest of the data ist missing in the Textbox but the string ResponseMessage have got the whole String. Have anybod an idea whats the reason can be ?

#2 ErikN

ErikN

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts
  • LocationNew York, NY

Posted 12 October 2012 - 07:39 PM

If the string has the full message but the textbox doesn't show it, the problem must be there. What data are you sending? Does it contain carriage returns and/or newline characters? If so, make sure the textbox is configured to show multiple lines. Just because the size is large enough to hold the text doesn't mean it's smart enough to show more than the first line. Next try to write out the characters to a file and open it with a hex editor or Word or Wordpad (but not Notepad) to see if there are "special" characters you don't expect in the string. Visual Studio will strip most of these out when you hover over to preview the string value so it will display correctly. But these characters could still exist and the textbox might be confused by them and not interpreting contents beyond them. This is less likely to me as the answer but it's the only other thing I can think of without seeing the actual text you're receiving and trying to assign to the textbox to display.

#3 Bernd

Bernd

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts
  • LocationGermany

Posted 13 October 2012 - 02:24 PM

Hello ErikN, Thank you for the answer. My first think was also that the reason for the failure must be a special character in the string. In the Debug mode I copied the String into Word but it shows no special character. I send three sentence with socket.send(). The first line is "LED is:TrueDD" the second is "LED is:FG" and the third "StatEOF" EOF means the end of the string and I´m remove this with a string function. The whole sentence is then "LED is:TrueDD LED is:FG Stat". The sentence content makes no sense it's only a test string. The strange thing is when I remove the space between the second and the third sentence, when it will show the whole sentence in the textbox. When I don't do this it will print out only the first sentence. Maybe the send command set a special character on the end of sentence but I don't know what it is. Or the problem it's up to UTF8. Because I have to change the string in UTF8 and recieve it in UTF8 and when I change it in a string again. But another strange think is I can printed out in a label an that work.

#4 Bernd

Bernd

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts
  • LocationGermany

Posted 13 October 2012 - 02:25 PM

I forget to send a picture that shows the problem. Here it is:

Attached Files



#5 ErikN

ErikN

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts
  • LocationNew York, NY

Posted 13 October 2012 - 05:51 PM

So a Label control displays it fine, but Textbox still has a problem with the space? That's really strange but not completely unexpected. The Textbox control is not ... great. You might try converting to ASCII instead of UTF8 and see what the output becomes.

#6 Bernd

Bernd

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts
  • LocationGermany

Posted 14 October 2012 - 09:45 PM

Hello, I found the problem. I convert it into ASCII chars. And the string contains ASCII 0 that means nothing. And That was the problem. It seems that Labels don't care about this. But Text- and Listboxes abort the output text. But anyhow thanks for the help.

#7 ErikN

ErikN

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts
  • LocationNew York, NY

Posted 14 October 2012 - 10:49 PM

Glad it's worked out!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.