node.js - NodeJS Socket.io -


i newbie nodejs. have learnt simple things in node , socket.io. till did practice external folder, i,e not in local server or live server. trying in local server. have folder structure this:

  xampp\htdocs\socketexmp->         .node-modules         .chat.js         .chat.html 

i have pointed chat.html file virtual server host name as:

   http://dev.chatexmp.com 

which running on port 8080. , node server running on port:8000. these 2 files under. chat.js

    var app = require('express')();       var http = require('http').server(app);       var io = require('socket.io')(http);        app.get('/', function(req, res){       res.sendfile('chat.html',{root:__dirname});       });       users = [];       io.on('connection', function(socket){       console.log('a user connected');       socket.on('setusername', function(data){       console.log(data);       if(users.indexof(data) > -1){       socket.emit('userexists', data + ' username taken! try other username.');       }       else{       users.push(data);       socket.emit('userset', {username: data});       }       });       socket.on('msg', function(data){       //send message       io.sockets.emit('newmsg', data);       })       });       http.listen(8000, function(){       console.log('listening on localhost:8000');       }); 

and chat.html

           <!doctype html>             <html>             <head><title>hello world</title></head>             <!-- <script src="/socket.io/socket.io.js"></script> -->             <script src="http://localhost:8000/socket.io/socket.io.js"></script>             <script>             var socket = io();             function setusername(){             socket.emit('setusername', document.getelementbyid('name').value);             };             var user;             socket.on('userexists', function(data){             document.getelementbyid('error-container').innerhtml = data;             });             socket.on('userset', function(data){             user = data.username;             document.body.innerhtml = '<input type="text" id="message">\             <button type="button" name="button" onclick="sendmessage()">send</button>\             <div id="message-container"></div>';             });             function sendmessage(){             var msg = document.getelementbyid('message').value;             if(msg){             socket.emit('msg', {message: msg, user: user});             }             }             socket.on('newmsg', function(data){             if(user){             document.getelementbyid('message-container').innerhtml += '<div><b>' + data.user + '</b>: ' + data.message + '</div>'             }             })             </script>             <body>             <div id="error-container"></div>             <input id="name" type="text" name="name" value="" placeholder="enter name!">             <button type="button" name="button" onclick="setusername()">let me chat!</button>             </body>             </html> 

currently, running example starting node server , going browser , typing:

  localhost:8000 

and works fine. can chat. want is, want go virtual host:

  http://dev.chatexmp.com:8080 

and make work. not functioning. have seen tutorials this , this. may level low , not understood. can 1 kindly make me understand how should , make function. thank you.

this apache configuration file i,e httpd.conf

  #             # main apache http server configuration file.  contains             # configuration directives give server instructions.             # see <url:http://httpd.apache.org/docs/2.4/> detailed information.             # in particular, see              # <url:http://httpd.apache.org/docs/2.4/mod/directives.html>             # discussion of each configuration directive.             #             # not read instructions in here without understanding             # do.  they're here hints or reminders.  if unsure             # consult online docs. have been warned.               #             # configuration , logfile names: if filenames specify many             # of server's control files begin "/" (or "drive:/" win32),             # server use explicit path.  if filenames *not* begin             # "/", value of serverroot prepended -- "logs/access_log"             # serverroot set "/usr/local/apache2" interpreted             # server "/usr/local/apache2/logs/access_log", whereas "/logs/access_log"              # interpreted '/logs/access_log'.             #             # note: filenames specified, must use forward slashes             # instead of backslashes (e.g., "c:/apache" instead of "c:\apache").             # if drive letter omitted, drive on httpd.exe located             # used default.  recommended supply             # explicit drive letter in absolute paths avoid confusion.              #             # serverroot: top of directory tree under server's             # configuration, error, , log files kept.             #             # not add slash @ end of directory path.  if point             # serverroot @ non-local disk, sure specify local disk on             # mutex directive, if file-based mutexes used.  if wish share             # same serverroot multiple httpd daemons, need change @             # least pidfile.             #             serverroot "e:/xampp/apache"              #             # mutex: allows set mutex mechanism , mutex file directory             # individual mutexes, or change global defaults             #             # uncomment , change directory if mutexes file-based , default             # mutex file directory not on local disk or not appropriate             # other reason.             #             # mutex default:logs              #             # listen: allows bind apache specific ip addresses and/or             # ports, instead of default. see <virtualhost>             # directive.             #             # change listen on specific ip addresses shown below              # prevent apache glomming onto bound ip addresses.             #             #listen 12.34.56.78:80             listen 80             listen 8080              #             # dynamic shared object (dso) support             #             # able use functionality of module built dso             # have place corresponding `loadmodule' lines @ location             # directives contained in available _before_ used.             # statically compiled modules (those listed `httpd -l') not need             # loaded here.             #             # example:             # loadmodule foo_module modules/mod_foo.so             #             loadmodule access_compat_module modules/mod_access_compat.so             loadmodule actions_module modules/mod_actions.so             loadmodule alias_module modules/mod_alias.so             loadmodule allowmethods_module modules/mod_allowmethods.so             loadmodule asis_module modules/mod_asis.so             loadmodule auth_basic_module modules/mod_auth_basic.so             #loadmodule auth_digest_module modules/mod_auth_digest.so             #loadmodule auth_form_module modules/mod_auth_form.so             #loadmodule authn_anon_module modules/mod_authn_anon.so             loadmodule authn_core_module modules/mod_authn_core.so             #loadmodule authn_dbd_module modules/mod_authn_dbd.so             #loadmodule authn_dbm_module modules/mod_authn_dbm.so             loadmodule authn_file_module modules/mod_authn_file.so             #loadmodule authn_socache_module modules/mod_authn_socache.so             #loadmodule authnz_fcgi_module modules/mod_authnz_fcgi.so             #loadmodule authnz_ldap_module modules/mod_authnz_ldap.so             loadmodule authz_core_module modules/mod_authz_core.so             #loadmodule authz_dbd_module modules/mod_authz_dbd.so             #loadmodule authz_dbm_module modules/mod_authz_dbm.so             loadmodule authz_groupfile_module modules/mod_authz_groupfile.so             loadmodule authz_host_module modules/mod_authz_host.so             #loadmodule authz_owner_module modules/mod_authz_owner.so             loadmodule authz_user_module modules/mod_authz_user.so             loadmodule autoindex_module modules/mod_autoindex.so             #loadmodule buffer_module modules/mod_buffer.so             #loadmodule cache_module modules/mod_cache.so             #loadmodule cache_disk_module modules/mod_cache_disk.so             #loadmodule cache_socache_module modules/mod_cache_socache.so             #loadmodule cern_meta_module modules/mod_cern_meta.so             loadmodule cgi_module modules/mod_cgi.so             #loadmodule charset_lite_module modules/mod_charset_lite.so             #loadmodule data_module modules/mod_data.so             #loadmodule dav_module modules/mod_dav.so             #loadmodule dav_fs_module modules/mod_dav_fs.so             loadmodule dav_lock_module modules/mod_dav_lock.so             #loadmodule dbd_module modules/mod_dbd.so             #loadmodule deflate_module modules/mod_deflate.so             loadmodule dir_module modules/mod_dir.so             #loadmodule dumpio_module modules/mod_dumpio.so             loadmodule env_module modules/mod_env.so             #loadmodule expires_module modules/mod_expires.so             #loadmodule ext_filter_module modules/mod_ext_filter.so             #loadmodule file_cache_module modules/mod_file_cache.so             #loadmodule filter_module modules/mod_filter.so             #loadmodule http2_module modules/mod_http2.so             loadmodule headers_module modules/mod_headers.so             #loadmodule heartbeat_module modules/mod_heartbeat.so             #loadmodule heartmonitor_module modules/mod_heartmonitor.so             #loadmodule ident_module modules/mod_ident.so             #loadmodule imagemap_module modules/mod_imagemap.so             loadmodule include_module modules/mod_include.so             loadmodule info_module modules/mod_info.so             loadmodule isapi_module modules/mod_isapi.so             #loadmodule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so             #loadmodule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so             #loadmodule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so             #loadmodule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so             #loadmodule ldap_module modules/mod_ldap.so             #loadmodule logio_module modules/mod_logio.so             loadmodule log_config_module modules/mod_log_config.so             #loadmodule log_debug_module modules/mod_log_debug.so             #loadmodule log_forensic_module modules/mod_log_forensic.so             #loadmodule lua_module modules/mod_lua.so             loadmodule cache_disk_module modules/mod_cache_disk.so             #loadmodule macro_module modules/mod_macro.so             loadmodule mime_module modules/mod_mime.so             #loadmodule mime_magic_module modules/mod_mime_magic.so             loadmodule negotiation_module modules/mod_negotiation.so             loadmodule proxy_module modules/mod_proxy.so             loadmodule proxy_ajp_module modules/mod_proxy_ajp.so             #loadmodule proxy_balancer_module modules/mod_proxy_balancer.so             #loadmodule proxy_connect_module modules/mod_proxy_connect.so             #loadmodule proxy_express_module modules/mod_proxy_express.so             #loadmodule proxy_fcgi_module modules/mod_proxy_fcgi.so             #loadmodule proxy_ftp_module modules/mod_proxy_ftp.so             #loadmodule proxy_hcheck_module modules/mod_proxy_hcheck.so             #loadmodule proxy_html_module modules/mod_proxy_html.so             #loadmodule proxy_http_module modules/mod_proxy_http.so             #loadmodule proxy_http2_module modules/mod_proxy_http2.so             #loadmodule proxy_scgi_module modules/mod_proxy_scgi.so             #loadmodule proxy_wstunnel_module modules/mod_proxy_wstunnel.so             #loadmodule ratelimit_module modules/mod_ratelimit.so             #loadmodule reflector_module modules/mod_reflector.so             #loadmodule remoteip_module modules/mod_remoteip.so             #loadmodule request_module modules/mod_request.so             #loadmodule reqtimeout_module modules/mod_reqtimeout.so             loadmodule rewrite_module modules/mod_rewrite.so             #loadmodule sed_module modules/mod_sed.so             #loadmodule session_module modules/mod_session.so             #loadmodule session_cookie_module modules/mod_session_cookie.so             #loadmodule session_crypto_module modules/mod_session_crypto.so             #loadmodule session_dbd_module modules/mod_session_dbd.so             loadmodule setenvif_module modules/mod_setenvif.so             #loadmodule slotmem_plain_module modules/mod_slotmem_plain.so             #loadmodule slotmem_shm_module modules/mod_slotmem_shm.so             #loadmodule socache_dbm_module modules/mod_socache_dbm.so             #loadmodule socache_memcache_module modules/mod_socache_memcache.so             loadmodule socache_shmcb_module modules/mod_socache_shmcb.so             #loadmodule speling_module modules/mod_speling.so             loadmodule ssl_module modules/mod_ssl.so             loadmodule status_module modules/mod_status.so             #loadmodule substitute_module modules/mod_substitute.so             #loadmodule unique_id_module modules/mod_unique_id.so             #loadmodule userdir_module modules/mod_userdir.so             #loadmodule usertrack_module modules/mod_usertrack.so             loadmodule version_module modules/mod_version.so             #loadmodule vhost_alias_module modules/mod_vhost_alias.so             #loadmodule watchdog_module modules/mod_watchdog.so             #loadmodule xml2enc_module modules/mod_xml2enc.so              <ifmodule unixd_module>             #             # if wish httpd run different user or group, must run             # httpd root , switch.               #             # user/group: name (or #number) of user/group run httpd as.             # practice create dedicated user , group             # running httpd, system services.             #             user daemon             group daemon              </ifmodule>              # 'main' server configuration             #             # directives in section set values used 'main'             # server, responds requests aren't handled             # <virtualhost> definition.  these values provide defaults             # <virtualhost> containers may define later in file.             #             # of these directives may appear inside <virtualhost> containers,             # in case these default settings overridden             # virtual host being defined.             #              #             # serveradmin: address, problems server should             # e-mailed.  address appears on server-generated pages, such             # error documents.  e.g. admin@your-domain.com             #             serveradmin postmaster@localhost              #             # servername gives name , port server uses identify itself.             # can determined automatically, recommend specify             # explicitly prevent problems during startup.             #             # if host doesn't have registered dns name, enter ip address here.             #             servername localhost:80              #             # deny access entirety of server's filesystem. must             # explicitly permit access web content directories in other              # <directory> blocks below.             #             <directory />                 allowoverride none                 require denied             </directory>              #             # note point forward must allow             # particular features enabled - if something's not working             # might expect, make sure have enabled             # below.             #              #             # documentroot: directory out of serve             # documents. default, requests taken directory,             # symbolic links , aliases may used point other locations.             #             documentroot "e:/xampp/htdocs"             <directory "e:/xampp/htdocs">                 #                 # possible values options directive "none", "all",                 # or combination of:                 #   indexes includes followsymlinks symlinksifownermatch execcgi multiviews                 #                 # note "multiviews" must named *explicitly* --- "options all"                 # doesn't give you.                 #                 # options directive both complicated , important.  please see                 # http://httpd.apache.org/docs/2.4/mod/core.html#options                 # more information.                 #                 options indexes followsymlinks includes execcgi                  #                 # allowoverride controls directives may placed in .htaccess files.                 # can "all", "none", or combination of keywords:                 #   allowoverride fileinfo authconfig limit                 #                 allowoverride                  #                 # controls can stuff server.                 #                 require granted             </directory>              #             # directoryindex: sets file apache serve if directory             # requested.             #             <ifmodule dir_module>                 directoryindex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \                                default.php default.pl default.cgi default.asp default.shtml default.html default.htm \                                home.php home.pl home.cgi home.asp home.shtml home.html home.htm             </ifmodule>              #             # following lines prevent .htaccess , .htpasswd files being              # viewed web clients.              #             <files ".ht*">                 require denied             </files>              #             # errorlog: location of error log file.             # if not specify errorlog directive within <virtualhost>             # container, error messages relating virtual host             # logged here.  if *do* define error logfile <virtualhost>             # container, host's errors logged there , not here.             #             errorlog "logs/error.log"              #             # loglevel: control number of messages logged error_log.             # possible values include: debug, info, notice, warn, error, crit,             # alert, emerg.             #             loglevel warn              <ifmodule log_config_module>                 #                 # following directives define format nicknames use                 # customlog directive (see below).                 #                 logformat "%h %l %u %t \"%r\" %>s %b \"%{referer}i\" \"%{user-agent}i\"" combined                 logformat "%h %l %u %t \"%r\" %>s %b" common                  <ifmodule logio_module>                   # need enable mod_logio.c use %i , %o                   logformat "%h %l %u %t \"%r\" %>s %b \"%{referer}i\" \"%{user-agent}i\" %i %o" combinedio                 </ifmodule>                  #                 # location , format of access logfile (common logfile format).                 # if not define access logfiles within <virtualhost>                 # container, logged here.  contrariwise, if *do*                 # define per-<virtualhost> access logfiles, transactions                 # logged therein , *not* in file.                 #                 #customlog "logs/access.log" common                  #                 # if prefer logfile access, agent, , referer information                 # (combined logfile format) can use following directive.                 #                 customlog "logs/access.log" combined             </ifmodule>              <ifmodule alias_module>                 #                 # redirect: allows tell clients documents used                  # exist in server's namespace, not anymore. client                  # make new request document @ new location.                 # example:                 # redirect permanent /foo http://www.example.com/bar                  #                 # alias: maps web paths filesystem paths , used                 # access content not live under documentroot.                 # example:                 # alias /webpath /full/filesystem/path                 #                 # if include trailing / on /webpath server                 # require present in url.                  # need provide <directory> section allow access                 # filesystem path.                  #                 # scriptalias: controls directories contain server scripts.                  # scriptaliases same aliases, except                 # documents in target directory treated applications ,                 # run server when requested rather documents sent                 # client.  same rules trailing "/" apply scriptalias                 # directives alias.                 #                 scriptalias /cgi-bin/ "e:/xampp/cgi-bin/"              </ifmodule>              <ifmodule cgid_module>                 #                 # scriptsock: on threaded servers, designate path unix                 # socket used communicate cgi daemon of mod_cgid.                 #                 #scriptsock cgisock             </ifmodule>              #             # "e:/xampp/cgi-bin" should changed whatever scriptaliased             # cgi directory exists, if have configured.             #             <directory "e:/xampp/cgi-bin">                 allowoverride                 options none                 require granted             </directory> 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -