Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 3.5 compatibility #98

Closed
cncfanatics opened this issue Aug 30, 2013 · 130 comments
Closed

.NET 3.5 compatibility #98

cncfanatics opened this issue Aug 30, 2013 · 130 comments

Comments

@cncfanatics
Copy link

I write games using Unity 3D.

Unity 3D uses mono to run managed code, while the engine itself is written in another language.
This means all extra programming happens using mono. Unfortunatly, it's a rather outdated version of mono that doesn't have any of the features of .NET 4.0.

NetMQ refuses to run on it, is it possible to fix this ?

(I could possibly do this myself with some guidance on how to do this)

@somdoron
Copy link
Member

Download the source code and try to compile with .net 3.5, I don't think
the project is using some .net 4 features.

On Fri, Aug 30, 2013 at 2:37 PM, Diego Duclos notifications@github.comwrote:

I write games using Unity 3D.

Unity 3D uses mono to run managed code, while the engine itself is written
in another language.
This means all extra programming happens using mono. Unfortunatly, it's a
rather outdated version of mono that doesn't have any of the features of
.NET 4.0.

NetMQ refuses to run on it, is it possible to fix this ?

(I could possibly do this myself with some guidance on how to do this)


Reply to this email directly or view it on GitHubhttps://github.com//issues/98
.

@tobi-tobsen
Copy link
Contributor

I quickly created a patch which compiles under 3.5 client profile.
As you see, I didn't change the Security and NetMQScheduler but just delete/excluded both. Also the tests still compile under 4.0 because they make excessive use of Task
I you want to have the NetMQScheduler, you might want to implement a ConcurrentBag using one of those approach mentioned in this Stackoverflow Question.

I think others than compiling under 3.5 client profile, you might check out issue #7 for other open issues regarding mono support. If you worked around those, be sure to submit a pull request ;-)

@cncfanatics
Copy link
Author

Patch applied, it compiles perfectly indeed, I'll be testing it in the next few days as I change my app to use NetMQ instead of clrzmq

Thanks!

@cncfanatics
Copy link
Author

I can confirm this looks good after some initial quicktesting with mono 2.6! This is currently on windows, but I'll be testing on linux soon as well and report what I find 👍

Is it worth considering making the code compile under both environments and add preprocessor statements around functionality making heavy use of the 4.0 framework ?

@reiroldan
Copy link
Member

There are quite a few people wanting to use netmq within Unity3D so I think it's a welcome addition @cncfanatics.

@JamesWHurst
Copy link
Contributor

What is the current status of this? I'm interested in this too - creating a software component that needs to be deployable on .NET 3.5. I'm using compiler pragmas PRE_4 to signal use of pre-.NET 4.0 features, and PRE_5 to signal use of pre-.NET 4.5/C# 5.0 features. Which does give me some gnashing of teeth as I do love using the latest language features!

@JamesWHurst
Copy link
Contributor

I now have a solution for the .NET 3.5 compatibility issue, and am about to submit a request to update. This only targets the Windows side - if it's accepted then I'll also do the Mono side if that is wished. Included in this are some edits to the tests to make them compile/test under 3.5. It was necessary to incorporate a conditional-compilation symbol: "PRE_4", to signal that the project is to be built using only pre- .NET 4.0 features. The Security is included, but I omitted NetMQScheduler since that probably doesn't make much sense under 3.5. I built and tested on a virtual machine which has only VS 2008, and no .NET higher than 3.5. This is my first contribution so any advice would be appreciated.

@luna-duclos
Copy link

I'd personally be a big fan of the mono side.
Unity specifically uses a rather old version of mono which would require this.

@JamesWHurst
Copy link
Contributor

