Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

UniWeb

Discussion in 'Assets and Asset Store' started by simonwittber, May 23, 2013.

  1. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    AFAIK Unity Free does not support sockets on these problems, and therefore UniWeb will not work.
     
  2. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    I need more information to help you. Did you change the REST api key to suit your own application?
     
  3. itjunkii

    itjunkii

    Joined:
    Dec 1, 2011
    Posts:
    35
    Yes absolutely, all I did was fill in my Parse keys which I am very familiar with Parse so i am sure I have the right ones.

    I just filled in where you had strings asking for them, Parse.cs I think it is?
     
  4. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228

    This is a 401 status code, which means Parse.com is telling you that you submitted an invalid password. The helpful message is output by UniParse to tell you this. Have you created the user you are trying to authenticate?
     
  5. Jiraboas

    Jiraboas

    Joined:
    Nov 16, 2012
    Posts:
    13
    Okay, here is one of the classes:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Net;
    5. using System.Net.Sockets;
    6. using System.IO;
    7. using System.Reflection;
    8. using System;
    9. using System.Text;
    10. using System.Security.Cryptography.X509Certificates;
    11. using System.Net.Security;
    12.  
    13. // See the Vuforia Web Services Developer API Specification - https://developer.vuforia.com/resources/dev-guide/adding-target-cloud-database-api
    14. public static class PostNewTarget
    15. {
    16.    
    17.     //Server Keys
    18.     private String accessKey    = VWS_API.accessKey;
    19.     private String secretKey    = VWS_API.secretKey;
    20.     private static String url   = VWS_API.url;
    21.    
    22.     private static Texture2D imageFile;
    23.    
    24.     //post target to the server with given informations
    25.     public static void postNewTarget(String targetName,String imageLocation)
    26.     {
    27.         Byte[] data;
    28.         ASCIIEncoding enc                           = new ASCIIEncoding();
    29.        
    30.         //create web request with post send method
    31.         HTTP.Request postRequest = new HTTP.Request("POST",url + "/targets");
    32.        
    33.         //create JSON object to store target informations
    34.         JSONObject requestBody = new JSONObject(JSONObject.Type.OBJECT);
    35.        
    36.         //set data to JSON object
    37.         bool result = setRequestBody(ref requestBody,targetName,imageLocation);
    38.        
    39.         if(result == true)
    40.         {
    41.             //get byte data from json object
    42.             data = enc.GetBytes(requestBody.print());
    43.            
    44.             String uniqueTargetId = "";
    45.            
    46.             //get nessecary headers for request
    47.             // Must be done AFTER setting the request body
    48.             System.Collections.Hashtable headers = VWS_API.setHeaders(data,"/targets","POST");
    49.            
    50.             string date = string.Format("{0:r}", DateTime.Now.ToUniversalTime());
    51.            
    52.             //set custom authorization headers to post request
    53.             postRequest.headers.Add("Authorization",(String)headers["Authorization"]);
    54.             postRequest.headers.Add("Date",date);
    55.             postRequest.headers.Add("Content-Type","application/json");
    56.            
    57.             postRequest.bytes = data;
    58.            
    59.             //send request and wait for response
    60.             postRequest.Send();
    61.            
    62.             //wait for response, coroutines dont work(why?)
    63.             while(!postRequest.isDone); // yield return null;
    64.            
    65.             if(postRequest.exception != null)
    66.             {
    67.                 Debug.LogError(postRequest.exception);
    68.             }
    69.             else
    70.             {
    71.                 //get response
    72.                 HTTP.Response response = postRequest.response;
    73.                
    74.                 Debug.Log("Response from server: " + response.Text);
    75.             }
    76.            
    77.             return;
    78.         }
    79.         else
    80.         {
    81.             Debug.Log("ERROR: Cant send request!");
    82.             return;
    83.         }
    84.     }
    85.    
    86.     private static bool setRequestBody(ref JSONObject requestBody,String targetName,String imageLocation)
    87.     {
    88.                         //...
    89.  
    90.             return true;
    91.     }
    92.  
    93. }
    I ported the java example code from vuforia to C#. Infos could be found here: https://developer.vuforia.com/resou...ng-targets-cloud-database-using-developer-api

    This class is used by the main class "VWS_API" and looks like this:

    Code (csharp):
    1. public class VWS_API : MonoBehaviour {
    2.    
    3.     public static string accessKey  = [access_key of server account];
    4.     public static string secretKey      = [secret_key of server account];
    5.     public static string url                = "https://vws.vuforia.com";
    6.    
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.        
    11.         Debug.Log("Initialize VWS API");
    12.        
    13.         PostNewTarget.postNewTarget("stones","stones");
    14.        
    15.     }
    16.  
    17.     //set authorisation header to request
    18.     public static System.Collections.Hashtable setHeaders(Byte[] data,String requestPath,String method) {
    19.  
    20.                          //...
    21.  
    22.         }
    23.    
    24.  
    25. }
    26.  
    If you need more specific informations, tell me!

    Thanks for your help! :)

    -Jira

    P.S.: Changing the line "yield return null" to any other yield-commands dont solve the problem. tried break, WaitForFrame() ant WaitSeconds() .
     
    Last edited: Jun 19, 2013
  6. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    Your PostNewTarget class does not inherit from MonoBehaviour, therefore it will not be able to directly use coroutines.
     
  7. Jiraboas

    Jiraboas

    Joined:
    Nov 16, 2012
    Posts:
    13
    No, allready checked that. It have nothing to to with the fact, that the class dont inherit from MonoBehaivour. If i change the class to MonoBehaviour, unfourtunatlly i have the same problem :(

    -Jira
     
  8. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    I assume you're calling the routine with something like StartCoroutine(PostNewTarget.postNewTarget(...))? It might be worth your time reading up on how coroutines work and their relationship to monobehaviour classes etc.
     
  9. Jiraboas

    Jiraboas

    Joined:
    Nov 16, 2012
    Posts:
    13
    No i dont use StartCoroutine.

    But you are right, I definitly have to take the time, to work trough the coroutine-thing, but i dont understand, why it dont work, even if i make the whole class to a MonoBehaviour class and use it like any other Mono-Scripts?

    I added " : MonoBehaviour" to the class head, added a Start()-Function to the class and call the PostNewTarget-Method from the Start-Function. Then I added the Script to an GameObject, and started the application in the unity editor.

    Even if i messed up with my non-mono class, it has to work, if i use the "regular" way, or do i miss something? :?

    -Jira
     
  10. mdowman

    mdowman

    Joined:
    Jul 10, 2012
    Posts:
    1
    Hello,

    I am just getting started with UniWeb and am trying to figure out how the caching works. I can't see from the code how it is implemented.

    Please advise.

    Thank you
     
  11. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    In your Start method, you will need to use the StartCoroutine method to actually start the postNewTarget coroutine. I'm also not sure that you can have a static MonoBehaviour.
     
  12. itjunkii

    itjunkii

    Joined:
    Dec 1, 2011
    Posts:
    35
    Simon,

    I downloaded UniWeb (which I only paid for because of UniParse)

    I added my keys in the UniParse.cs script EXACTLY as they appear in Parse:

    string RESTAPIKey = "";
    string applicationId = "";

    I got your message about an invalid user which I think is hilarious because this is your code CREATING a user then LOGGING that user in so one would think if that is how you designed your demo it would just work?

    Code (csharp):
    1.  
    2.     //Register a new user
    3.         var user = ParseClass.users.New();
    4.         user.Set("username", "itjunkii");
    5.         user.Set("password", "123");
    6.         user.Create();
    7.         while(!user.isDone) yield return null;
    8.         //check for error
    9.         if(user.error != null) {
    10.             //A message is printed automatically. We can diagnose the issue by examing the HTTP code.
    11.             Debug.Log(user.code);
    12.         }
    13.        
    14.         //Authenticate an existing user
    15.         var auth_user = ParseClass.Authenticate("itjunkii","123");
    16.         while(!auth_user.isDone) yield return null;
    17.         //check for error
    18.         if(auth_user.error != null) {
    19.             Debug.Log("An error occured, likely a bad password!");
    20.         }
    21.  
    Have you ran your demo project straight from the store lately? Are you capable of solving this problem? If not please do let me know so I can move on with my life.
     
  13. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    Remember UniParse is free, so there has not been a large amount of time into making it super easy to use.

    However, I've been using UniParse V2 for some time now, but am running into trouble getting it onto the Asset Store. If you would like to see this version drop me a private email and I'll send you the package. It's much better than the version currently on the asset store.
     
  14. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,641
    Hi,

    I'd like to know if the https call ACTUALLY validates the certificate or skip it making the library vulnerable to Man-in-the-middle attacks
     
  15. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    To be honest, I don't know. I use the .NET SSL classes, and I'm not sure if they do any validation automatically, or whether this needs to be coded in manually.
     
  16. Jiraboas

    Jiraboas

    Joined:
    Nov 16, 2012
    Posts:
    13
    Yes, that does the trick, thanks! And it works with a non-mono static class ;) Dont have to use MonoBehaviour!

    But now i have an other problem: How to set the Content-Type header correctly? If i use request.headers.Add("Content-Type","application/json"); i got a 500 result code from the server.

    For requests without a request body(like a get request) everything works fine now, but if i need the Content-Type to set to "application/json" my request dont work anymore.

    Any ideas?

    Thank you again for your help!

    -Jira
     
  17. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    I have been working with UniWeb/UniParse for some time now in an app we have live in the store. It seems 1 out of ever 4-5 times I run the app, I get an exception regarding cookies from Parse.com. Once this happens, it seems any other calls to UniWeb fails with something similar until the app is restarted. Is there perhaps a way to just disable cookie handling or something, since I know this is not needed for Parse. Thanks!
     
  18. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    You can modify the code yourself to remove any cookie related features, however I will add this as a feature for the next version so you can easily switch off cookies.
     
  19. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    Oh duh, I've already added this myself. Use the .enableCookies variable on your Request instance! :)
     
  20. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Double DOH, I should have checked for that too. Hopefully this solves the issues, thanks!
     
  21. Jiraboas

    Jiraboas

    Joined:
    Nov 16, 2012
    Posts:
    13
    @simonwittber:

    Any solution on my problem? I need a solution, asap!

    EDIT: Fixed it. Dont need help anymore. Thanks!

    -Jira
     
    Last edited: Jun 26, 2013
  22. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    UniWeb 1.9.22 is about to hit the asset store. Contains some important bug fixes, including the unterminated stream exception!
     
  23. DarkOverLordQC

    DarkOverLordQC

    Joined:
    Dec 19, 2012
    Posts:
    6
  24. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    That's great, thanks.
     
  25. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Hi,

    To support strip on iOS, you can also add a link.xml file at the root of the project :

    Code (csharp):
    1.  
    2. <linker>
    3.     <assembly fullname="mscorlib">
    4.         <namespace fullname="System.Security.Cryptography" preserve="all" />
    5.     </assembly>
    6. </linker>
    7.  
     
  26. deekpyro

    deekpyro

    Joined:
    Oct 16, 2012
    Posts:
    71
    I seem to be getting a crash on occasion with this error:

    HTTP.HTTPException: Unterminated Stream
    at HTTP.Response.ReadLine (System.IO.Stream stream) [0x00000] in <filename unknown>:0
    at HTTP.Response.ReadFromStream (System.IO.Stream inputStream) [0x00000] in <filename unknown>:0
    at HTTP.Request.<Send>m__18 (System.Object t) [0x00000] in <filename unknown>:0

    Also I would love to see stripping supported.
     
  27. DarkOverLordQC

    DarkOverLordQC

    Joined:
    Dec 19, 2012
    Posts:
    6
    Disabling completely the stripping for System.Security.Cryptography using link.xml increases the build size of 305kb. I would not recommend this solution.
     
  28. John-Higuera

    John-Higuera

    Joined:
    Oct 14, 2012
    Posts:
    20
    Hi!, there would be any new examples?

    Some of us here would like to check something like client-server small example, perhaps something like a game control from another exe, or perhaps from a html website.

    Is this possible?
     
  29. tr3dent

    tr3dent

    Joined:
    Jul 2, 2013
    Posts:
    1
    Hi all

    I am currently developing with the webplayer and want to use UniWeb with parse.com but it seems they have no socket policy server :( , Does anyone know if there is any Baas service that supports a socket policy server?

    Thanks
     
  30. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    @DarkOverLordQC
    Yes but what do you propose if we need the System.Security.Cryptography ?
    For example, in Request.cs there is the method :
    Code (csharp):
    1. public static bool ValidateServerCertificate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    that uses X509Certificate and X509Chain that are in this package :/
     
  31. DarkOverLordQC

    DarkOverLordQC

    Joined:
    Dec 19, 2012
    Posts:
    6
    Unity relies on static code analysis in order to detect what is needed and what is not, however it seems to fails for some things (Like the .Create() methods of the providers or with reflection in general)*.

    Most of the time it works well so what we do is avoid the use of "link.xml" since we want to be under 50mb and that 300k is not negligible.

    I recommend to test thoroughly all the features without using link.xml and fix what can be fixed (Ex: changing a .Create() for a "new" in this very specific case). Also, it appears we can be more specific in link.xml at using "type" instead of namespace in order to specify specific classes that fails.

    *: "Stripping depends highly on static code analysis and sometimes this can't be done effectively, especially when dynamic features like reflection are used. In such cases, it is necessary to give some hints as to which classes shouldn't be touched." http://docs.unity3d.com/Documentation/Manual/iphone-playerSizeOptimization.html
     
    Last edited: Jul 2, 2013
  32. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Thanks for the answer,

    Yes, but ! in this particular case, we must implement the ValidateServerCertificate method and thus use X509Certificate :/

    But as you said, I'll try to add just the 2 classes and not the whole package System.Security.Cryptography, but I fear this won't work because of dependencies...

    EDIT : Yup... does not work :)
     
    Last edited: Jul 2, 2013
  33. DarkOverLordQC

    DarkOverLordQC

    Joined:
    Dec 19, 2012
    Posts:
    6
    The best would be to checkout the source code of mono that was used in your version of Unity and look for Reflection in the code that is called before it crashes.

    The problem could be in SslStream in example.

    Have you tried only with the namespace System.Security.Cryptography.X509Certificates in link.xml?
    Code (csharp):
    1. <linker>
    2.     <assembly fullname="mscorlib">
    3.         <namespace fullname="System.Security.Cryptography.X509Certificates" preserve="all" />
    4.     </assembly>
    5. </linker>
     
  34. Murdock

    Murdock

    Joined:
    May 21, 2013
    Posts:
    5
    I guess is not a policy server, since it doesn't respond to <policy-file-request/>. Also, today I ran the same test and I couldn't even connect to that port (connection refused). I give up on trying to use uniweb for my facebook client, still using it to connect to the game API which runs in my own servers.
     
  35. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    I'm using uniweb with facebook calls without issues.
    What platforms are you building on? (me Android iOS).
     
  36. AllonVR

    AllonVR

    Joined:
    Jul 16, 2012
    Posts:
    28
    Hi there,

    I have one question. Does your GoogleMaps plugin in combination with UniWeb work when I build to Unity or Flash Webplayer?
    When researching and testing I find that the sandbox security normally poses a problem - basically one needs to put a crossdomain.xml on the google server to prevent this.
    Do your plugins circumvent this issue?
     
  37. Murdock

    Murdock

    Joined:
    May 21, 2013
    Posts:
    5
    My game is multiplatform (web, ios, android), and the problem only occurs in the web version. As I understand it,due to the security sandbox implemented by the webplayer, the server to which you want to connect has to be running a policy server if you are connecting using sockets, which is the case with UniWeb. Facebook doesn't run such policy server, so I guess you can't connect to it using UniWeb if your game has a web version.
     
  38. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    No, the plugins do not work as google would need to provided a crossdomain.xml policy server, as you suggested.
     
  39. scone

    scone

    Joined:
    May 21, 2008
    Posts:
    244
    Hi there. I'm using UniWeb because I'm using ElasticSearch as my remote data store. The reason for this is that I'm trying to send a lot of data back (performance metrics per-frame and replay data) and a standard PHP/MySQL service is too slow. I can't use the WWW class because ES uses a very strict REST API and it is important that you be able to specify the request method (GET, POST, etc.).

    Just using HTTPRequest and HTTPResponse from .NET is working, but there's a pretty major blocking period (~250ms or longer) when the request is sent. It looks like you can make these calls asynchronous, but I figured I could save myself some time by trying UniWeb.

    Unfortunately, UniWeb isn't working at all. I enter the same URL (with port) and data as was working with HTTPRequest, but with UniWeb I get an error:

    System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it.

    Any ideas?
     
  40. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    Hmmm from here it would seem that perhaps the URL is not specifying the correct port? Are you able to show the URL you are using?
     
  41. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Sorry can't help you here :/
    We'll be working on a Facebook WebPlayer port soon, but nothing for the moment. If you find a way, please share it :)
     
  42. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Not working :(
    And I'm not going through the source code of mono to figure it why, too painful for now lol
     
  43. scone

    scone

    Joined:
    May 21, 2008
    Posts:
    244
    Actually, it looks like the server was down! HA! I can't check right now but I'll let you know if it's any other issue :)

    Out of curiosity, will the Request class solve my blocking problem?
     
  44. SinisterDex

    SinisterDex

    Joined:
    Jul 2, 2013
    Posts:
    3
    Hi,

    i'm currently considering buying your extension but would like to know how far your socket.io integration is.
    According to your description you support it. Does that mean you've implemented the entire socket.io protocol?

    Do you have a trial version for Uniweb?

    Thanks in advance for your answer
     
  45. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
  46. ohmdob

    ohmdob

    Joined:
    Jan 20, 2013
    Posts:
    1
    Hi,
    Can I use unity webplayer + uniweb on websocket protocol?
     
  47. arcadeindy

    arcadeindy

    Joined:
    Feb 4, 2013
    Posts:
    8
    I used uniweb for my web player (facebook), android and ios games with :

    - Node.js + Socket.IO + Websocket protocol. : stable.
    - SuperWebsocket 0.8 + private socket policy server : stable
    - Alchemy Websocket + private socket policy server : unstable.
     
  48. scone

    scone

    Joined:
    May 21, 2008
    Posts:
    244
    Hi again,

    So after recognizing my face-palm-server-fail, I'm able to successfully read/write to the server over HTTP. However, I've started getting some mysterious Unity Editor crashes since adding the calls to UniWeb. Then again, I'm on a different machine than I normally am right now, so it could be something unrelated. I'll let you know if I get more details on the nature of the crash.
     
  49. Spel

    Spel

    Joined:
    Nov 9, 2012
    Posts:
    1
    Hi.

    Assets/UniWeb/Plugins/Utility.cs(6,14): error CS0234: The type or namespace name `Web' does not exist in the namespace `System'. Are you missing an assembly reference?
     
  50. attiksystem

    attiksystem

    Joined:
    Aug 21, 2012
    Posts:
    23
    Hi, same problem here. I just bought Uniweb, and: