Search Unity

Good ol' Sockets (.NET sockets for mobile without Unity Pro) [Released]

Discussion in 'Assets and Asset Store' started by ZimM, Feb 12, 2014.

  1. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Yes, I've actually just noticed this today as well. I'm working on the fix right now, expect an update in the nearest hours.
     
  2. mzzl

    mzzl

    Joined:
    Nov 10, 2014
    Posts:
    2
    We just updated Unity to 4.6.1 beta to build our game in 64 bit iOS, since this is required as of 1st of February.
    When I try to build the project with Xcode, I get the errors as you can see in the attachment of this post.

    It looks like the errors come from Good Ol Sockets, but I don't understand what the errors mean.
    Can you help us get rid of these error message so we can build for iOS?

    Thanks in advance!
     

    Attached Files:

  3. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Thanks for reporting this, I haven't yet tested Good ol' Sockets build for 64bit iOS. It seems like IL2CPP can't handle obfuscated assemblies... I'll see what can be done with this in the nearest days.
     
  4. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    @mzzl
    So it seems like that current IL2CPP can't handle Good ol' Sockets as it relies on reflection a lot, and IL2CPP has no support for link.xml for now. I can't do anything with this, since this is an issue in IL2CPP, not in Good ol' Sockets. I've reported this, and hopefully this'll get fixed in the next Unity 4.6 IL2CPP betas.
    TL;DR: there is no solution to this at the moment, but I'll keep track on the situation.
     
  5. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Version 1.4.3 update is now live at the Asset Store!
    Changelog:
    • Multithreading stability fixes (should fix rare "Attempt to release a non-locked array" exception).
    • Fixed build for Windows Store Apps failing when Good ol' Sockets was in the project.
    • Minor performance optimizations.
     
  6. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    Thanks for the quick turnaround on this one. Rolling a new build out now and will advise if we see any more anomalies in the logs.
     
  7. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    Things seem to be much more stable now, but we are (again very occasionally) seeing:

    Argument cannot be null.
    Parameter name: buffer is null

    Code (csharp):
    1.  
    2.   at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
    3.   at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
    4.   at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    5.  
     
  8. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    This looks like a more involved problem. Could you please provide some more information on when that happens and what code is running when that happens? The stack trace seems incomplete too.
     
  9. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    I've had the latest build rolled out to all my users for about 24 hours now and only saw that one error one time in that entire period. Unfortunately, that's the full trace and detail that hit my logs. I'll keep digging and see if I can find any more info.
     
  10. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    We're now getting this error with the latest release of BestHTTP and Good Ol' Sockets ONLY (but consistently) on iOS:

    Code (csharp):
    1.  
    2. An exception was thrown by the type initializer for LostPolygon.System.Net.IPAddress
    3.  
    4.   at BestHTTP.HTTPConnection.Connect () [0x0003c] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs:404
    5.  
    6.   at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x000b3] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs:192
    7.  
    8. UnityEngine.Debug:Internal_Log(Int32, String, Object)
    9.  
    10. UnityEngine.Debug:LogError(Object)
    11.  
    Any ideas? (I also posted this on the BestHTTP Forum if this is coming form their stuff)
     
  11. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    So this never happened with Good ol' Sockets 1.4.3 + previous version of BestHTTP, right? It seems to be an issue in Good ol' Sockets, and I'll check that. Still, I'm puzzled why it never happened before (or with previous BestHTTP versions)...
     
  12. Monsu

    Monsu

    Joined:
    Dec 20, 2014
    Posts:
    13
    Anyone using this for GameSparks? I sort of got it to work. It works perfectly on Android, but on iOS it is giving me some issues. I am just running the test scene yet.

    This is the output in the console in the test scene of GameSparks:
    ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) System.Threading.Interlocked:CompareExchange (A.D/A`1<object[]>&,A.D/A`1<object[]>,A.D/A`1<object[]>)' while running with --aot-only.​

    This is the stack track from Xcode:

    at A.D.CompareAndSwap[Object[]] (A.A`1& location, A.A`1 comparand, A.A`1 newValue) [0x00000] in <filename unknown>:0
    at A.D+B`1[System.Object[]].A (System.Object[] ) [0x00000] in <filename unknown>:0
    at A.D..cctor () [0x00000] in <filename unknown>:0
    Rethrow as TypeInitializationException: An exception was thrown by the type initializer for A.D
    at LostPolygon.System.Net.IPAddress..ctor (Int64 addr) [0x00000] in <filename unknown>:0
    at LostPolygon.System.Net.IPAddress..cctor () [0x00000] in <filename unknown>:0
    Rethrow as TypeInitializationException: An exception was thrown by the type initializer for LostPolygon.System.Net.IPAddress
    at WebSocket4Net.WebSocket.ResolveUri (System.String uri, Int32 defaultPort, System.Int32& port) [0x00000] in <filename unknown>:0
    at WebSocket4Net.WebSocket.CreateSecureClient (System.String uri) [0x00000] in <filename unknown>:0
    Anyone know what to do about it?

     
  13. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    This actually looks like the same issue @slumtrimpet posted before. I'm investigating it right now.
    Strange thing is that I'm not seeing this error myself... What device and Unity version do you use?
     
  14. frankadimcosta

    frankadimcosta

    Joined:
    Jan 14, 2015
    Posts:
    203
    I' trying to build your demos for Windows 8,1 / windowsphone 8.1 platforms.
    Compiling from Mono is ok. But building from editor i got this errors:

    Assets\GoodOldSockets\Demos\Scripts\HttpGet.cs(139,17): error CS0246: cannot find name space 'Thread';

    Assets\GoodOldSockets\Demos\Scripts\QuoteOfTheDay.cs(116,21): error CS0246: cannot find name space 'Thread';

    Can you help me ? TNX !
     
    Last edited: Jan 24, 2015
  15. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Windows Store and Windows Phone use different runtimes that are not fully compatible with regular .NET. Demos are not meant to be buildable for these platforms, as asset only supports Android & iOS.
     
    frankadimcosta likes this.
  16. frankadimcosta

    frankadimcosta

    Joined:
    Jan 14, 2015
    Posts:
    203
    TNX for reply.

    But ... is windowsphone 8.1 and Windows 8.1 support planned ?
     
    Last edited: Jan 24, 2015
  17. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Um, sorry? You can already use sockets for free on these platforms.
     
  18. mzzl

    mzzl

    Joined:
    Nov 10, 2014
    Posts:
    2
    Thanks! We will wait patiently for a solution then :)
     
  19. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    @slumtrimpet
    @Monsu
    After battling with recent issues for three days I've decided to revert some optimizations introduced in 1.4.0 that led to all these recent issues. It came at small performance cost, but I believe stability is much more important than some ephemeral performance gain... Update to 1.4.4 is already live on the Asset Store.
     
  20. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    Totally agree with the stability focus, and the latest build does seem to have resolved our issue. Thanks!
     
  21. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    Hello,
    I have this Exception:"Operation is not supported" when I use Socket.SendToAsync on Android 4.4
    That work fine on PC and WP8

    Socket _socket
    _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    _socket.SendToAsync(socketEventArg);
     
  22. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hi,
    I've just checked with a simple test script and it worked fine for me.
    Code (CSharp):
    1. using System.Text;
    2. using UnityEngine;
    3. using LostPolygon.System.Net;
    4. using LostPolygon.System.Net.Sockets;
    5.  
    6. public class NewBehaviourScript : MonoBehaviour {
    7.     private Socket _socket;
    8.  
    9.     private void Start() {
    10.         _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    11.         SocketAsyncEventArgs socketAsyncEventArgs = new SocketAsyncEventArgs();
    12.         socketAsyncEventArgs.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.10"), 5656);
    13.         byte[] bytes = Encoding.UTF8.GetBytes("some test string");
    14.         socketAsyncEventArgs.SetBuffer(bytes, 0, bytes.Length);
    15.         socketAsyncEventArgs.Completed += SocketAsyncEventArgsOnCompleted;
    16.         _socket.SendToAsync(socketAsyncEventArgs);
    17.     }
    18.  
    19.     private void SocketAsyncEventArgsOnCompleted(object sender, SocketAsyncEventArgs socketAsyncEventArgs) {
    20.         Debug.Log("completed ok");
    21.     }
    22. }
    so, assuming you've done the initial setup correctly (and I'd suggest re-checking that in the first place), you're probably doing something wrong in your code. It's hard to say what exactly, as I don't know how do you fill socketEventArg. Please re-check your code.
     
  23. greggtwep16

    greggtwep16

    Joined:
    Aug 17, 2012
    Posts:
    1,546
    In my project I'm going to be using sockets to broadcast on the LAN before setting up a more conventional Network.Connect from the unity API (basically finds who on the network is the server automatically no prior IP known). Two questions before I go ahead and purchase GoS.

    1. The documentation says not the entire System.Net.Sockets namespace is implemented. Do you know if the IPV6 multicast support is in GoS? For IPV4 I will just broadcast UDP on the LAN but in the IPV6 world I'll have to use multicast groups and wanted to know if this is supported in GoS.

    2. Any update on IL2CPP? I realize that this is more in Unity's court than yours but I have certainly seen them responding to bug reports fast in the beta forums. Not sure what specific reflection issues you were seeing with IL2CPP but have you filed bugreports and has unity fixed them yet? Obviously Feb 1st has passed so for any new project if it doesn't currently work there is no way to use GoS on IOS.
     
  24. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    What System.Net.Sockets classes are required for using multicast groups? I'm not really sure since I've never did IPV6 broadcasting. Probably it is already implemented, but even if not - I think I can add the support.
    As it turned out, those weren't reflection issues, it was actually IL2CPP behaving strangely with obfuscated assemblies. I've tuned the obfuscator settings and that issue was gone... but only for me to find out that sockets are not working at all in the current version of IL2CPP. Unity is working on this, the latest responses on this matter are:
    So it's still being worked on, and all I can do is to watch and wait for the initial sockets support in IL2CPP. To be clear, it's not just Good ol' Sockets that is blocked by this - all code that uses .NET sockets is broken, even if you have the Pro license.
     
    Last edited: Feb 16, 2015
  25. greggtwep16

    greggtwep16

    Joined:
    Aug 17, 2012
    Posts:
    1,546
    Wow didn't realize that even Unity built in sockets support would be an issue under IL2CPP. I'm sure it's a top priority for unity then. GDC is pretty close and I'm sure that's when they want to debut Unity 5 but judging from all the activity on that thread looks like they are burning the midnight oil at Unity right now.

    As far as mulitcast specific classes vs just a typical IPV4 broadcast on 255.255.255.255 I scanned some sample code and this is the two things that stand out as different to me.

    System.Net.Sockets.IPv6MulticastOption class
    System.Net.Sockets.UdpClient class invokes method JoinMulticastGroup where a IPv4 broadcast does not
     
  26. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Yes, Unity seems to be working very hard on sockets now, but it's impossible to say when sockets will be ready. I won't actually be surprised if Unity 5 will ship without them...
    That said, both things you've mentioned are already in Good ol' Sockets, so IPv6 broadcast should work without problems.
     
  27. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
  28. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    Good news, my game is ready, and works on Android, WindowsPhone, but not on iOS since IL2CPP.
     
  29. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    I tried with Unity 4.6.3 and I still continu to have a Exception when I try to create a Socket.
    _socket = newSocket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
     
  30. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    The current version available on Asset Store is not even supposed to work with IL2CPP. I have an internal version that I use for testing against IL2CPP runtime, but the results are not very encouraging at the moment... While sockets somewhat work sometime, I'm still getting stalls and crashes even in simple tests. I'm still investigating what I can do, but take into consideration that IL2CPP is still very much beta quality software, and I won't actually expect sockets to work reliably for quite some time.
     
  31. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Update to version 2.0.0 with initial IL2CPP support is now live on Asset Store!
    Changelog:
    • Initial IL2CPP support.
    • Major internal improvements, edge cases are handled better now.
    • Improved patcher UI, performance and compatibility.
    • Added validation of player settings to make sure they are always setup correctly.
    • Fixed an issue that made some methods always throw a NullReferenceException.
    • Added some more specific patching routines.
    • Dropped support for Unity 4.2 and older.
    Please note: "IL2CPP support" doesn't means that all networking code will just work now. Good ol' Sockets is still limited by the underlying socket implementation, and at the moment, sockets in IL2CPP are extremely unreliable.
    So in case you're seeing network stalls or crashes, please check if your project works with Mono runtime first. If it works fine with Mono runtime, then it's likely the issue is in IL2CPP, and it's probably better to send bugreports to Unity Technologies, as I personally can't do anything with it anyway.
     
  32. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    I always have the a exception when I use IL2CPP with your last release.
    My game works great on iOS with Mono runtime, it's only with IL2CPP.

    Did you try to create a simple Socket with newSocket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) on a iOS device with IL2CPP ?

    Exception message :A null value was found where an object instance was required.

    Exception StackTrace: at AnimerArme.Update () [0x00000] in <filename unknown>:0

    at LostPolygon.System.Net.Sockets.Socket.SendTo (System.Byte[] buffer, LostPolygon.System.Net.EndPoint remote_end) [0x00000] in <filename unknown>:0

    at SocketClientUDP.SendUDP (System.String data) [0x00000] in <filename unknown>:0

    at PlayerNetwork.traiterSocketUDP () [0x00000] in <filename unknown>:0

    at System.Threading.ThreadStart.Invoke () [0x00000] in <filename unknown>:0

    at Replacements.MSCompatUnicodeTable.get_IsReady () [0x00000] in <filename unknown>:0
     
  33. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Socket.SendTo
    As far as I can see, you can create the socket just fine, it is Socket.SendTo that fails... Could you please provide a minimal example that fails for you?
    I've just tested with these two lines of code:
    Code (CSharp):
    1. Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    2. sock.SendTo(new byte[] {55, 55, 55}, 3, SocketFlags.None,  new IPEndPoint(IPAddress.Parse("192.168.0.104"), 5555));
    And there were no exceptions thrown.
     
  34. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hi everyone.

    With Unity 5 Personal license now allowing .NET sockets access on all platforms for free, Good ol' Sockets won't have any purpose for new projects utilising Unity 5. And since most people who used free version of Unity 4 will probably switch to Unity 5 Personal soon enough, Good ol' Sockets is now declared obsolete.

    I have no plans to remove it from the Asset Store for at least half a year, as there'll still be a lot of people with existing projects that use Good ol' Sockets. However, I do not plan on making any future improvements, and only release patches fixing critical bugs, if any will be discovered.

    It has been fun developing and supporting Good ol' Sockets, and I'm happy to know it helped a lot of you implement your ideas. Good ol' Sockets were good ;)

    - Serhii
     
    slumtrimpet and hopeful like this.
  35. greggtwep16

    greggtwep16

    Joined:
    Aug 17, 2012
    Posts:
    1,546
    Yeah I thought about that today when reading the announcements. A lot of the assets that used to bring pro only features to unity free are now obsolete (obviously you aren't the only one). Even though I recently purchased your asset I must say I don't regret doing it it worked quite well. Thanks for all your hard work! I hope you have more ideas for quality assets!
     
  36. JOKINN

    JOKINN

    Joined:
    Jul 4, 2013
    Posts:
    5
    Hi , i've just bought the asset , i'm trying hard to get this working with Gamesparks , but as i build the project on android i don't get any result , my device does'nt log to FB and all i can see in logcat is this

    I/Unity (16622): MethodAccessException: Method `LostPolygon.System.Net.EndPoint:.ctor ()' is inaccessible from method `System.Net.DnsEndPoint:.ctor (string,int)'

    I/Unity (16622):

    I/Unity (16622): at WebSocket4Net.WebSocket.ResolveUri (System.String uri, Int32 defaultPort, System.Int32& port) [0x00000] in <filename unknown>:0

    I/Unity (16622): at WebSocket4Net.WebSocket.CreateSecureClient (System.String uri) [0x00000] in <filename unknown>:0

    I/Unity (16622): at WebSocket4Net.WebSocket.Initialize (System.String uri, System.String subProtocol, System.Collections.Generic.List`1 cookies, System.Collections.Generic.List`1 customHeaderItems, System.String userAgent, System.String origin, WebSocketVersion version) [0x00000] in <filename unknown>:0

    I/Unity (16622): at WebSocket4Net.WebSocket..ctor (System.String uri, System.String subProtocol, System.Collections.Generic.List`1 cookies, System.Collections.Generic.List`1 customHeaderItems, System.String userAgent, System.String origin, WebSocketVersion version) [0x00000] in <filename unknown>:0

    I/Unity (16622): at WebSocket4Net.WebSocket..ctor (System.String uri, System.S

    I/Unity (16622): GS: Connecting to:wss://preview.gamesparks.net/ws/294765rExfKL?deviceOS=ANDROID&deviceID=ed5ecccfd108dec14761d94b52177044&SDK=

    I/Unity (16622):

    I/Unity (16622): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)

    I/Unity (16622):
     
  37. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    @JOKINN
    GameSparks have removed support for Good ol' Sockets in the latest versions of their SDK. So make sure you are using GameSparks SDK version released before Unity 5 release. It may be a bit hard to find, but still possible.
    My recommendation, though, is to update your project to Unity 5, if possible, since .NET sockets are available with both Personal and Pro versions of Unity 5. Good ol' Sockets was declared obsolete since Unity 5 release.
     
  38. JOKINN

    JOKINN

    Joined:
    Jul 4, 2013
    Posts:
    5
    Thanks for your answer , i will update to unity 5.0 , but i need for you to give me a refund , if it's possible.
     
  39. reese01

    reese01

    Joined:
    Oct 21, 2014
    Posts:
    21
    Might I kindly ask you for an evaluation version to test if it works with GPGS?
     
  40. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    If you're using Unity 5.0+ then I don't think you need this anymore, since all the Unity Pro features are included in Unity Personal edition.
     
  41. reese01

    reese01

    Joined:
    Oct 21, 2014
    Posts:
    21
    Binaries built with Unity 5.0+ do not work on my device.