Ok - working on that now (I'm between jobs at the moment, lamentably, so I have some time to devote to this right now). Exactly which version of Mono does the current version of Unity require? And - btw, what is the exact command-path that one uses to submit a 'git push' of one's changes? I'm getting various errors as I try different variations of the line under [remote "origin"]. I tried url = ssh://git@github.com/zeromq/netmq.git, and other variations with my user nickname ( JamesWHurst ) at various places within that. None work.

@reiroldan
Copy link
Member

Unity targets 3.5 features of Mono though it uses a custom build. I'm not exactly sure what the changes they applied are, but I believe that just targeting the 3.5 .net framework should suffice.

@JamesWHurst Regarding the push issues you are having, please read: https://help.github.com/articles/fork-a-repo

@JamesWHurst
Copy link
Contributor

I had read that page - those commands are not working for me. Eg, git push results in ERROR: Permission to zeromq/netmq.git denied to JamesWHurst. fatal: Could nto read from remote repository.

@reiroldan
Copy link
Member

Because you are trying to push to the main repository and not your forked copy. You should fork the main, pull that, make a branch, write your changes, commit / push. Go back to github and a nice little button "pull something something" will show up.

@JamesWHurst
Copy link
Contributor

Ok. I had clicked on the "Fork" button on the github page. I didn't see anything happen. I had pulled that down onto my local drive, put my edits there. So, just now, I created a branch on my local box using git branch Net35CompatFix (the intent was to name the branch Net35CompatFix). Then I entered git checkout Net35CompatFix to move over to that branch. Now, how do you bring this branch up to Github? On the Github page, I created the branch named Net35CompatFix. Do I now need to enter the command: git push --set-upstream origin Net35CompatFix ? Or does that push my edits into the master instead of into my branch?

@almazik
Copy link
Contributor

almazik commented Oct 15, 2013

James,

It seems that you are not familiar with Pull Requests contribution model. I
suggest you to read the following article first:
https://help.github.com/articles/using-pull-requests

On Tue, Oct 15, 2013 at 10:21 PM, James Hurst notifications@github.comwrote:

Ok. I had clicked on the "Fork" button on the github page. I didn't see
anything happen. I had pulled that down onto my local drive, put my edits
there. So, just now, I created a branch on my local box using git branch
Net35CompatFix (the intent was to name the branch Net35CompatFix). Then I
entered git checkout Net35CompatFix to move over to that branch. Now, how
do you bring this branch up to Github? On the Github page, I created the
branch named Net35CompatFix. Do I now need to enter the command: git push
--set-upstream origin Net35CompatFix ? Or does that push my edits into the
master instead of into my branch?


Reply to this email directly or view it on GitHubhttps://github.com//issues/98#issuecomment-26364137
.

@JamesWHurst
Copy link
Contributor

That is correct. I have used many other version-control systems, but never Git. I have a little book here, "Pragmatic Guide to Git", which doesn't feel like it's quite helping. And that article you list - I'd already read. It explains a few generic concepts, but the specific commands it lists don't seem to work. Nothing seems to be working as it is supposed to. I guess I should have just done a very tiny edit or bug-fix before attempting this, so that I wouldn't have wasted so many days before discovering this is something I cannot use.

@JamesWHurst
Copy link
Contributor

Actually - no. I had already done the Fork, cloned the repo to my desktop cptr, created a branch, and then added and committed my changes to my local branch. And I created a branch on that Github page by the same name - Net35CompatFix, by clicking on the webpage-control. And, I understand how to make a pull-request. It is just the process of pushing my repo from my local machine, up to the branch on the Github repo, that is not happening. At this point it would have been faster to copy it onto a pile of floppy-disks, duck-tape those to the back of a turtle, and send it in the direction of the Github server to be manually unpacked and transferred. This is why I should try to stay away from open-source.

@reiroldan
Copy link
Member

James... you create the branch on your local fork (on your computer).

Regarding your comment on why you stay away from open-source, sad you think that way, but given the hundreds of thousands of people currently working with github, I doubt it's a problem with OSS/git ;)

@JamesWHurst
Copy link
Contributor

I had. Perhaps it is best to start over. I receive a ton of 'how-to' advice, most of which turned out to be incorrect.
The first step is for Fork, right? And we accomplish this by clicking on the "Fork" button at the upper-right corner of the Github project page? Attached is a screenshot of it, after I clicked on it. The only change I see, is that the number to the right of it incremented from 34 to 35. Is this correct so far?
fork

@reiroldan
Copy link
Member

Now, the "HTTPS clone url" on the bottom right is the url you should be cloning onto your computer. This is your "personal" version of the repository as you can see from the "JamesWHurst/netmq" project. Make a branch, make your changes, commit and push. Then, from your repository on git, you'll be offered the option to create a pull request to the main repository, which we can then pull in.

@JamesWHurst
Copy link
Contributor

Aha! Thx. So on my local box I entered at a command-line: git clone https://githumb.com/JamesWHurst/netmq.git
That seemed to operate ok.
To confirm: the next steps are to create a branch on my local box, merge in my changes, commit, and then enter "git push" - right?

@reiroldan
Copy link
Member

Basically yes, you create a branch on local box, hack on it, commit then push.
After that, you go to your repo at: https://github.com/JamesWHurst/netmq and you'll get an option to create a pull request from your committed branch.

On a side note, until you get accustomed to using git, you might want to give a git gui tool a try, something like TortoiseGit or SmartGit. (I personally use TortoiseGit as its quite fast and simple to use).

@JamesWHurst
Copy link
Contributor

What exactly is the correct command to push the commits back to my branch on the repo? On my local box, I am "in" branch Net35CompatFix. When I entered "git push", it responds: fatal: The current branch Net35CompatFix has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin Net35CompatFix.
Is that what I need to enter?
Thanks,
jh

@reiroldan
Copy link
Member

I believe you'd do: git push -u origin Net35CompatFix

the -u will automagically add the upstream for you for future uses, so you'd be able to perform a git push, on successive pushes without being asked for the upstream branch.

@JamesWHurst
Copy link
Contributor

Thank you reiroldan - I appreciate your help. Your recommendation worked splendidly, and the Pull Request is in.

I appreciate your helping me through this!

jh

@reiroldan
Copy link
Member

Glad I could help you through that ;)

