问题
I'm working on a school project. The goal is to link a Windows Phone 8 (WP8) with a server (node.js using sails.js framework based on express.js) by TCP socket.
I have found a great tutorial for the C# part (WP8), I'm working with a Windows 8 Virtual Machine but it's not an issue. (Just slow an borring -_-)
Based on the tutorial, I "realized" the WP part. I realized also the node.js server, using socket.io.
Here the WP8 tutorial: http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202858(v=vs.105).aspx
Here my WP8 application (8.0): (Based on the tutorial but customized)
SocketClient: http://pastebin.com/8ncad4EV
MainPage.cs: http://pastebin.com/5VAU96JV
Mainpage.xaml.cs: http://pastebin.com/hhvmQvPS
Here, a screenshot of the application + node.js server side source code:
On the left screen you can see the server side code which create "listeners". At right the VM with WP8 and the emulator. As you can see, I can connect to my server using socket. But I don't get any response.
About server logs, there is no log created when I run the WP8 application, it's writted than the connection is a success but no log on the server about it.
You can see the website directly here: 137.135.176.144:1337 and you can use the javascript console for run tests if you want, like:
socket.emit('disconnection', function(res){console.log(res);});
You will see a response from the server about you are disconnected (it's just a log, not true) and I will get it on my own console, server side.
But when I try to connect with WP8 or netduino (because I have to connect netuido and WP8 using sockets with node.js) it's the same. No error during connection but no response.
So, I'm here because I'm noobie about node.js and I tried a lot of things but still the same. Could you help me? Thank you.
I'm trying something else. Another code client side (WP8). Because I was running synchronious requests, I'm trying to run asynchronious now, because the node.js server is asynchrone:
Source code
You can create a new project, add this class and call it in the "main" function.
Output:
Application proccessing...
Application started
Operation processing: Connect
Connect: Successful connection etablished to Unspecified/137.135.176.144:1337
Operation processing: Send
Operation processing: Receive
Data received: connection (10)
Date received is equal to the data I sent myself (you can see it line 70). I don't get data from the server (Or I do it wrong) and I don't see any connection on the server console.
As you can see I'm not sure to call the good URL, but if I write http:// before the IP address, the program throw a SocketException: "No such host is known"
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'System.Net.Sockets.SocketException' occurred in System.Net.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'System.Net.Sockets.SocketException' occurred in System.Net.ni.dll and wasn't handled before a managed/native boundary
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in SocketsTest.DLL
I don't understand why it throw an error with http://. The source code server side is the same than before.
Could you help me? I'm pretty lost here. Thank you.
来源:https://stackoverflow.com/questions/19103993/connect-wp8-vm-with-node-js-server-using-tcp