WebChatapp with C++ I need suggestions from the start - c++

I can't decide which way I should take so instead of trying all options I would like to get expert's or more knowlageable people's ideas since I'm a C++ newbie. (After frustration with php for years I understood C,C++ is the way to go )
Extra info: I'm only linux user for a year :)
--Here is what I want to do: Webapp that people can register and chat and be friends. Like facebookchat but no less ability than it (should be realtime all the way) (For instance: If a friend closes the browser it should be seem unavailable).
--Options I have I guess: Using boost:asio, using BSD directly, using opensource server like nginx,lighttpd with fcgi (I din't like libev, libevent.)
--Here is main questions:
1) Is Nginx+fcgi+CPP spawning a new Cpp programme for each request (Performance would be bad)
2) Would using a ready server+FCGI make it impossible or harder the chat thing i stated above.
3) Would you choose BSD, asio or tweaking a ready server for such thing?(with a short why)
(Scability for development is main concern. I mean if it requires new implementations it should be done in future)(blaa blaa must be done)
What would you do?

I think I'd step back a bit, and consider a few questions. First and foremost, it's not apparent from your question whether you're basically trying to set up a web site (or something on that order) that provides this service, or you want to write software that (or example) others could incorporate into their web sites.
Second, it's not entirely clear whether you're interested primarily in the client side, the server side, or both. Most of what you talk about is on the server side, but the features you talk about providing are mostly on the client side.
Third, is the question of whether you're willing to write a closed system that requires your client to work with your server, or you want to use something like XMPP to provide compatibility with existing software.
To summarize: you seem to be jumping directly into nitty-gritty details of how to do things; before you can figure out how very well, you first have to decide exactly what you're going to do. Until those are answered, many of the "how" questions can't be -- and after they're answered, many of the "how" questions may easily disappear.