@DirkBroenink
Copy link

Hi, I'd also like to make use of NetMQ in Unity3d. I do not know enough about GitHub yet to know how all this works. If I understand correctly, you can either download tobi-tonsen's patch or JamesWHurst's branch, and you should get NetMQ compatible with .NET 3.5. However, I don't know how to do either of these. (I tried looking around for a while, but I wouldn't know where to begin.)

If I download tobi-tonsen's patch, how do I apply it?
Where can I find the download for JamesWHurst's branch?

@somdoron
Copy link
Member

somdoron commented Jul 7, 2014

download git from http://git-scm.com/downloads and install git for windows.

open command prompt and create a directory for your git repositories.

than run "git clone https://github.com/PSG-Sakari/netmq.git"

you now have a new directory called NetMQ, open it, open src folder, open
the solution and compile.

On Mon, Jul 7, 2014 at 2:01 PM, Taboen notifications@github.com wrote:

Hi, I'd also like to make use of NetMQ in Unity3d. I do not know enough
about GitHub yet to know how all this works. If I understand correctly, you
can either download tobi-tonsen's patch or JamesWHurst's branch, and you
should get NetMQ compatible with .NET 3.5. However, I don't know how to do
either of these. (I tried looking around for a while, but I wouldn't know
where to begin.) Could anyone give me some pointers?


Reply to this email directly or view it on GitHub
#98 (comment).

@DirkBroenink
Copy link

Thanks!

It worked!

Question: how did you know about the existence of the PSG-Sakari fork? Next
time I should be able to find something like that myself.

On Mon, Jul 7, 2014 at 1:15 PM, Doron Somech notifications@github.com
wrote:

download git from http://git-scm.com/downloads and install git for
windows.

open command prompt and create a directory for your git repositories.

than run "git clone https://github.com/PSG-Sakari/netmq.git"

you now have a new directory called NetMQ, open it, open src folder, open
the solution and compile.

On Mon, Jul 7, 2014 at 2:01 PM, Taboen notifications@github.com wrote:

Hi, I'd also like to make use of NetMQ in Unity3d. I do not know enough
about GitHub yet to know how all this works. If I understand correctly,
you
can either download tobi-tonsen's patch or JamesWHurst's branch, and you
should get NetMQ compatible with .NET 3.5. However, I don't know how to
do
either of these. (I tried looking around for a while, but I wouldn't
know
where to begin.) Could anyone give me some pointers?


Reply to this email directly or view it on GitHub
#98 (comment).


Reply to this email directly or view it on GitHub
#98 (comment).

@cncfanatics
Copy link
Author

I've put in a pull request for it, you can see it under the pull requests
list in the original repo :)

Note: I'm planning on updating that fork soon with a more up-to-date way of
supporting both 3.5 and 4.5 if you're interested.
You'll see the changes appear likely tonight or tomorrow

On Mon, Jul 7, 2014 at 2:19 PM, Taboen notifications@github.com wrote:

Thanks!

It worked!

Question: how did you know about the existence of the PSG-Sakari fork?
Next
time I should be able to find something like that myself.

On Mon, Jul 7, 2014 at 1:15 PM, Doron Somech notifications@github.com
wrote:

download git from http://git-scm.com/downloads and install git for
windows.

open command prompt and create a directory for your git repositories.

than run "git clone https://github.com/PSG-Sakari/netmq.git"

you now have a new directory called NetMQ, open it, open src folder,
open
the solution and compile.

On Mon, Jul 7, 2014 at 2:01 PM, Taboen notifications@github.com
wrote:

