[Python-au] Iron Python Byte Array / String question
kingsleyturner at westpac.com.au
Fri Aug 25 02:57:33 CEST 2006
The Iron Python moderator hasn't approved my mailing list
subscription yet, so here's a question...
rx_buffer = '*' * 1024
rx_buffer = System.BitConverter.GetBytes(rx_buffer.ToCharArray())
bytes_rx = System.Net.Sockets.Socket.Receive(self.socket,rx_buffer)
if (bytes_rx > 0):
encoder = System.Text.UTF8Encoding()
self.incoming_message += encoder.GetBytes(rx_buffer) ### LINE 127
print "MESSAGE ["+self.incoming_message+"]"
However, I can't convert the byte array back to any kind of string:
Accepted Connection from 127.0.0.1:3975!
Unhandled Exception: IronPython.Runtime.Exceptions.ArgumentTypeException:
Cannot convert Array[Byte](System.Byte) to String
at IronPython.Runtime.Converter.ConvertToString(Object value)
at Add##114(Object , Object )
at IronPython.Runtime.Calls.CallTarget2.Invoke(Object arg0, Object
context, Object arg0, Object arg1)
context, Object arg0)
at IronPython.Runtime.Operations.Ops.Call(Object func, Object arg0)
op, Object self, Object arg0)
op, Object self, Object arg0)
at IronPython.Runtime.Types.DynamicType.Add(Object self, Object other)
at IronPython.Runtime.Operations.Ops.Add(Object x, Object y)
at IronPython.Runtime.Operations.Ops.InPlaceAdd(Object x, Object y)
at __main__.receiveData$f9(FunctionEnvironment16Dictionary $env, Object
self) in C:\chatterbox.py:line 127
at IronPython.Runtime.Calls.Function1.Call(ICallerContext context,
Any sage advice on how to convert that Array[Byte] to a String?
Looking at some C# example code, what I'm doing seems the right approach,
but obviously summat isn't right.
(obnoxious non-removable corporate .sig follows, my apologies)
Please consider our environment before printing this email.
WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately.
It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments.
This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision.
Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency.
Westpac Banking Corporation ABN 33 007 457 141.
More information about the python-au