Javascript client C++ server game - javascript

I have a question which path should I follow.
I want to develop real time online game via webbrowsers.
I would want to write game server using C++ with TCP sockets listening. The client side game will be written in javascript. The only problem I dont know how to communicate javascript with c++ server using TCP sockets. I have considered using Socket.IO but as far as I know this library does not have option to just connect to real TCP server, push bytes through and read incoming ones. Instead I would need to use some wrapper like Node.JS server which I want to avoid.
Anyone could guide me which path I should take?

You could make your game server itself an HTTP server. For the most part it could just serve up your static files, but when it received a WebSocket upgrade request, it could handle that however it desired.

You should take a look to websockify:
websockyfy is a WebSocket to TCP proxy/bridge. This allows a browser
to connect to any application/server/service. Implementations in
Python, C, Node.js and Ruby.

Related

Why in socket io they having set of script lines in html page?

I am trying to develop a flutter chat app using nodejs and socketio.i'm just getting started with the socketio i have surf several examples in which every front end or client side having a set of socketio script. Can i develop my code purely server side? so that i can integrate with any type of front end.
You can do that. Socket.io is a web socket implementation in node js. It enables real-time, bidirectional and event-based communication between client and server.
Server and client can send and receive the events. If you don't want write any script in client side then you don't have any use of sockets.
Edit:
socket.io given nice example for chat application with explanation. https://socket.io/get-started/chat/
Socket.io has two distinct parts - the server and the client. The docs make this clear. There is nothing preventing you from just writing the server part, and leaving the client implementation out of the equation, for someone else to implement.
Although the main point of Socket.io is to implement the WebSocket protocol, it does so by wrapping it in its own interface, so to speak. So a socket.io server can only talk to socket.io clients, not clients that implement WebSocket in other ways. That being said, there are socket.io client libraries for pretty much every major language out there:
Javascript (main client)
Java
C++
Dart/Flutter
You also asked about React and Angular, but both of those are web front-ends, so there should be no reason why they can't use the standard Javascript client library with those frameworks.

Communication between client side javascript and C++ socket server

I would like to communicate between my browser on the client PC and a C++ socket server running on an another PC.
I researched online pretty much enough. I came across socket.io, HTML5 Websockets.
Though I am not sure about socket.io, websockets require a server that supports websockets. The pure old C++ socket server does not. Changing the server side is not an option. Is there anything else I can do with websockets?
Using socket.io, can I achieve the goal without installing an interpreter like nodejs on the server side? Any additional introduction of Javascript/Jquery library on the client side is affordable.
Or is there any other approach I can use?
Thank you.
C++ sockets and websockets are quite different things, having "socket" in their names doesn't mean they operate the same. Websockets protocol is RFC6455. There're several C++ libraries for implementing websocket support, if you can't use any type of web server.

How to set up a JS Require tool to require('net') on the client side?

So my application is running Sails.js, which is an extension of node.js. I'm very new to the JS backend framework scene, and I'm attempting to send a TCP message using a socket from the client side. However, in order to do that I need to require('net'). How can I do this? I don't even see the net module in my node_modules folder - does it not come with Sails.js?
How can I resolve this issue?
Also, just for extra clarification, I need to use require() on the browser side - apologies for not being more clear in my original question.
You can't use the node.js net module on the client side. Browsers don't allow you to access plain TCP sockets. That would enable you to circumvent many of their security features, so it simply is not going to happen.
You can implement realtime communication with your own server with web sockets or a wrapper suck as socket.io, but that obviously doesn't let you talk in arbitrary protocols.

Websockets and telnet connection

Does anyone know if it is possible to use HTML-WebSockets to listen to a telnet stream?
Description: I have a DSL-Phone-Router (Fritzbox) which has a "Callmonitor"-function. This sends for every incomming/outgoing call a telnet line with specific infos.
I can see this stream, when i run...
telnet fritz.box 1012
on my Windows-CMD or MAC-Terminal.
My Question: Is it possible, that HTML5-Websockets can listen to this stream? Or can HTML5-Websockets only listen to a Websockets-Server like node.js etc...?
The websockify project was created for exactly this sort of thing. It is a python program that bridges between the WebSocket clients and raw TCP servers. You will need somewhere to run websockify, but the websockify requirements are fairly minimal. Also, you will need to implement the client side (HTML/Javascript) to display the stream, but websockify includes a wstelnet.html example that you should be able to modify or use directly for that purpose. Disclaimer: I created websockify.

Is it possible to connect to SSH using JavaScript?

I know there is an implementation of VNC using WebSockets (http://novnc.com) but that still requires a server. I am looking to create a simple client-side JavaScript only (no Flash) connection to a port running SSH. I am guessing WebSockets is the only way to go since it does TCP. Any example code? Any other way?
Sorry, given your constraints (client-side Javascript only), there is no way to connect to a plain old SSH server.
WebSockets is not plain TCP. It's a framed protocol with a HTTP-like handshake between the client and server that includes origin policy.
Flash can make plain TCP connections, but it also has origin policy enforcement. The way it does this is by making a connection to the same server on port 843 and asking for a special XML file that contains the origin policy.
If you are willing to relax your constraints slightly such that you are willing to run a generic WebSockets to TCP proxy either on a server (any server) or on the client then you can do what you are wanting to do. noVNC includes a C and python WebSockets to TCP proxy: http://github.com/kanaka/noVNC/tree/master/utils/.
Other info you might find useful:
Current WebSocket draft: https://datatracker.ietf.org/doc/html/draft-hixie-thewebsocketprotocol-76
Simple (insecure) way of running a flash policy server (Linux/UNIX with socat) is described here: http://github.com/kanaka/noVNC/blob/master/docs/flash_policy.txt
More info about the flash policy file: http://code.google.com/p/doctype/wiki/ArticleFlashSecurity
You can take a look at serfish. It's a solution to access a SSH server. But if you're hosting your web application on the same server as your ssh, there are other solutions such as shell in a box.
For those still searching, paramikojs could be the answer.
I'm currently having a similar issue:I need a SSH JS client-side implementation, and I need it to be BSD licensed. Alas paramikojs seems to be GPL licensed.
It's definitely possible using a Linux emulator with full network support like the great OpenRISC emulator jor1k.
Note that I've created browser-tools.net, a collection of in-browser tools from number of different projects.
Yes you can
Install SSH server on your server
Write a server side program (could be in PHP) that uses SSH
client in the background
Redirect messages between the SSH client (that probably has been residing in the same server as SSH server) and the JavaScript program in the web browser other side of the internet.
That server side program acts like a postman only and the java script program in the browser is just another postman between the user and server program.
(SSH server)<->(SSH client)<->(PHP e.g)<->(JavaScript)
Also don't forget that in the JavaScript program could have use Ajax for better mechanism. Also SSH client might be not completely and absolutely necessary because that PHP server side program could directly connect to SSH server

Categories