Hi, I'd also like to make use of NetMQ in Unity3d. I do not know
enough
about GitHub yet to know how all this works. If I understand
correctly,
you
can either download tobi-tonsen's patch or JamesWHurst's branch, and
you
should get NetMQ compatible with .NET 3.5. However, I don't know how
to
do
either of these. (I tried looking around for a while, but I wouldn't
know
where to begin.) Could anyone give me some pointers?


Reply to this email directly or view it on GitHub
#98 (comment).


Reply to this email directly or view it on GitHub
#98 (comment).


Reply to this email directly or view it on GitHub
#98 (comment).

@DirkBroenink
Copy link

Just be sure I am getting this. You are requesting to put your changes into
zeromq/netmq with that pull request, right?

Also, if it's yours, you should know I had some problems compiling your
version with VS2012, I had to comment out the entire NetMQScheduler class
in order for the compilation to work for the Net35 project. It compiled out
of the box for all other projects, but not for Net35. These are the errors
I got when compiling the first time:

  • Error 7 The type or namespace name 'ThreadLocal' could not be found (are
    you missing a using directive or an assembly reference?)
    C:\Users\Dirk\Desktop\netmq-master\src\Net45\NetMQScheduler.cs 25
  • Error 8 The type or namespace name 'ThreadLocal' could not be found (are
    you missing a using directive or an assembly reference?)
    C:\Users\Dirk\Desktop\netmq-master\src\Net45\NetMQScheduler.cs 26

etc etc, for classes ThreadLocal, TaskScheduler, Task, ConcurrentBag,
Concurrent, TryExecuteTask, TaskCreationOptions. In other words, for .NET
4.0 specific classes.
Notice how it gave the errors when compiling the Net35 project, but the
path is in the Net45. I don't understand why this happens, but when I
commented out the entire class it worked. This was the only class in which
errors occurred. (Commenting out the class caused new errors in the
TestNetMQScheduler class, but I don't need that to work).

After commenting it, compiling a new version, it works perfectly in
Unity3D.

Gr, Dirk

On Mon, Jul 7, 2014 at 2:20 PM, Diego Duclos notifications@github.com
wrote:

I've put in a pull request for it, you can see it under the pull requests
list in the original repo :)

Note: I'm planning on updating that fork soon with a more up-to-date way
of
supporting both 3.5 and 4.5 if you're interested.
You'll see the changes appear likely tonight or tomorrow

On Mon, Jul 7, 2014 at 2:19 PM, Taboen notifications@github.com wrote:

Thanks!

It worked!

Question: how did you know about the existence of the PSG-Sakari fork?
Next
time I should be able to find something like that myself.

On Mon, Jul 7, 2014 at 1:15 PM, Doron Somech notifications@github.com
wrote:

download git from http://git-scm.com/downloads and install git for
windows.

open command prompt and create a directory for your git repositories.

than run "git clone https://github.com/PSG-Sakari/netmq.git"

you now have a new directory called NetMQ, open it, open src folder,
open
the solution and compile.

On Mon, Jul 7, 2014 at 2:01 PM, Taboen notifications@github.com
wrote:

Hi, I'd also like to make use of NetMQ in Unity3d. I do not know
enough
about GitHub yet to know how all this works. If I understand
correctly,
you
can either download tobi-tonsen's patch or JamesWHurst's branch, and
you
should get NetMQ compatible with .NET 3.5. However, I don't know how
to
do
either of these. (I tried looking around for a while, but I wouldn't
know
where to begin.) Could anyone give me some pointers?


Reply to this email directly or view it on GitHub
#98 (comment).


Reply to this email directly or view it on GitHub
#98 (comment).


Reply to this email directly or view it on GitHub
#98 (comment).


Reply to this email directly or view it on GitHub
#98 (comment).

@somdoron
Copy link
Member

Are you compiling 32bit and .net fill runtime?

Can you try and fint out on which method the CreateSocketPublisher is
blocked?

On Mon, Nov 24, 2014 at 9:25 AM, billyhct notifications@github.com wrote:

Thanks for the files.

I have tried to use the dll, it got freezed when under pub sub mode.
I then import the source code and debug, it stopped and crash the Unity3d
at:

            NetMQContext ctx = NetMQContext.Create();
            PublisherSocket socket = ctx.CreatePublisherSocket(); // Freeze here

            //...
            socket.Send(byteArray);


Reply to this email directly or view it on GitHub
#98 (comment).

@billyhct
Copy link

Hi I compile with 64 bit as Apple requires 64 bits next month.
Not sure if it can support 64bit?

