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. MANISH KUMAR

    MANISH KUMAR

    Joined:
    Nov 22, 2010
    Posts:
    57
    Is this Connect With ROR and Latest Socket IO version 1.1.0
     
  2. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hi there,
    what is ROR? I haven't tested personally SocketIO with Good ol' Sockets, but some people did and it worked for them.
     
    Last edited: Sep 18, 2014
  3. MANISH KUMAR

    MANISH KUMAR

    Joined:
    Nov 22, 2010
    Posts:
    57
    Ruby On Rails server (ROR).
    I want to make a chatting in my game by using of ROR.
    if possible then pls reply full details about this .
    Thank you
     
  4. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    I'm not sure that you fully understand the purpose of this plugin, as what you are asking sounds like "Is it possible to drive to the shop on this car?". This plugin just allows to use .NET sockets on free version of Unity, nothing more, nothing less. So obviously, you are able to communicate with any socket connections, including a ROR server.
     
    Last edited: Sep 18, 2014
  5. nitroSS

    nitroSS

    Joined:
    Aug 28, 2014
    Posts:
    19
    Hey

    i want to ask if this would solve it for Photon Chat (Android and iOS) without using Pro license ?
     
  6. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    It works for Photon Realtime, so I'm pretty sure it'll work for Photon Chat as well, as they seem to be using the same codebases.
     
  7. nitroSS

    nitroSS

    Joined:
    Aug 28, 2014
    Posts:
    19
    thanks, i have just purchased the plugin and applied patch system but now getting this error:

    Assets/Photon Unity Networking/Plugins/PhotonNetwork/SocketUdp.cs(126,31): error CS0029: Cannot implicitly convert type `System.Net.IPAddress' to `LostPolygon.System.Net.IPAddress'

    /* take me to this */

    126 - IPAddressep = IPhotonSocket.GetIpAddress(this.ServerAddress);
    127- this.sock.Connect(ep, this.ServerPort);
    128- this.State = PhotonSocketState.Connected;
     
  8. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    It seems like you've only applied the patch to a part of the project. What I did is:
    1) Created a new empty project.
    2) Imported Photon Networking
    3) Copied "demo-photon-chat\Assets\Plugins\PhotonChatApi' directory into the project
    4) Imported Good ol' Sockets and applied the patch
    5) Opened "Assets/Photon Unity Networking/Editor/PhotonNetwork/AccountService.cs" and added this to the using section
    Code (CSharp):
    1. using ServicePointManager = System.Net.ServicePointManager;
    It worked fine for me after these steps.
     
  9. nitroSS

    nitroSS

    Joined:
    Aug 28, 2014
    Posts:
    19
    ok thanks but why everything on scene got deleted?
     
  10. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Sorry, what do you mean? The demo scenes worked fine for me after the patch.
     
  11. nitroSS

    nitroSS

    Joined:
    Aug 28, 2014
    Posts:
    19
    i have a scene with a lot of object, i went to asset store, purchased the plugin, downloaded it, and did run the patch, now i got that error and all the objects in the hierarchy disappeared, the hierarchy is empty T_T

    how could i revert back

    did not backup that scene
     
  12. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Try reverting the patch, restarting Unity and reopening the scene. Good ol' Sockets has absolutely nothing to do with this, it never even touches the scenes.
     
  13. MANISH KUMAR

    MANISH KUMAR

    Joined:
    Nov 22, 2010
    Posts:
    57
    I understand your answer , and clear concept of SocketIO and WebSockets .
    but which library i use for any targeting server machine ,
    Other side is SocketIO v1.1.0.
    So i need make a connection for Socket mean connect in a room and chat with persons .

    but i can't find the right plugin for this ..
    I found many plugins and testing but not success ....
     
  14. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
  15. MANISH KUMAR

    MANISH KUMAR

    Joined:
    Nov 22, 2010
    Posts:
    57
    yes I use WebSocketSHarp and UnitySocketIO.
    but it's connect IOSOcket version 0.6 ,
    it's issue on IOSocket 1.0.
     
  16. thready

    thready

    Joined:
    Sep 23, 2014
    Posts:
    7
    Hmm.. I have a bug I think.. I started a brand spanking new project, imported good-ol-sockets and BestHTTP. I create a script on a new empty gameobject to do a simple request that works in Windows with BestHTTP like so:

    Code (CSharp):
    1. public class NewBehaviourScript : MonoBehaviour {
    2.  
    3.     // Use this for initialization
    4.     void Start () {
    5.  
    6.         HTTPRequest request = new HTTPRequest(new Uri("http://10.10.50.1:8000?info=WORKS"), OnRequestFinished);
    7.         request.Send();
    8.     }
    9.  
    10.     void OnRequestFinished(HTTPRequest request, HTTPResponse response)
    11.     {
    12.         // do nothing for now.
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update () {
    17.  
    18.     }
    19. }
    This does NOT work when deployed to Android. I'm using the 4.6 0b17 version (beta) of Unity. Is this the reason it's not working?

    Thanks!
    Mike
     
  17. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    I've just tested this code and it worked fine on Android:
    Code (CSharp):
    1. public class NewBehaviourScript : MonoBehaviour {
    2.     private void Start() {
    3.         HTTPRequest request = new HTTPRequest(new Uri("http://unity3d.com"), OnRequestFinished);
    4.         request.Send();
    5.     }
    6.  
    7.     private void OnRequestFinished(HTTPRequest request, HTTPResponse response) {
    8.         Debug.Log(response.DataAsText); // the page contents are printed successfully here
    9.     }
    10. }
    As you can see, basically just the URL has changed. This leads me to conclusion that there is nothing wrong with the plugin here, but 10.10.50.1 is not accessible from your phone. Probably 10.10.50.1 is only available from your local machine or from other network? It doesn't looks like a regular IP address for sure.
     
  18. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    @thready
    Oh, and one important thing many people forget to do, despite it being in the very beginning of manual. Have you set "Internet Access" to "Require" and "Api Compatibility Level" to ".NET 2.0" in the Build Settings?
     
    Last edited: Sep 25, 2014
  19. thready

    thready

    Joined:
    Sep 23, 2014
    Posts:
    7
    I do have internet access set to require and .NET 2.0 set in the build settings. And when I type the URL for 10.10.50.1 into chrome's address bar on the same device, it works, so it's not that. I tried your example as well and I don't get anything in the console. The only other differences are:

    1- Maybe this doesn't work on current beta version of Unity?
    2- When using your example, I'm assuming that the Debug.Log will go to the console while my phone is connected after a "build & run". Is this the case?
    3- I'm new to Unity and there's something super-basic I'm missing here...

    Thanks for your help,
    Mike
     
  20. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    @thready
    1. No, this definitely has nothing to deal with the beta status of Unity.
    2. Well, no. Debug.Log goes into logcat - the Android logging system. For more information about it:
    http://developer.android.com/tools/help/logcat.html
    http://forum.xda-developers.com/showthread.php?t=1726238
    This leads me to another question - you are saying that your code does not works, but how do you know that? Your code just makes a request and dies silently without ever outputting anything, so in any case you won't be getting any visual feedback. Maybe BestHTTP outputs errors to logcat too, but I'm not sure about that.
     
    Last edited: Sep 26, 2014
  21. thready

    thready

    Joined:
    Sep 23, 2014
    Posts:
    7
    my code hits an http server i wrote at that address. it does work in windows, but not when i deploy to android...
     
  22. thready

    thready

    Joined:
    Sep 23, 2014
    Posts:
    7
    ... and the problem was in my httpServer. Thanks for the logcat info. I will now give you 5 stars!

    Cheers,
    Mike
     
  23. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    @thready
    Glad you've figured it out :) And thanks!
     
  24. batm4n

    batm4n

    Joined:
    Oct 10, 2014
    Posts:
    1
    Hi ZimM, I also purchased the plugin to use it with socket.io 1.0+, but with no luck. (UnitySocketIO & sharp are not maintained and supported with the latest version) Is there a working example of server connection with WebSocket event listening on unity side? Is it even possible?

    Cheers,
    b
     
  25. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hi there, could you please elaborate what exactly wasn't working? I know some people were able to use UnitySocketIO successfully... And it is certainly possible, but maybe I am missing something, as I don't really know much about SocketIO and WebSockets, to be honest. But I know for sure that Good ol' Sockets works well with these two assets:
    UniWeb
    Best HTTP
    and both of them have WebSockets support, so maybe that'll work for you.

    Basically, this is not a question about Good ol' Sockets, but rather about general ways to use WebSockets from Unity. Good ol' Sockets won't help if you aren't able to make it work on PC at least.
     
  26. BonyYousuf

    BonyYousuf

    Joined:
    Aug 22, 2013
    Posts:
    110
    Hi,
    I am so excited to see this asset. This is really a life save or at least $4500 saver. :)

    I am currently working a game with SmartFoxServer2X. Any idea if your plugin will support SmartFox server? They just gave me a .dll file to add to the unity project. If you are not sure is there a way I get to test this plugin first to see if it works with smartfox and then buy it?

    Or alternatively I could just send you the .dll file and you can tell me if your plugin will work with it or not.

    Please let me know.
    Again thank you for such an awesome plugin.
    Hi,
    I am so excited to see this asset. This is really a life save or at least $4500 saver. :)

    I am currently working a game with SmartFoxServer2X. Any idea if your plugin will support SmartFox server? They just gave me a .dll file to add to the unity project. If you are not sure is there a way I get to test this plugin first to see if it works with smartfox and then buy it?

    Or alternatively I could just send you the .dll file and you can tell me if your plugin will work with it or not.

    Please let me know.
    Again thank you for such an awesome plugin.
     
  27. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    I've checked SmartFox with Good ol' Sockets last month and it worked well :)
     
  28. BonyYousuf

    BonyYousuf

    Joined:
    Aug 22, 2013
    Posts:
    110
    oh goodness, this is awesome news!! I can't thank you enough.
     
  29. clever

    clever

    Joined:
    Oct 11, 2012
    Posts:
    39
    hey ZimM, great asset, especially for budget developers (me included). Quick question, do you know if it works with uLink networking? Thanks.
     
  30. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hi there,
    no, uLink isn't officialy supported at the moment. However, some users have reported that uLink+GOS is working on Android, but not on iOS.
     
  31. H3llp1x

    H3llp1x

    Joined:
    Sep 29, 2014
    Posts:
    1
    Hello. I just bought plug-in There is a WP8 folder, is it for windows phone?)
     
  32. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    .NET sockets are already available on Window Phone with free version of Unity. dll's in WP8 are nothing but stubs that intentionally produce compilation errors when someone tries to use them on Windows Phone, just to remind that fact.
     
  33. JohnTube

    JohnTube

    Joined:
    Sep 29, 2014
    Posts:
    66
    @ZimM I just need confirmation that this should work with Photon TurnBased SDK before buying, thank you.
     
  34. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Just tested it again and it seems to work fine!
     
  35. TopSpoT

    TopSpoT

    Joined:
    May 1, 2014
    Posts:
    2
    Hi Zimm...I developed a game using Photon "Turnbased" API.. I am struck with an error while generating apk file "'System.Net.Sockets' are supported only with Unity Android Pro. Referenced from assembly 'PlayerIOUnity3DClient'."... So, if i use good ol sockets could i be able to generate an apk file? does it work? if not does it work with Yahoo player.io? please suggest me to get out of this problem, thanks in advance...
     
  36. JohnTube

    JohnTube

    Joined:
    Sep 29, 2014
    Posts:
    66
    Yes "Good Ol' Sockets" works well with Photon Turnbased SDK on Unity Free for Android/iOS. I'm using it myself.
     
    Last edited: Dec 17, 2014
  37. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    @TopSpoT
    Yes, just as @JohnTube said, it works fine with Photon Turnbased SDK. Not so sure about Player.IO, though - to be honest, I haven't tested it yet with Good ol' Sockets, as it seems like pretty much no one is using it with Unity. Why are you using both Photon TurnBased and Player.IO in the same project?
     
  38. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Hi ZimM
    I've imported your asset to the existing project, set player settings as required, but for some reason menu items "Patch for .Net socket support" and another one are grayed out and disabled. Please advice
     
  39. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Are you trying the file context menu? They'll be enabled only if used on something that can be patched. But you don't need that unless you really know what you are doing. Instead, use the main menu items:
    Tools → Lost Polygon → Good ol’ Sockets → Patch System.Net.Sockets usages
    That will automatically detect files that need to be patched and then patch them.
     
  40. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Thanks that works, I was trying from different place Assets->Good ol' Sockets
     
  41. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Version 1.4.0 update is now live at the Asset Store!
    Changelog:
    • Improved Unity 5 compatibility.
    • Adding #define GOODOLDSOCKETS_IGNORE to the beginning of .cs file now prohibits patching that file. May be useful for libraries.
    • Added specific patches for some popular assets to remove need for most manual post-patch fixes.
    • Multiple performance and memory allocation optimizations.
    • Fixed an error when assembly patcher found an unknown type in System.Net namespace.
    • Assemblies from "Assets/Plugins/Metro/" directory won’t be patched anymore.
    • Resolved some UI issues.
    Happy New Year everyone!
     
    Last edited: Dec 31, 2014
  42. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    it seems the new version is missed LostPolygon.System.Net.WebClient.
    After importing asset I got the following error:
    Assets/TNet/Common/TNTools.cs(323,25): error CS0246: The type or namespace name `WebClient' could not be found. Are you missing a using directive or an assembly reference?
     
  43. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    This is intentional, WebClient was never actually implemented, it was a dirty hack just for TNet, so I got rid of it. Instead, the patching for that file is done differently now. Basically - just revert the patch for that file and patch again.
     
  44. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Thanks, that fixed the issue. Does it make sense to revert the whole project and then patch it?
     
  45. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    There is no need in that, unless maybe if you have assemblies that use sockets (like if you are using Photon Networking, for example). For TNet, only TNTools.cs file has a specific patch.
     
  46. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Patch update to 1.4.1 is now live! Changelog:
    • Multiple improvements in handling null reference parameters.
    • Multithreading stability fixes.
    • Added stub assemblies for Windows Store Apps platform.
    It fixes some multithreading issues discovered in 1.4.0, so it is recommended to update in case you are noticing some funky behaviour.
     
  47. piece-of-toast

    piece-of-toast

    Joined:
    Oct 24, 2013
    Posts:
    2
    Hey, probably a stupid question but will good ol' sockets work on wi-fi as well as phone data.
     
  48. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Sure it will, there is no difference.
     
  49. piece-of-toast

    piece-of-toast

    Joined:
    Oct 24, 2013
    Posts:
    2
    Thanks, just wanted to know if it was the phones I was testing on.
     
  50. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    We're using the most recent versions of Good Ol' Sockets with BestHTTP (Pro) and occasionally are seeing very low level errors in the stream read that appear to be originating from the Good Ol' Sockets stack. The same requests will work 999/1000 times but very rarely we're getting the error:

    "attempt to release a non-locked array"

    with trace:

    Code (CSharp):
    1.  
    2.   at A.b+a.A (Int32 ) [0x00000] in <filename unknown>:0
    3.   at A.b.A (Int32 , Int32 ) [0x00000] in <filename unknown>:0
    4.   at LostPolygon.System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
    5.   at System.IO.Stream.ReadByte () [0x00007] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/Stream.cs:168
    6.   at BestHTTP.HTTPResponse.ReadTo (System.IO.Stream stream, Byte blocker) [0x0001a] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPResponse.cs:381
    7.   at BestHTTP.HTTPResponse.ReadHeaders (System.IO.Stream stream) [0x00015] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPResponse.cs:247
    8.   at BestHTTP.HTTPResponse.Receive (Int32 forceReadRawContentLength, Boolean readPayloadData) [0x000dc] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPResponse.cs:196
    9.   at BestHTTP.HTTPConnection.Receive () [0x00038] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs:487
    10.   at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x00159] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs:227
    11.  
    Any idea?