Send HTTP request through browser to a program that is listening on a port - html

So I am trying to build a C Program that handles HTTP requests through a web browser. The program is listening on a predefined port for incoming HTTP requests and responds appropriately. It is working totally fine when I place is it in the root directory but it doesnt work when I move it to directory on its own.
For instance, this works:
localhost:9000
but this doesnt:
localhost:9000/myprogram
Any clues on how I may fix this?

Hard to answer with so few details. But to get started I would check the following:
What does the web server log say?
Is the web server configured to allow execution of [CGI] in this directory?
Are you sure you haven't mixed up the web root with the directory root, thus placing your
program in the wrong place?
Are the directory and program access modes set correctly?

Related

Local debugging of subdomains with VS 2015

I have a multi-tenant website that has to take care of any incoming request and determine the appropriate routing by the URL subdomain.
I set up the subdomain routing using this or a similar solution.
However I'm trying to access my website on my local machine using subdomains an alias website. I'm unable to get my local IIS to port to my website with the subdomain I've specified.
I want to dedicate a virtual domain name in my local machine that will port to the website I'm debugging on VS (localhost:23456).
I've read some answers of identical questions (like this or this one), but it looks like the system has changed with the new IIS and Visual Studio 2015 and ASP.NET 5 MVC 6 (vNext) project configuration.
Here's what I've tried according to the answers linked above:
I tried setting the hosts file porting www.myexample.com to 127.0.0.1 but I get a "Bad request" error when navigating to www.myexample.com:23456 in my browser, and anyway the debugger doesn't report a request.
I tried setting <binding protocol="http" bindingInformation=":23456:www.myexample.com" /> in the applicationhost.config file, gets IIS to raise an error saying "Replace hostname with localhost. Any other bindingInformation not specificying localhost as the website raises that IIS error.
Update
After opiants answer
I knew about the .vs folder and that's were I was configuring the bindings indeed.
However, looks like it was the permission that caused IIS to throw errors.
Running that netsh command solved the issue. And BTW, since I'm only running it my own machine, I'm not gonna need to open the firewall.
Anyway my question is if there is a way to add a wildcard instead of each subdomain separately? Since each tenant gets a unique subdomain, the whole process of adding subdomains is going to be dynamic by nature. I need to allow an asterisk in all the 3 places:
hosts file
applicationhost.config file
netsh command
It looks like I can add the asterisk in those places but it doesn't actually work.
I'm guessing you're using IIS express locally?
If so, in your solution directory, there is a .vs folder. You need to add the binding in the \config\applicationhost.config file inside that folder. Then make sure that you've allowed IIS express to listen to that subdomain.
You can refer to Scott's article on how to configure IIS Express. Specifically look for this paragraph "1. GETTING IIS EXPRESS TO SERVE EXTERNALLY OVER PORT 80"
To be more specific, you need to run these commands:
netsh http add urlacl url=http://{your-domain}:{custom-port}/ user=everyone
netsh firewall add portopening TCP {custom-port} IISExpressWeb enable ALL

How to create flash socket policy files to open port 843 for flash application in Apache server run on windows