I will check which method is blocked

Thanks
Billy

@neozeed
Copy link

neozeed commented Jan 3, 2015

I started to play around with Kerbal Space program, a which is powered by Unity3d, and I wanted to take a plugin, namely KSPIo, and convert it to using some kind of messaging. Naturally mono doesn't support Win32 named pipes, so I thought I'd try netmq. I downloaded the zip file from here, and loaded it into Visual Studio 2013, and built the .net 3.5 version. It 'builds' in under a second so I wonder if it's really compiling anything.... Anyways as a simple test, I setup two small projects in VS 2013, a client/server to verify that they work with .net 3.5 ...

Server:

using System;
using System.Threading;
using NetMQ;

namespace HelloWorldDemo
{
class Program
{
private static void Main(string[] args)
{
NetMQ.NetMQContext xx = NetMQContext.Create();
NetMQ.Sockets.ResponseSocket xy = xx.CreateResponseSocket();
xy.Bind("tcp://127.0.0.1:5557");
while (true)
{
Console.WriteLine(xy.ReceiveString());
xy.Send("Packet ");
}
}
}
}

Client:

using System;
using NetMQ;

namespace HelloWorldDemo
{
class Program
{
private static void Main(string[] args)
{
NetMQ.NetMQContext xx = NetMQContext.Create();
NetMQ.Sockets.RequestSocket xz = xx.CreateRequestSocket();
xz.Connect("tcp://127.0.0.1:5557");
xz.Send("Data");
Console.WriteLine(xz.ReceiveString());
xz.Disconnect("tcp://127.0.0.1:5557");
}
}
}

And these work as I'd expect.

So now the fun part, I paste the client portion into the existing plugin, on it's awake method, and I get this nice crash...

[EXC 12:41:29.332] FormatException: Invalid format for Guid.Guid(string). System.Guid+GuidParser.ParseChar (Char c) System.Guid+GuidParser.ParseGuid2 () System.Guid+GuidParser.Parse () System.Guid..ctor (System.String g) AsyncIO.Windows.UnsafeMethods..cctor () Rethrow as TypeInitializationException: An exception was thrown by the type initializer for AsyncIO.Windows.UnsafeMethods AsyncIO.CompletionPort.Create () NetMQ.zmq.Utils.Proactor..ctor (System.String name) NetMQ.zmq.IOThread..ctor (NetMQ.zmq.Ctx ctx, Int32 threadId) NetMQ.zmq.Ctx.CreateSocket (ZmqSocketType type) NetMQ.NetMQContext.CreateHandle (ZmqSocketType socketType) NetMQ.NetMQContext.CreateRequestSocket () KSPSerialIO.SettingsNStuff.Awake ()

Obviously I'm doing something wrong.

@somdoron
Copy link
Member

somdoron commented Jan 3, 2015

You are actually doing ok, NetMQ is using AsyncIO, which uses guid in a way
that mono doesn't support, I fixed that but need to release a version and
netmq to use that. Anyway you can download the source code from following
link, it should work:

#175

and compile netmq.unity

On Sat, Jan 3, 2015 at 6:50 AM, neozeed notifications@github.com wrote:

I started to play around with Kerbal Space program, a which is powered by
Unity3d, and I wanted to take a plugin, namely KSPIo
<//https://raw.githubusercontent.com/zitron-git/KSPSerialIO/master/KSPSerialIO/KSPIO.cs>,
and convert it to using some kind of messaging. Naturally mono doesn't
support Win32 named pipes, so I thought I'd try netmq. I downloaded the zip
file from here https://github.com/somdoron/netmq/tree/Unity, and loaded
it into Visual Studio 2013, and built the .net 3.5 version. It 'builds' in
under a second so I wonder if it's really compiling anything.... Anyways as
a simple test, I setup two small projects in VS 2013, a client/server to
verify that they work with .net 3.5 ...

Server:

using System;
using System.Threading;
using NetMQ;

namespace HelloWorldDemo
{
class Program
{
private static void Main(string[] args)
{
NetMQ.NetMQContext xx = NetMQContext.Create();
NetMQ.Sockets.ResponseSocket xy = xx.CreateResponseSocket();
xy.Bind("tcp://127.0.0.1:5557");
while (true)
{
Console.WriteLine(xy.ReceiveString());
xy.Send("Packet ");
}
}
}
}

Client:

using System;
using NetMQ;

