views:

159

answers:

4

Hey, I want to write a browser-chat and write an own server in c++, because you can not send text between the different instances (chat user) in php and other languages. I have apache running with port 80 and that's why I cant run the "chat http server" on port 80. Some browsers block connection to a http site if it does not use port 80. Does someone knows, what port I should use for this small server for best browser compatibility? Maybe 8080? I could also buy a different IP to run it under :80, but my host wants 5€ per month for a new ip...

Thanks.

A: 

Use hostname to partition your application --i.e., www.foo.bar:80 and chat.foo.bar:80 ?

Hassan Syed
As far as I know you can only open a socket on an IP, not a hostname?
Dr. Unknown
uhm yes, but your webserver has the ability to route traffic based on hostname -- i.e., a webserver can server a thousand different domain names on a single physical_server-ip_address pair.
Hassan Syed
Yeah but my server has an own listening socket, so this would not work. mod_proxy (Tronic), will solve this problem.
Dr. Unknown
yes it will ..... its a fundamental feature of the HTTP protocol.
Hassan Syed
I dont understand this. I got one IP and if I set up apache on port 80 on this IP, I can't run a second web server on this port, because apache will answer them all, even if I didn't set up a VirtualHost for each hostname.
Dr. Unknown
you can use the same apache process to forward requests to a different hostname.
Hassan Syed
A: 

Besides port 80, port 443 (normally https) is most common to be allowed for outbound connections through various firewalls.

Anders Abel
I already use https and I think there are some browsers that only allow connection to 443 if it's really https with a ssl-cert
Dr. Unknown
+1  A: 

You can use mod_proxy (or mod_proxy_balancer) to forward requests on some branch of your Apache site to the other web server that listens to localhost on some other port.

Tronic
Good idea, thank you. Do you think it slows down the connection speed? The http-chat server only provides text, apache for everything else (graphics, ...). So it shouldn't be a problem, right?
Dr. Unknown
A: 

You could write your site in a Apache mod_chat or something. This way you keep all the basic HTTP stuff to Apache and can concentrate on your application will the full power of C++.

Gianni
I'm not into apache modules. As far as I understand apache's modular structur, it will open an own thread for each chat user. So I can't send chat messages to every user who is in the same room. That's why I want to code it as an own webserver. I think it's not a good idea to write the texts into a database (like mysql) and request a new text multiple times a second. That would result in bad performance.
Dr. Unknown
@Dr. You could create a shared memory area where all threads or processes (depending how your apache is set up) can exchange data. You would have to solve the same problem if you create your own server, except if you use single process asynchronous architecture.
Gianni