I would start playing with Wt (http://www.webtoolkit.eu/wt) which is a framework for Web applications, or Qt (http://qt.nokia.com/products/) which offer good http and https support

Related

Web App and c++

It's something totally new for me, and since it seems to be something trivial, I can't find any response with our beloved friend ggle...
My question is : I have to create a webapp that can work if the client have nothing on his computer but a browser. My question is : is it possible to include to my project an external library (here I want to use PCL (Point Cloud library), a C++ library), and make it works even if the client have nothing installed? If I use QtWebKit for example, will I be able to create this kind of webapp?
Thanks a lot, and sorry for the (maybe) stupid question, I never did web dev before, it's my first time. ...
Have a nice day!
Wow, that question is as broad as the day is long, but here goes (you don't give too much about your background so I apologise if I am going too basic).
A web browser is just a piece of software that knows how to process HTML, CSS and Javascript passed over HTTP from a TCP socket.
So, on a most basic level, to get something to work in a browser all you need is to write a program that listens on a TCP socket and passes headers and HTML in the body of the response as per the HTTP protocol.
So, leaving aside the socket part, your method may look something like this:
std::cout << "<h1>Hello, world!</h1>" << std::endl;
In fact, the vast majority of the original dynamic web sites worked just like this: they were just C programs that just happened to produce HTML as output in the old days (cgi-bin).
The main issue with this approach is it's very tedious and time consuming to write code to that level of detail to generate HTML, especially when you factor in CSS and JavaScript.
This is one of the key reasons that most web applications these days are implemented in Java, .Net, Ruby, PHP etc as there is a wealth of fully-featured, stable and mature frameworks for web development that take the grunt work out of creating dynamic web sites (and C/C++ is much rarer).
However there are a couple of good frameworks out there for C++ if that is definitely the language you want to use.
Wikipedia has a limited section on C++ frameworks but it covers the 2 I would suggest investigating (CppCMS and Wt):
https://en.wikipedia.org/wiki/Comparison_of_web_frameworks#C.2B.2B
Of these, I've only had direct experience of CppCMS but I can recommend it - it's approach is idiomatic C++ (to my eyes at least, but I must confess I am more often a Java web developer than C++)
Also, there is quite a useful if slightly dogmatic SO discussion on this thread that may be relevant:
How popular is C++ for making websites/web applications?

Best way of logging a user in C++

I am trying to get into C++ programming so apologise if this is a bit of a stupid question.
I am attempting to create a program in C++ that is linked to a website via the database, that's all sorted. In this program, the user must log into it to be able to use its features, I've also managed to do this fine. My question is, what is the best way of storing that users session so I can refer to their username, display that users settings from the database e.c.t?
I am unsure, but I don't think c++ has session options like in php so I cannot do it that way. I did some googling before I posted this, spent all night trying to find a solution, I found nothing.
My knowledge if c++ is slim and this may sound like a more complicated or unnecessary route to take, but it was thinking of perhaps when the user logs in, to create a txt file storing that users username and then calling on it when I need to refer to that users username for queries and such, then when the user logs out or closes the program it deletes the file. Is that stupid? Forgive me if it is.
Is there better way to go about this?
Thanks for your time!
EDIT
I read your comments, if it needs to be a stand-alone application, like some sort of client, you could take a look at the C++ libraries I mentioned, but I'd use any higher level language (Java or C# have good documentation and there are many tutorials for creating GUIs, if that's what your're looking for. I think even Python would make a good candidate).
If you really must use C++, your best bet would be to use an existing library to implement your web solution. POCO includes an HTTP server framework, and a library for sockets and other forms of low-level network programming. Boost ASIO can also serve your purposes. But this is hardly something I'd recommend to start learning programming, or C++ for that matter.
If you want to learn about web programming, then you should definitely take a look at other languages. PHP or ASP.NET come to mind. AS you learn, you'll most likely also end up writing some form of Javascript. You can find a lot of info out there, just Google for tutorials. A site to get started is w3Schools, but any site with tutorials will do. Good luck!

Desktop SCADA Application - Reading and Writing to PLCs through C++

I did my best to search all topics regarding to SCADA and developing your own C++ desktop application to communicate with PLCs, but could not find any recent, or in my opinion, relevant topics that fit what I needed. If I missed them, a link to them would be very much appreciated. If I also happened to post this in the wrong section, or you can think of a better section for me to post this in, I will take it there.
With that said, I thank you in advance for taking the time to read my questions, and appreciate any input you have to offer.
A little bit about what I'm doing
I'm currently in school for electromechanical engineering, and for my final year project I am developing a desktop application in C++ to monitor PLCs we have located within one of our labs.
Within this lab, I have a pre-existing ethernet network connecting all PLCs to single point, which I am tying into with a PC, and will be doing all my work from there.
I will be developing the application in Qt for an easy way to design the GUI, and giving me access to the QNetworkInterface as well as QTcpSocket.
With that said, I wouldn't go as far as saying I'm an experienced programmer, but I have been fooling around with a few languages (i.e.: python, c++, c, php) for quite a few years, and am still learning, considering the learning NEVER stops.
My questions
Is there any reference material I can read, that you can suggest, on the subject to more easily understand what sort of process I need to go through to receive information (i.e.: individual I/Os, status bits, tags, logs, etc...) from the PLCs directly, and not through an OPC server?
If an OPC server is required, I've never dealt with OPC links other than using Rockwell Automations RSLinx to grab tags and display their values within excel (I had created a prototype using that exact method to start, but would like to move away from excel, and if possible, the OPC server (RSLinx) as well). What would you suggest to someone who knows nothing about the subject of OPC servers, or to my knowledge, OPC in general?
Have any of you previously written your own application to do something similar, if not of the same nature to what I'm trying to accomplish?
What advice or suggestions would you give for someone who is attempting this type of project?
PS: As a start for this project, I would initially just want to get the reading of the I/Os (tags or addresses) to view what their current values are (closed or open for inputs, energized or not for outputs). But eventually I would also like to be able to write values to tags on the PLCs I'm monitoring based on the values I've received from them.
PSS: I would like to note again, that I am still a student, and am still learning about this subject in it's entirety. I would just like to ask for your patience, as I may not grasp things completely the first time!
If I've missed any information you feel is pertinent to be able to provide an answer, please let me know! I will do my best to come up with said information in a timely manner!
Thank you!
EDIT #1: Added in another question, and altered my first question slightly
EDIT #2: Fixed up question 2
IMHO a SCADA program should have as a minimum requirement to be able to connect to an OPC server. OPC is used for most commercial PLCs.
Strictly speaking there is no need to have an OPC server/client approach but it gives you flexibility and gives you an abstraction model. If you want to directly connect to PLCs using a protocol then that is of course possible as well. You then need to know more details about the protocols and their various versions.
Yes I worked for a few years in a team that developed a commercial SCADA application.
It is very easy to get lost in details in such a project so try to keep things as simple as possible. By using OPC you will save time instead of fiddling directly with the protocols. You could add the ability to add custom-drivers for other protocols - depending on your timeframe. Try to model up your project before you start coding to a birdsview of the model and avoid getting lost in the details.
I would stay well away from looking to write your own code to connect directly
to an AB PLC - there are products out there that you can use in your application:
http://www.rtaautomation.com/software/ethernetip/client/tagc/ControlWin.html
http://www.automatedsolutions.com/products/dotnet/ascomm/
You would be better to use OPC - you can write you own OPC client if you want and follow examples you find here:
http://www.opcconnect.com/source.php#freesource
According to this http://www.control.com/thread/1026173407 you should be able to get source code of Kepwares OPC Quick Client.
It would probably be easier to just use a library as in this example (RSLogix,C#):
http://www.mesta-automation.com/opc-client-with-c-an-how-to-video/
You might find this of use:
http://www.rockwellautomation.co.kr/applications/gs/ap/GSKR.nsf/files/rslinxsdk_ma_eng.pdf/$file/rslinxsdk_ma_eng.pdf
Some resources:
http://www.opcconnect.com/ ,
http://www.mesta-automation.com/
Answer to question #4 - realize that your lab technically could contain ANY manufacturer's PLCs in the future. If you ever took a Data Communications class, you realize that for N different PLC types, you would have to write N different communication drivers for your PLC client.
This is where standards are helpful. Without the use of a standard protocol, scaling your lab could become more time consuming and less manageable. This is why communications standards exist.
HOWEVER, not all PLCs necessarily support the standard(s) you may decide upon.
The best choice is OPC/UA. Many PLCs have server drivers readily available. That means that your client just needs to understand 1 protocol (OPC/UA), and then it can "easily" be connected to any PLC that has a driver for that standard.
After that, there is OPC. After that, Modbus (TCP and RTU flavors), a relatively simple industry standard that is supported by most PLCs. EtherNet/IP is also a possible choice, although not all PLCs support it in a "server" role (many do support it as a client, but that is not what you need).
have a look at pycomm in github or pylogix at github which are Python written drivers to link to clx plc.

Create a C++ program that processes incoming calls on a phone-line (land-line)

For some time now I've been tossing around what I think is am awesome idea: I want to write essentially a C++ phone server to handle all of my incoming calls on a land-line. I'll have a white-list (yay never having to worry about telemarketers ever again!), a black-list, and will be able to access my phone using my gaming headset, allowing me to make/answer calls while I'm gaming or whatever. In the future I'd also like to hook it up to a gui and make it have pop-ups and other cool features.
The problem is, I have no idea where to start. I'm familiar enough with C++, but have no idea how to go about doing anything with a phone-line. I can plug a phone-line into my computer, but I have no idea how to get my program to be able to use that connection. There's WinSock2 for being able to use my ethernet connection, is there something similar I'd be able to use to use the phone line? As it's using the same ethernet jack, I wonder if it's even possible to use WinSock2 to use the phone-line?
I saw this post, which wasn't particularly helpful: stackoverflow link , which points out Dual-tone multi-frequency signaling. I stumbled across this site: link, but isn't really going to help me get started.
So I was wondering, is there some sort of library out there that would allow me to tap into a phone-line that's connected to my computer? Is there a standard somewhere out there concerning phone-lines and what the different combinations of tone's mean? Can anyone here help get me started? I realize it's somewhat of a big undertaking, so any push in the right direction would be greatly appreciated. Thanks.
[Update:]
I found this question, which is a step in the right direction, but I'm not sure yet if it helps me (I need to go to bed, and will take a look at it in the morning). I did see mention of a Microsoft Telephony API though, I'll try doing more research on that tomorrow.
If working with MS products is not an absolute necessity, you might also consider taking a shot at Asterisk. This is an open-source PBX (in software) that allows development on Linux, Windows (emulated) and Mac. At the company where I work, we use it for implementing small-scale exchanges, about a 100 lines or so. It also interfaces well with VoIP and allows a whole host of protocols. I have developed scripts and programs in C++ that work on voice packets in real-time, and so far, my experience has been good. As for your stated use-case of blocking telemarketers etc., this would be a very good fit. Check out further details here.
After doing more research, having one link lead to another link, and coming up with new search terms, I stumbled across this site that looks like it could kick me off using the Windows Telephony API in C++: link. This link includes open source c++ samples showing how to do the basics of what this question asks, I'll just have to test to see if they actually still work.
This is only the beginning of my research, so I'll keep you posted on any other findings. If anyone else is knowledgeable in this area, please still feel free to drop me information on what I want to accomplish.

Any way to display C++ on a webpage?

Is there a relatively easy way to display the output of a C++ program on a webpage? And I don't mean manually, in other words, you see it on a webpage as it runs not as in I make a code tag and write it in myself.
EDIT: Just so everybody can get this clear I am going to post this up here. I am NOT trying to make a webpage in C++. Please excuse me if this sounds spiteful or anything but I am getting a lot of answers relating to that.
Step one, get yourself a server-side language. Be that PHP, ASP, Python, Ruby, whatever. Get it set up so you can serve it.
Step two, find your language's exec equivalent. Practically all of them have them. It'll let you run a command as if it were from the command line, usually with arguments and capture the output. Here's PHP's:
http://php.net/manual/en/function.exec.php
Of course, if you're passing user-input as arguments, sanitise!
I've just seen that you accepted Scott's answer. I usually wouldn't chase up a SO thread so persistently but I fear you're about to make a mistake that you'll come to regret down the line. Giving direct access to your program and its own built-in server is a terrible idea for two reasons:
You waste a day implementing this built-in server and then getting it to persist and testing it
More importantly, you've just opened up another attack vector into your server. When it comes to security, keep it simple.
You're far better having your C++ app running behind another (mature) server side language as all the work is done for you and it can filter the input to keep things safe.
You could write a CGI app in C++, or you could use an existing web server language to execute the command and send the output to the client.
You want to use Witty.
Wt (pronounced 'witty') is a C++
library for developing interactive web
applications.
The API is widget-centric and similar
to desktop GUI APIs. To the developer,
it offers complete abstraction of any
web-specific implementation details,
including event handling, graphics
support, graceful degradation (or
progressive enhancement), and pretty
URLs.
Unlike many page-based frameworks, Wt
was designed for creating stateful
applications that are at the same time
highly interactive (leveraging
techinques such as AJAX to their
fullest) and accessible (supporting
plain HTML browsers), using automatic
graceful degradation or progressive
enhancement.
The library comes with an application
server that acts as a stand-alone web
server or integrates through FastCGI
with other web servers.
I am not sure this is what you are looking for but you may want CGI You may want to look at this SO question, C++ may not be the best language for what you want to do.
based off the questions you posted Writing a web app like what you want is no simple task. What I would recommend is use some other library (this is one i found with a quick google) to get a web console on your server and give the user it is running under execute deny permissions on every folder except the folder you have your app installed.
This is still is a risky method if you don't set up the security correctly but it is the easiest solution without digging around too much on existing libraries to just have the application interactive.
EDIT --
The "Best" solution is learn AJAX and have your program post its own pages with it but like I said, it will not be easy.
It sounds like you want something like a telnet session embedded in a webpage. A quick google turns up many Java telnet apps, though I'm not qualified to evaluate which would be most ideal to embed in html.
You would set up the login script on the host machine to run your c++ app and the user would interact with it through the shell window. Note though that this will only work for pure command line apps. If you want to use a GUI app in this way, then you should look into remote desktop software or VNC.
It may be worth looking into Adobe's "Alchemy" project on Adobe Labs
This may help you with what you're trying to achieve.
:)
Are you looking for something like what codepad.org does? I believe they explain how they did it here.
There is a library called C++ Server Pages - Poco. I used it for one of my college project, its pretty good. There is also good documentation to get started with, u can find it here http://pocoproject.org/docs/