namespace HelloWorldDemo
{
class Program
{
private static void Main(string[] args)
{
NetMQ.NetMQContext xx = NetMQContext.Create();
NetMQ.Sockets.RequestSocket xz = xx.CreateRequestSocket();
xz.Connect("tcp://127.0.0.1:5557");
xz.Send("Data");
Console.WriteLine(xz.ReceiveString());
xz.Disconnect("tcp://127.0.0.1:5557");
}
}
}

And these work as I'd expect.

So now the fun part, I paste the client portion into the existing plugin,
on it's awake method, and I get this nice crash...

[EXC 12:41:29.332] FormatException: Invalid format for Guid.Guid(string).
System.Guid+GuidParser.ParseChar (Char c)
System.Guid+GuidParser.ParseGuid2 ()
System.Guid+GuidParser.Parse ()
System.Guid..ctor (System.String g)
AsyncIO.Windows.UnsafeMethods..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the
type initializer for AsyncIO.Windows.UnsafeMethods
AsyncIO.CompletionPort.Create ()
NetMQ.zmq.Utils.Proactor..ctor (System.String name)
NetMQ.zmq.IOThread..ctor (NetMQ.zmq.Ctx ctx, Int32 threadId)
NetMQ.zmq.Ctx.CreateSocket (ZmqSocketType type)
NetMQ.NetMQContext.CreateHandle (ZmqSocketType socketType)
NetMQ.NetMQContext.CreateRequestSocket ()
KSPSerialIO.SettingsNStuff.Awake ()

Obviously I'm doing something wrong.


Reply to this email directly or view it on GitHub
#98 (comment).

@neozeed
Copy link

neozeed commented Jan 3, 2015

Wow that did it!

I'm now exporting my telemetry data from my rocket! This is totally awesome!

I don't know why, but i had to manually add the project NetMQ.Unity to the master project, but again it compiles in 1 second, and works!

Thank you so much for your help!!!!

@krisrok
Copy link
Contributor

krisrok commented Jan 21, 2015

for later visitors looking for a unity compatible version: by now it works with the .net3.5 project in the master branch, no need to resort to somdoron's previous pull request. (working for win, osx and ios export).

@somdoron
Copy link
Member

Try version 3.3.0.12-rc1, or to build from source.

On Wed, Apr 8, 2015 at 6:40 PM, Jonas Trottnow notifications@github.com
wrote:

@krisrok https://github.com/krisrok are you shure that the 3.3.0.11
release of netMQ is compatible with Unity? I tried to use it, and it
compiles and imports without issues. But there are no messages comming
through (using a simple PUSH/PULL pattern).
When I swap the AsyncIO.dll and NetMQ.dll to the ones compiled from the
Unity fork by @somdoron https://github.com/somdoron it workes flawless.


Reply to this email directly or view it on GitHub
#98 (comment).

@EmitKiwi
Copy link

When I use ZeroMQ at Android, the app crashes a lot. I use the version 3.3.0.12-rc1 and Unit 5.1.0F3. It does not show any exception.

@somdoron
Copy link
Member

Try to compile from master, also try to run following line at the beginning
of the Main functions:

ForceDotNet.Force();

On Tue, Jun 23, 2015 at 5:56 PM, Flime notifications@github.com wrote:

I cant get NetMQ to work when building for Android in Unity. It doesnt
have any errors, but the server does not receive anything. In the unity
editor it does work. But I need to restart the Unity every time when I hit
play for the second time. (Unity freezes) I used the 3.3.0.12-rc1 build.


Reply to this email directly or view it on GitHub
#98 (comment).

@somdoron
Copy link
Member

Also if it still doesn't work, try to compile NetMQ with AsyncIO.Unity from
here:

https://github.com/somdoron/AsyncIO/tree/master/Source/AsyncIO

On Fri, Jun 26, 2015 at 9:11 AM, Doron Somech somdoron@gmail.com wrote:

Try to compile from master, also try to run following line at the
beginning of the Main functions:

ForceDotNet.Force();

On Tue, Jun 23, 2015 at 5:56 PM, Flime notifications@github.com wrote:

I cant get NetMQ to work when building for Android in Unity. It doesnt
have any errors, but the server does not receive anything. In the unity
editor it does work. But I need to restart the Unity every time when I hit
play for the second time. (Unity freezes) I used the 3.3.0.12-rc1 build.


Reply to this email directly or view it on GitHub
#98 (comment).

@EmitKiwi
Copy link

It does work. (Tried it with building AsyncIO for unity and compiling NetMQ.) Only after a few minutes it stops working. I need to reopen my unity android app to let it start working again. Also adding ForceDotNet.Force(); does not have any effect at the unity editor. It will crash every time I start the playing for the second time. (Only in Unity Editor).