I am creating a real time application and have come across HTML5 web-socket which is the ideal technique over ajax long polling. But web-socket is not guaranteed to run in every browser. I tested with IE-8 and IE-9, it is not supported in those versions.
I found web-socket-js which seems to be a perfect fallback for the browser not supporting modern web-socket. It uses flash for to carry out the task. But since flash 9, flash application are now required with flash socket policy file to access port 843. I have researchd in this article setting up a flash socket policy but could not find a solution that works with Apache installed in windows. How should I create this policy file and where should I put it. I am very much confused.
A policy file dictates the hosts from where .swf files can access services on the server. A policy file server is a TCP server that hosts a master policy file (an XML document) on port 843. The Flash Player first attempts to access the master policy file on this port, but if it doesn't find the policy file, requests for the file on the port on which it is trying to fetch the data.
That means the Flash Player actually makes 2 network requests. One goes to port 843 by default. If that request times out (in 3 seconds) then it makes a second request to the port you are making a connection to (presuming it's port 80 in your case).
If I remember correctly, the request is made to the following URL -
hostname:port//crossdomain.xml
In your case, I think it might just be a matter of putting the master policy file in the root of your web server. Apache uses the DocumentRoot directive in the .conf file to identify this directory.

Accessing a file on my domain relative to port

I am running a node server on port 3000. I have a css file stored just on http://mydomain.com/style.cssbut since every page right now is http://mydomain.com:3000/randompage.html How can I access the style.css file? I can get http://mydomain.com:3000/styles.css from the page I am working on, but that doesn't exist.
What is the best way to deal with this situation? I suppose it applies to any files I need to access.
I don't know a simple solution using a relative URL or some HTML magic in the page.
The usual solution is to install a module in Apache or a function in node.js which will redirect some requests to the other server so that for your HTML, everything seems to be coming from a single source.
This document should get your started when using Apache: Using mod_rewrite for Proxying

HTML5 WebSockets Only Work For Localhost

I am having a bit of a problem with HTML5 & WebSockets.
I have put together a very simple client / server application to pass strings to each other and all works well when I am accessing the client html page via a local file path or via http://localhost, however when I try and call it from http:// or http:// it doesn't seem to work.
The first thing the client does is check if the browser supports Web Sockets:
if (!window.WebSocket) {
_Status.innerHTML = "Web Sockets not support by this browser";
return;
}
When I browse to the page with the local host address window.WebSocket is true, but when I use anything else, the page works but window.WebSocket is false.
Am I missing anything obvious? Is it an IE permissions/trust issue?
I am using IE10 and Windows 8 Consumer Preview.
I am out of ideas. Has anyone got any ideas?
WebSockets uses TCP protocol layer to connect.
Server opens Socket and Binds it to specific Port. Then it listening port and accepting connections.
If you are trying to connect to your server, make sure that you use right external IP and you probably need to set up Port Forwarding on your router to your computer, that router will know where to redirect packets.

AS3 FTP Programming and the Socket and ByteArray Classes

Sorry for the subject line sounding like an even nerdier Harry Potter title.
I'm trying to use AS3's Socket class to write a simple FTP program to export as an AIR app in Flex Builder 3. I'm using an FTP server on my local network to test the program. I can successfully connect to the server (the easy part) but I can't send any commands. I'm pretty sure that you have to use the ByteArray class to send these commands but there's some crucial piece of information that I'm missing apparently. Does anyone know how to do this? Thanks!
Dave
The FTP protocol predates UTF encoding. Switch to ANSI/ASCII for better results. If you do opt for writeMultiByte instead of writeUTFBytes, be aware that it is buggy in linux. Here's one way around it.
There's another question here where the line ending turns out to be the culprit, so make sure that you get it right (as suggested above).
As said before, if this is running from the web, all socket connections will require a crossdomain policy, but this is NOT file based over HTTP. Recent changes to the security rules mean that any socket based connection must first get a crossdomain from a policy server hosted on port 843 of the target host.
Quoting from Adobe:
A SWF file may no longer make a socket connection to its own domain without a socket policy file. Prior to version 9,0,115,0, a SWF file was permitted to make socket connections to ports 1024 or greater in its own domain without a policy file.
HTTP policy files may no longer be used to authorize socket connections. Prior to version 9,0,115,0, an HTTP policy file, served from the master location of /crossdomain.xml on port 80, could be used to authorize a socket connection to any port 1024 or greater on the same host.
Essentially, what this means is that you must be in control of the target FTP host, and install supplementary software on it to get this working.
Read this link too and maybe it can be useful this one too.
The first one is about policy files and the second is an example of a TELNET (so, no FTP here) client.
I've been able to get an FTP client working in a browser, but it's buggy. I had to get a listener running on port 843 to server the policy file so that Flash would be allowed to connect and transfer data. Then, I had to figure out how FTP actually works:
You have to open 2 sockets: a command socket and a data socket. The command socket is where you send your USER, PASS, CWD, and STOR commands. The data socket is where you write your ByteArray data to. Sending the PASV command will tell you what port your data socket must connect to.
Where it is buggy is on Mac, in both Safari and FF, when I call the "socket.close()" command, the server socket actually closes. On Windoze, it does not. This is a huge problem because the Event.CLOSE event is not fired until the SERVER closes the connection. This is in the livedocs.
This is where I'm at. I have no idea why it would work flawlessly on Mac and then be completely busted in 3 different browsers on Windows. The only thing I can come up with is that it's either something in my Windows configuration that's preventing proper communication with the server, or it's the Window Flash player that's causing the problem.
Any thoughts?
We will need more info to resolve this.. What you're saying here appears correct to me. You're using the Socket class to send data though, not ByteArray.
Are you sure data is not being sent? How are you receiving the response? It may be that it's working fine but you're just not aware of it? As i said, tell us more about what you're doing..
Lee Brimelow has a screencast on gotoAndLearn of writing an POP3 client. It's essentially the same of what you're doing so take a look.
Are you 100% sure the syntax is correct? I know with HTTP you'll have to an include extra linebreak after the request for it to go through. Without it you'll get nothing back. Not sure how it is with FTP though.
The FTP standard requires CRLF at the end of commands. Try using "\r\n" in place of the "\n" in your example.
You must serve the CrossDomain Policy File from your FTP server in order to conect correctly.
From what I've gathered, you have to send each command one at a time and validate the response before moving on. You should be getting something back against ProgressEvent.SOCKET_DATA
Try just this and see what you get in response.
socket.writeUTFBytes("USER "+user+"\n"); socket.flush();
You would then read the response out like this.
var response:String = mySocket.readUTFBytes(mySocket.bytesAvailable);