Comments (18)
ZFrame is a Stream, string reading/writing functions are in StreamReader/StreamWriter class, so I think maybe it's not necessary to encode/decode string byte-by-byte again.
from clrzmq4.
Awesome, you are actually using Unicode! 16bit or 32bit?
You should use
using System;
using System.Text;
using ZeroMQ;
private static void Main(string[] args)
{
var push = new ZSocket(ZSocketType.PUSH);
push.Bind("tcp://127.0.0.1:12345");
var pull = new ZSocket(ZSocketType.PULL);
pull.Connect("tcp://127.0.0.1:12345");
string str = "中文字符串";
Console.WriteLine("str send: {0}", str);
push.SendFrame(new ZFrame(str, Encoding.Unicode));
using (ZFrame frame = pull.ReceiveFrame())
Console.WriteLine("str recv: {0}", frame.ReadString(Encoding.Unicode));
}
This is because ZContext.Encoding
is Encoding.UTF8
... Please, try this one!
The problem with StreamReader
/StreamWriter
classes is, they are closing the stream after their use - and I don't want a ZFrame
being closed before I do so...
from clrzmq4.
Encoding.Unicode is fine.
StreamReader
and StreamWriter
constructor has a leaveOpen
parameter since .net 4.5, maybe that will help:
https://msdn.microsoft.com/en-us/library/gg712853(v=vs.110).aspx
from clrzmq4.
".net 4.5" - I don't want to say they could have done this in ".net 2.0"
from clrzmq4.
For .net 2.0, we can derive a custom class from StreamReader/StreamWriter and override the Dispose method not to close underlying stream.
from clrzmq4.
Yes, this is what ZFrame
is basically all about - Dismiss
, Dispose
and not going to close the stream, when someone is reading from or writing on it.
I also thought about a ZFrameReader
and ZFrameWriter
. But I don't like the creation of additional objects, just to read and to write. This is why I made these functions directly into the stream, the ZFrame
.
from clrzmq4.
Agree. Still I think it's better if we can use StreamReader/Writer with some simple work-around, and not to re-invent the wheels 😄
from clrzmq4.
However, you can do so already... You just need someone initializing your ZFrame on the length of the string.
from clrzmq4.
In fact I think we do not need to support net 2.0 any more
from clrzmq4.
Not .NET 2.0, but I do like .NET 4.0 because it runs on WinXP. .NET 4.5 doesn't.
from clrzmq4.
So what's your plan of this bug? If users are required to use Encoding.Unicode, the API should not have an encoding parameter.
from clrzmq4.
I can try to make a PR of a custom derived StreamReader/Writer if you are OK with this kind of work-around
from clrzmq4.
This is actually a really hard PR, because you need to write a new ZFrame
constructor...
The Encoding
is there to actually read/write a string
on a ZFrame
. This may be removed, if you have a ZFrameReader
and ZFrameWriter
.
You may try...
from clrzmq4.
I will try to make it as simple as possible
from clrzmq4.
The new ZFrame
constructor will be you biggest problem, because you need someone initializing the ZFrame
to a specific Length
. The other changes are in ReadString, ReadLine and WriteString, WriteLine... And you need to make ZFrameReader
/Writer
classes.
Let's see, now I'm curious about your PR :-) (Please try using TAB instead of SPACEs for intendation!)
from clrzmq4.
I am a bit lost here... Was this really a bug? Or was clrzmq4 used in a wrong way? If it was a bug, was is solved by #57? Is there any reason to keep this issue open?
from clrzmq4.
IMO, if you do not care much about the performance hit of memory copy, you can just treat ZFrame as a byte stream.
from clrzmq4.
@goldenbull Sure you can do this.
Is there any reason to keep this issue open from your point of view?
from clrzmq4.
Related Issues (20)
- News on ZeroMQ/clrzmq4 - New Initial Release HOT 4
- NuGet v4.1.0.28 does not include i386 and amd64 libs HOT 10
- latest v4.1.0.30 not include libsodium.dll while create instance HOT 1
- How do you see the times for request/reply messages processed?
- Fails to create ZContext under .net Core 3.0 HOT 7
- Heartbeat incompatibility with jeromq using curve
- Shared library issues with DotNet Core 2.1 under Linux HOT 1
- Nuget package with version that supports netstandard2.0 HOT 4
- Cannot get Ironhouse ZGuideExample to work
- Crash in ZSocket.SendMessage()
- Windows KERNELBASE exception and growing delay HOT 1
- Subscriptions not delivered to late publisher
- Missing Server/Client sockets HOT 1
- Non-conformant nuget package folder layout
- Please, make release with libzmq v4.3.4 included HOT 2
- Better signature to send string from ROUTER to DEALER
- NullReferenceException from ZeroMQ.ZPollItems.PollIn in ROUTER<-->DEALER communication
- Bug in public virtual bool Send(IEnumerable<ZFrame> frames, ZSocketFlags flags, out ZError error) HOT 2
- Correct handling of timeout during polling
- Receive event when a subscriber is connected
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clrzmq4.