@pixerati
Copy link

pixerati commented Aug 9, 2015

Hey guys,

I've been happily working with this build of NetMQ for Unity both in OS X and Windows.

But I've been doing all my testing using the loop back 127.0.0.1. As soon as I moved the server (a Pyzmq server) to another machine I get no connection, at least nothing that sends and receives data.

I'm using tcp://*:5555 as the bind address on the server and tcp://theServerMachineIP:5555 on the client.

When I look at windows netstat on the server box it actually shows an active connection with the client binding to 5555 but connecting to some random port on the client (which I'm assuming is normal) but my code is unresponsive in terms of sending and receiving data.

No the machines firewalls are off and I've even explicitly set rules to allow port 5555 through, but no joy. Even tried connecting to a different router in case that was the issue.

Any ideas? So weird that it works fine on the same machine using the loopback. Incredibly frustrating after having spent weeks building up the code on a local box and everything testify fine:(

@drewnoakes
Copy link
Member

Can you telnet to port 5555 between the boxes? That's a good test to rule
out network issues.

On Sun, 9 Aug 2015 at 16:57 pixerati notifications@github.com wrote:

Hey guys,

I've been happily working with this build of NetMQ for Unity both in OS X
and Windows.

But I've been doing all my testing using the loop back 127.0.0.1. As soon
as I moved the server (a Pyzmq server) to another machine I get no
connection, at least nothing that sends and receives data.

I'm using tcp://*:5555 as the bind address on the server and
tcp://theServerMachineIP:5555 on the client.

When I look at windows netstat on the server box it actually shows an
active connection with the client binding to 5555 but connecting to some
random port on the client (which I'm assuming is normal) but my code is
unresponsive in terms of sending and receiving data.

No the machines firewalls are off and I've even explicitly set rules to
allow port 5555 through, but no joy. Even tried connecting to a different
router in case that was the issue.

Any ideas? So weird that it works fine on the same machine using the
loopback. Incredibly frustrating after having spent weeks building up the
code on a local box and everything testify fine:(


Reply to this email directly or view it on GitHub
#98 (comment).

@pixerati
Copy link

pixerati commented Aug 9, 2015

I did a raw telnet through to port 5555 without any issue. Could send commands from client box and receive back from server box.

@dragosbulugean
Copy link

Hey guys, if anyone is still troubled by this, you have to manually dispose of any sockets and contexts at unity's app quit like:

 void OnApplicationQuit()
        {
            socket.Dispose();
            context.Dispose();
        }

That stops unity from freezing on the second start of the game.

@Mystfit
Copy link

Mystfit commented Oct 12, 2015

@pixerati I'm running into the same problem. Running PyZmq server on localhost, 2 clients can connect to the host and directly to each other just fine via bindRandom ports. Moving the server or either client to another machine still lets the connection form but no messages make their way through.

I'm running the latest AsyncIO3.5 code, the latest NetMQ code, Unity 5.2.1 and Windows 10. Network issues have been ruled out by using lightweight PyZmq and NetMq servers/clients to simulate a similar environment.

Also, if one of the sockets times out whilst sending (rather than blocking forever) then disposing the sockets and context at the end will still hard freeze Unity. I suspect that the busted socket is still being held by a thread somewhere.

@LewisBridgeman
Copy link

Hi guys.
I've tried pretty much all of the advice above, but I still cannot get my code to run without freezing (the first time I run it, not just the second).
I tried NetMQUnity and NetMQ3.5, AsyncIO3.5 and AsyncIOUnity, and all combinations of the above. I compiled these as .Net 3.5 x86. Is this right?
Sorry if I'm being stupid, I'm getting a bit confused with all of the different versions.

@somdoron
Copy link
Member

I will give it a try today.

Which unity version are you using?

On Thu, Oct 22, 2015 at 12:15 PM, LewisBridgeman notifications@github.com
wrote:

Hi guys.
I've tried pretty much all of the advice above, but I still cannot get my
code to run without freezing (the first time I run it, not just the second).
I tried NetMQUnity and NetMQ3.5, AsyncIO3.5 and AsyncIOUnity, and all
combinations of the above. I compiled these as .Net 3.5 x86. Is this right?
Sorry if I'm being stupid, I'm getting a bit confused with all of the
different versions.


Reply to this email directly or view it on GitHub
#98 (comment).

@LewisBridgeman
Copy link

Thanks. I'm currently using 5.2.1. I'll upgrade to 5.2.2 quickly, just in case that changes anything.

@somdoron
Copy link
Member

Can you also upload somewhere a project that get freeze? I have little
experience with unity...

On Thu, Oct 22, 2015 at 12:26 PM, LewisBridgeman notifications@github.com
wrote:

Thanks. I'm currently using 5.2.1. I'll upgrade to 5.2.2 quickly, just in
case that changes anything.


Reply to this email directly or view it on GitHub
#98 (comment).

@Mystfit
Copy link

Mystfit commented Oct 22, 2015

Lewis, the most success I've had is with the latest branch of NetMQ using
the NetMQ.3.5 project, compiled with the latest version of ASyncIO using
the ASyncIO.Unity project, and everything compiled with .Net 3.5 (Any CPU)
and used with Unity 5.2.1f1.

This got me to the point where a very simple Unity project could
send/receive messages, but anything more complex fell apart quite quickly.

On Thu, Oct 22, 2015 at 10:16 PM LewisBridgeman notifications@github.com
wrote:

Hi guys.
I've tried pretty much all of the advice above, but I still cannot get my
code to run without freezing (the first time I run it, not just the second).
I tried NetMQUnity and NetMQ3.5, AsyncIO3.5 and AsyncIOUnity, and all
combinations of the above. I compiled these as .Net 3.5 x86. Is this right?
Sorry if I'm being stupid, I'm getting a bit confused with all of the
different versions.


Reply to this email directly or view it on GitHub
#98 (comment).

@LewisBridgeman
Copy link

Thanks both. Mystfit, I'll try doing that. Somdoron, I'll upload my Unity project after I've tried Mystfits advice.

@LewisBridgeman
Copy link

I tried your method, but it doesn't seem to work for me. It might be that I'm misunderstanding how to use NetMQ in Unity, so I've attached the script that freezes.
Am I right to be using a coroutine? Maybe a backgroundworker would be better?

void Start ()
 {
    AsyncIO.ForceDotNet.Force();
    StartCoroutine(ReqCoroutine());
}

IEnumerator ReqCoroutine()
{
    using (NetMQContext ctx = NetMQContext.Create())
    {
        using (var client = ctx.CreateRequestSocket())
        {
            client.Connect("tcp://127.0.0.1:5555");

            while (true)
            {
                var reqMsg = DateTime.Now.ToString();                    
                Debug.Log(reqMsg);

                client.TrySendFrame(reqMsg);
                yield return new WaitForSeconds(1);

                var replyMsg = client.ReceiveFrameString();
                Debug.Log(replyMsg + Environment.NewLine);
            }
        }
    }
}

My API compatibility level is set to ".Net 2.0" rather than ".Net 2.0 Subset"

@drewnoakes
Copy link
Member

@LewisBridgeman I don't know much about Unity, but the coroutine (C# generator function) has one problem in that the while (true) loop can never exit, meaning that the socket and context are never disposed.

@LewisBridgeman
Copy link

@drewnoakes Thanks, you were right!

@monsdar
Copy link

monsdar commented Mar 24, 2016

I've got the problem that @dragosbulugean and @Flime wrote about. The following code freezes Unity when I start the game in the editor for the second time:

using UnityEngine;
using NetMQ.Sockets;

public class PosResetter : MonoBehaviour
{
    SubscriberSocket subSocket = null;

    void Start ()
    {
        Debug.Log("Starting up NetMQ interface");        
        subSocket = new SubscriberSocket();
    }

    void OnApplicationQuit()
    {
        subSocket.Dispose();
    }
}

I'm using the following:

Do I have to build something in a specific way?

It seems as if the SubscriberSocket is not being released after OnApplicationQuit. On the second startup this let's Unity freeze. But that's just a blind guess...

@monsdar
Copy link

monsdar commented Mar 24, 2016

I've probably been able to fix the above mentioned issue myself with the following code:

using UnityEngine;
using NetMQ;
using NetMQ.Sockets;

public class PosResetter : MonoBehaviour
{
    NetMQContext context = null;
    SubscriberSocket subSocket = null;

    void Start ()
    {
        Debug.Log("Starting up NetMQ interface");
        context = NetMQContext.Create();
        subSocket = context.CreateSubscriberSocket();
    }

    void OnApplicationQuit()
    {
        Debug.Log("Shutting down...");
        subSocket.Close();
        context.Terminate();
        Debug.Log("Done...");
    }
}

Looks like it is somehow related to issue #424. Due to the missing context it is not possible to clean up completely. By explicitly terminating it works as expected and Unity does not freeze on second start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests