I'm trying to get a connection via TCP sockets from my Phone that is plugged via USB to the PC. It does not seem to work. The Socket.ConnectAsync returns a Success, so the hostname (name of my PC) is correctly resolved. However, the first Socket.SendAsync ends up in a Connection Reset.
It works with the emulator and if the PC and phone are in the same private WiFi network, but never via the USB connection.
This is kind of strange, since HTTP traffic seems to work quite well: The phone's browser can connect to my PC's webserver (with both PC and phone beeing offline, just connected via USB) and a small test app can connect via HTTP (WebClient) to the PC, like asked in this SO question here.
So my question is, as there must be some security restriction that I did not discover yet, or some technical restriction: How can I get it to work, and if not, why?
Thanks in advance for any help with this!
Have you tried doing a connection using the Socket class to the web server (ie. port 80) on your computer?
I'm pretty sure the USB Connection Sharing for WP7 is restricted on the ports that it actually shares. I could be wrong, of course, but this would explain your situation.
Related
I'm trying to write a simple UWP IoT App that is to run on Windows 10 IoT Core on a Raspberry Pi.
The App need to test if another device is currently alive on the local network. All the Apps knows about this other device is its ip address.
I see from other SO questions that Ping is not supporten because ICMP is not supported on WinRT. I assume this also the case on UWP?
I guess I could create a socket and try an connect to for example port 80 and unless a time-out error is received then that means the device is available. However that "hack" seems a bit messy and I'm not sure that it would be solid enough to rely on.
Any other ideas for some C# UWP code that can be used for testing that a device is available and alive on a local network based on its ip address?
You are correct, ICMP is still not supported on UWP. But you could use this instead: https://github.com/christophwille/winrt-vasily (it's kind-of what you wanted to do, but already done)
I'm developing an app for remote monitoring of a small power plant. The idea is to keep the remote connection all the time.
We hava a small PC with broadband connection and in addition 3G/4G modem attached.
Checking the connectivity when I have broadband is quite easy for me.
fist I check if the interface that Im using is up, and then just with simple web client i check the response from google or any other site that I assume that should be online :-)
Im using System.Net.NetworkInformation.NetworkInterface.*
Then if there is no connection over the lan network Im connecting to 3G modem and starting 3G connection.
The problem is how to check if my lan connection again got the internet connection and disconnect 3G modem? How to check that particular interface from C# code that it has internet access?
Can I make some manual routing trough the interfaces, or its done somewhere inside the OS it self?
Some advice? Someone has got similar project?
Well you could fetch the Lan connection profile with the same library as the Profile Name is "Ethernet" and then to check you'll first need to connect to a LAN connection and then check and if the connection has internet access the stay else you'll have to switch back. I tried it it takes roughly 30 seconds to do a full route
Having some trouble with websocket-connection within the local network.
Scenario:
For my laptop (Win7) I've written a service which opens a websocket-server to port 2014. Because websockets aren't enabled by default for windows 7 I'm using the supersocket library ( http://www.supersocket.net/ ).
For the Client I've written a android app with sencha touch and Phonegap. To enable websocket- support for android devices with version lower 4.4 I've integrated the phonegap websocket- pugin.
The reason is to open a websocket-connection between the android device and the laptop to control the laptop by the android app. Both devices are members of the same local network.
The problem:
After installing both applications (windows service and android app) I've tried to connect my android device with the service from the laptop. First step is to open the connection on the client:
var connection = new WebSocket('ws://192.168.178.21:2014');
But in the event-logs of my windows service there is no successful connection logged.
After that I opened the browser of my laptop and tested the same code - successful. Client and Server could communicate with each other.
So I've tested the websocket-support on my android device: changed the websocket-url to
var connection = new WebSocket('ws://echo.websocket.org');
and could connect to the server -> Android websockets are okay.
Third step was to disable my firewall and check the connection with Wireshark:
Screenshot:http://www.directupload.net/file/d/3710/y9t79npy_png.htm
192.168.178.21 -> Laptop IP
192.168.178.23 -> Android device IP
So it seems that the packets reach my laptop but not the service. Additional tried to use the secure wss:// protocol - no victory.
Don't have any ideas anymore. Would be a pleasure to get some help :)
So it seems that the packets reach my laptop but not the service.
Could it be that the server is binding to a specific IP address or hostname? Often servers will implicitly bind to all interfaces, such as 0.0.0.0, but sometimes they bind to one specific interface. If that happens, then you need to connect to that same interface.
You said your client is connecting to ws://192.168.178.21:2014, but could it be that the server is binding to 127.0.0.1 or localhost or your hostname, and therefore doesn't see the request? That could explain why the laptop received the request, but not your service.
Then again, you said you tried it from your local browser, and it worked. Did you use the same IP address, or did you use 127.0.0.1 or localhost? Assuming you used the same IP address, 192.168.178.21, then that would indicate it's not the bind issue I described.
Sorry, that's all I can think of at the moment.
After some time i´ve found the solution:
Had to add the firewall rule to the public firewall options.
Thanks for your help:)
I've published an Android app which communicates with a C# server app via UDP. I've implemented an "Auto Connect" feature which does broadcasting and receives an answer from the server. Once an answer received by phone, the phone app holds the sender IP and sends subsequent messages to this IP directly. Also there is a Manual Connect feature which sends data to the IP address the user enters (which is the local IP of the PC running the server app).
So, everything works great for lots of users but some users reported me that when they use manual connect, it never connects; when they use auto connect, the server gets the broadcast message (seems connected) and the phone receives the answer but afterwards none of the (direct) messages will be received by the server app. The common point of these users is that their PCs are connected to the WiFi router by wire and their phones are connected by wireless. I've tried the same thing on my network but again it works for me without any problem.
May it be because of having multiple network interfaces (both LAN and WLAN)? I've been searching net for 1 week but no success.
What should I do? Please help.
Thanks in advance.
Ok, I tried for the last couple hours and I give up:
I develop for a mobile device (Win CE on Unitech HT660) and have a weird thing occurring:
I try to communicate with a service on my PC and I'm using TCPClient for it.
This works great except for one big problem:
Once I unplug the USB-Cable I use to copy the files from VS on program start TCPClient throws a SocketException that no socket connection could be made because the target machine actively refused it (not the case, Firewall is off, no third-party installed and the service is listening)
And it gets weirder: If the cable is plugged in and I remove it after the program made the connection everything works perfectly fine, I can send and receive data without the cable, I can just not connect without the cable.
Btw: It's the same story with MySQLConnection from the MySQL .NET Connector. It works with the cable, but if it is removed without an established connection no connection can be made.
Has anyone ideas on that?
Thanks in advance!
PS: One thing I forgot to mention: I use wireless to connect to my network, and IE as well as pinging the computer with the service and mysql database on it works.
If you're using Vista / Win7, check if the wireless network is set as private / office network.
Having it set to public network causes very weird symtoms.
Thanks for all the good advice, however in the end it was nothing with my code or the network or the server.
I checked it on another mobile device with no changes and it works.
Seems that the Unitech HT660 has some issue with TCP/IP connections under .Net.
Googled this and I'm not the only one with this problem...