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.
Related
apologies for weak English
Hello my friends
I have a problem that very confused me
Project description:
I created c# wpf project for server side and android studio app for client side. in wpf I coded socket communication codes also in android studio. main point is I connected my phone to pc by charger cable as modem to connect the internet. also use the phone for debugging android studio app. when I test the communication between my pc and phone established successfully . it connects very good on android virtual device manager too . but when my friend install client app on his phone , connection is not established and my ip (192.168.xxx.xxx) is not accessible for client. I tried by my public ip founded from whatismyip.com but I don't socceeded
thanks in advance
special thanks for you and other friends
For safety reasons your modem is blocking request that come from the outside of your local network. You must setup a NAT/PAT on your modem to allow external request to be treated. There is tutorial on internet depending on your modem.
Hope that will help you.
Have nice day !
your private IP "192.168.xxx.xxx" is not routed over internet, you have to use your public IP provided by your ISP provider(NAT), if you are using ADSL router, log in to it IN ORDER TO find your public IP, then do port forwarding to your local IP address,and enable dynamic DNS, then you can access your private IP using public IP from anywhere over internet
I’m working on a C# application. I need to know when the application connects to a different Wi-Fi network. The tricky part here is that the application is assigned the same IP address on both Wi-Fi networks:
The application is currently connected to Wi-Fi #1 with IP address 11.22.33.44.
On the PC where the application runs, I disconnect the PC from Wi-Fi #1.
The PC quickly connects to Wi-Fi #2 and is assigned the same IP address (in this example 11.22.33.44).
The application receives the NetworkChange.NetworkAddressChanged event.
The application loops in the network interfaces returned by NetworkInterface.GetAllNetworkInterfaces() in order to detect an IP address change (by checking if the IP address, assigned to a particular NetworkInterface.Id, has changed).
The problem is that the network interface information has not changed (NetworkInterface.OperationalStatus is still UP and the IP address is the same).
The NetworkChange.NetworkAvailabilityChanged event is not received. If the NetworkInterface.OperationalStatus was to DOWN and then back to UP, I could detect a change.
Any idea?
Is it possible to access the list of Wi-Fi network and find out which one the application is connected with?
Thanks!
Provided you are only interested in testing Wi-Fi networks, you could use the SSID to determine which network you are on.
Get SSID of the wireless network I am connected to with C# .Net on Windows Vista
I want to take control over all the requests which arrive to the virtual wifi hotspot.
I opened up a wifi hotspot via Microsoft Virtual WiFi Mini Adaptor through command prompt. I used netsh wlan start hostednetwork. I also put it into static ip mode to overcome with the android stuck at obtaining ip address issue. Everything is working fine.
Some time ago I built a server software with C# which binds to internal ip address of the wifi hotspot. I use it as a file server, remote computer controlling purposes.
Here is core section: If you connect to the hotspot from a device like android phone or pc, open the browser and type http://192.168.137.1:8080/ (hotspot pc ip address) on address bar, you simply connect to it and a home page appears and so on. But I want every client to be redirected to my server.
So regardless of what they put into address bar like google.com, facebook, yahoo, they will be redirected to my server and visit its homepage. This is something like controlling DNS, I guess. Is it possible to take control over every request that way?
I finally figured it out. First of all I need a DHCP server.
Here is one: http://tftpd32.jounin.net/
This also may help: http://www.wikihow.com/Set-up-DHCP-on-a-Local-Area-Network
With this program I can run and configure its DHCP server. I need to set the DNS server address to my own servers address (like 192.168.0.1 which is default gateway). So when clients connect to my virtual hotspot, they will receive this as a DNS server address. Clients will request every domain name from that address (instead of 8.8.8.8 which is Google Public DNS for example). So I also need a DNS server of my own. It must be bound to port 53 (192.168.0.1:53 with UDP protocol, not TCP!!) which is default DNS port number. Main server must be bound to 192.168.0.1:80 with TCP. Notice that it is bound to HTTP port.
If everything goes fine after doing these, my DNS server will give main servers IP address to clients regardless of the domain name IP they requested. Hence they will connect to my server instead of real ones (facebook,youtube etc).
By the way the DHCP server program which I given the url of is working very well for me. It is very simple and efficient. It will eliminate issues like "Android stuck at obtaining IP address". It also provides other servers such as TFTP, SNTP, SysLog and DNS. It also works so fine even without any advanced virtual hotspot program (such as Connectify). You may only call "netsh wlan start hostednetwork" command. I don't intent any promotion here. I'm just trying to help.
If you want redirecting all domain search queries to your ip address you have to control the DNS.
The best way is to operate as a proxy service between your client and the destination, so you can manipulate the query of the client.
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 am developing a LAN-based database application. It involves a central "server" app to house the database, along with many "client" applications that access it.
The "server" will be a simple C#-based HTTP server that responds to GET and POST requests. However, since it is designed to be able to run from any laptop on the network, I am wondering how to establish the connection between clients and the server without knowing the IP address.
I suppose I could ping every IP address from 192.168.0.0 to 192.168.0.255, and then test those that responded to see if any are my server. But I would only do that if there is no better way. Any suggestions?
Many of these types of discovery services run by putting out some kind of beacon on either the subnet broadcast address (for 192.168.0.0/24 it would be 192.168.0.255) or by putting out a beacon on a multicast address.
Multicast is particularly interesting because in a properly configured network, it allows hosts to find the service even across subnets. Routers and switches won't generally forward broadcast packets across subnet boundaries, but multicast packets will.
The beacon would have information in it such as the port the service is running on, what type of service it is, whatever is needed to start using the service.
To head you in the right direction, what you should do is have the database server running on a specified port. Then send out a broadcast to that port from the client (the system needing to connect to the database). When the database server receives this, it will be able to respond to the sender, allowing a handshake to occur.
Of course, you will need to validate the database server's authenticity (to make it secure, unless you aren't worried about that). This can be as simple as having the client display 4 numbers which then need to be typed into the database, so that the database can send the 4 numbers back to the client proving it is the right computer (how the iTunes remote works), or you can use certificates (but that is too complex a topic for me to cover correctly).
After that the two computers will know each others IPs, and you're set!