communicate on public ip from socket - c#

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

Related

How to handle any request coming to my virtual wifi hotspot in Windows 7

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.

websocket can´t reach local network client service

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:)

Android UDP broadcasting works but direct IP not working

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.

WP7: TCP connection from phone to PC via USB

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.

Port forwarding on Windows 7

How do I redirect an incomming request on port xxx to localhost:yyy on windows 7?
Development Server (vs 2008) only allow access from localhost which isnt good enough. I need to test my app from various computers.
Thanks for the suggestions guys, although I found the answer myself.
I downloaded Microsoft SOAP Toolkit version 3 and started MSSoapT, created a formatted trace listening on port 8080, forwarding to host: 127.0.0.1 port: 3804. My problem was I used "localhost" and not "127.0.0.1".
Now every request made to my development machine from other computers through port 8080 will be redirected to port 3804 where ASP.NET Development Server is statically set to listen when debugging VS.NET webapps.
On the command prompt.
$> netsh
$> interface portproxy
$> add v4tov4 listenport=xxx connectaddress=127.0.0.1 connectport=yyy protocol=tcp
See: http://technet.microsoft.com/en-us/library/cc776297%28WS.10%29.aspx#BKMK_1
If this really is for some testing, you could create a server which listens on a port, and when it receives an incoming connection spawns a thread that opens a connection to the actual local server, and afterward just waits for data to come in either end and shuffle it along to the other end. If either socket closes, the worker thread would terminate. This is obviously not a scalable solution, but for testing it should easily do the trick.
Not really sure what you are looking for. However port forwarding will be relevant when you have a router in place and you need to explicitly forward a request on a specific router port to a specific IP and port on a LAN computer. If you want to access the web server from other LAN computers on the same network then http://ip-address should just work fine. Also make sure that your web server is listening on the LAN IP and is not just bound to localhost.
I'm using windows 7 64 bit and couldn't get the Microsoft SOAP Toolkit to work on my machine for port forwarding and didn't like the free port forwarding software I found out there so I just changed my VS 2010 web app to use local iis, I know this doesn't help people running 2008 but it works if you have 2010... Here's a screen shot of my change: I'm doing this for testing on the iPad...

Categories