2018-01-06 01:20:40

Hello.
Earlier I decided that I would use the following programming languages: C#, Python, Java, PHP.
But now I'm thinking about developing MUD games.
There are a lot of popular and trusted libraries in C and C++.
Should I use C or C++ for my tasks?
Do I need a deep knowledge of C or C++ when using libraries or not?
Thanks in advance!

2018-01-06 06:10:03

Let me answer your questions, and advise you, too.
1. Use C++. C makes for very dirty implementations that are hard to use. Bad (or good?) thing is your going to be using it anyway.
2. Yes, indeed there are a lot -- and I do mean a lot! -- of libraries available out there. On Linux you have your standard POSIX sockets implementation. Then there's Boost.Asio, Poco, Dlib, and much more. I'll post an example of a socket writer in C++ below, as an example, as I find that that is the easiest to get comfortable with. This sample uses Boost.Asio:

//compile with g++ srcfile.cpp -lboost_system -pthread 

#include <boost/asio.hpp>

int main()
{
boost::asio::io_service io_service;
boost::asio::ip::tcp::socket sock(io_service);
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query("localhost", "4321");
boost::asio::connect(sock, resolver.resolve(query));
boost::asio::write(sock, boost::asio::buffer("Hello world socket\r\n"));
return 0;
}

In C, this looks like:

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

int main() {
int i, sock, len, slen;

struct addrinfo hints, *addrs;  
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;

   if (0 == getaddrinfo("localhost", "256", &hints, &addrs)) {
sock = socket(addrs->ai_family, addrs->ai_socktype, addrs->ai_protocol);
if ( sock >= 0 ) {
if ( connect(sock, addrs->ai_addr, addrs->ai_addrlen) >= 0 ) {
const char *pm = "Hello world!";
do {
len = strlen(pm);
slen = send(sock, pm, len, 0);
pm += slen;
} while ((0 <= slen) && (slen < len));
}
close(sock);
}
freeaddrinfo(addrs);
}
}

As personal preference, I do prefer Rust to C and C++:

// Echo server, handles (perhaps) only one connection, don't really know
use std::net::*;

fn handle_client(stream: TcpStream) {
loop {
let mut text = String::new();
stream.read_to_string(&text).expect("Failed to read TCP stream.");
stream.write (text.as_bytes());
}

fn main() {
let listener = net::TcpListener::bind("127.0.0.1:2500").expect ("Cannot bind to port 2500.");
for stream in listener.incoming() {
match stream {
Ok(s)=>handle_client(s),
Err(e)=>error!("IO Error: {}", e),
}
}
}

That's my personal preference though.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2018-01-06 08:24:23

Hello.
But the point is, should I use C++ if I want to use predefined libraries or other languages. Should I be a C++ professional to work with libraries?

2018-01-06 09:51:07 (edited by Ethin 2018-01-06 09:51:39)

This question is very hard to answer and really depends on your personal preference. And, to be honest (and blunt), it seems like your switching languages a lot and can't find a good language to settle down with. I know the feeling, but if your going to make anything big and major you can't really sprinkle lots of different languages in it because that makes the compiler (that is, the person who's building the project) need far more dependencies. For instance, if you mixed C#, C, C++, and Rust in a single project, you'd need .NET/.NET Core, all the packages (Nu or via assemblies) to satisfy .NET or .NET Core, a C compiler capable of compiling both C and C++, all the C and C++ libraries which you used, the Rust compiler, and all the crates you used when using Rust. This is a symptom known as 'dependency hell'. Dependency hell is a colloquial term for the frustration of some software users who have installed software packages which have dependencies on specific versions of other software packages.
The dependency issue arises around shared packages or libraries on which several other packages have dependencies but where they depend on different and incompatible versions of the shared packages. If the shared package or library can only be installed in a single version, the user may need to address the problem by obtaining newer or older versions of the dependent packages. This, in turn, may break other dependencies and push the problem to another set of packages. Unlike the dependency hell described here where the user gets frustrated, the builder also runs into this problem; they have to build libraries, compilers, programs and tools, which may need other libraries, programs, tools, etc., and so on and so forth, until your building so much that you run out of disk space or you enter a dependency loop and go no further, which only causes a massive mess that you cannot recover from. I would highly advise that you find a language your comfortable with first, program in it for a few months, if not a few years, look up code examples, research it, and then start doing big projects in it. Only then will you alleviate this problem permanently. But if you interbreed multiple languages together, your *going* to run into dependency hell, whether you like it or not. .NET/.NET Core does not have this problem only because the different CLI/CLR languages can be safely mixed because assemblies are language-agnostic. You have clearly rejected C# in favor of others and, therefore, will not have this safety resolver.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2018-01-07 09:37:38

Hello.
No, I don't want to use multiple languages in the same project. I'm interested in what I should have knowledge of C++ for using ready-made libraries. I don't want to develop from scratch. I know the basics, conditions, variables, loops, arrays, pointers, OOP in C++, is this knowledge sufficient?
I like using C# or Python, but I need a reliable tool for developing a server for Linux. For C++, there are many libraries and examples for my tasks, but I'm not sure that my knowledge is sufficient.
Thanks in advance!

2018-01-07 10:50:37

Yes, your knowledge is sufficient. Developing something like that from scratch is simply stupid, so use what libraries you have. To do something like this, find a good networking library or list of networking libraries (I'd recommend http://en.cppreference.com/w/cpp/links/libs as a highly-prised list) as a possible starting point. Look at examples and find what you feel most at home with.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2018-01-07 13:18:31

hello
so you need recommendation for networking libraries
1. boost.asio
2. eNet
3. sdl2_net
4. kNet
5. curl (for http/ftp etc)
6. winsock (if you are using windows)
7. poco
8. openssl (for ssl and encryption)
9. crypto++ for encryption algorithms
10. happyhttp
11. tomCrypt for encryption/decryption
note these libraries all are not ment to be used specificly for mud, but might use them (boost.asio or sdl2_net)

2018-01-07 14:15:06

I want to use one of the MUD engines. But I want to know that my knowledge of C++ is enough. Because many people told me that I have to know STL and many other tools. Stroustrup writes in his books that C++ is not suitable for those who want to use ready-made solutions.

2018-01-07 17:13:16

My problem is the choice between C and C++. Can I use C, etc.? It's a simple language, but it's difficult to develop on it. I do not know if I can use ready-made libraries.

2018-01-07 19:22:05

@jonikster, C++ and C are the same language with a few extras with C++. And that's not what he meant. You can develop ready-made solutions in C++ or develop with them.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2018-01-21 22:35:38

I'm skipping all ethin's back and forth and just responding to your question.
I've written a mud engine which you can check out here:
https://github.com/sorressean/aspen.
This is a good starting point if you want to use c++--it's light weight, pretty barebones and a good jumping off point. But unless you have a reason to use C++ (I started this back before 1 gb VPS systems were $5/m), get something like python and evennia. It's fast, stable, has a lot of unit tests and code coverage and works great. No reason to develop a mud in c++ anymore, unless you have a specific purpose (I still love my engine concept because it has a very low memory footprint and allows you to extend it with Angelscript). Map out your game and see which you'd prefer, then take one or the other.
I've also got a socketmud c++11 implimentation if you want to use that and just have something to work from.
I used to be a fan of boost but recommend staying far away from it. I ripped it out of my mud engine and there are much better networking libraries out there (libevent, for example), etc.
HTH,

2018-01-21 22:42:47

@sorressean, your attitude is seriously reminding me of a perfectionist. You skip my posts because you could care less if I'm right or wrong because I might get a fact wrong, or might be wrong. It's starting to seem like you want me *always* to be right, or you hate me because I might be more wrong than I am right. If you actually cared to read my posts, primarily in post six, I did post to a plethora of C++ libraries. But you don't care because I might be 3-5 percent more wrong than I am right. But hey, that's you. tongue

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2018-01-21 22:45:47

No, you're usually totally wrong and your arrogant "I know everything" attitude coupled with your utter lack of experience and your copypaste examples to try to show that you know what you're talking about simply aren't worth wasting the effort to read through. It's clear you're here in this specific forum to bolster your own ego, and apparently hearing yourself speak is all it takes. For the rest of us, it's not flattering.

2018-01-21 22:52:46

Copyposting? Oh, please! Post six was not copyposting. Post 10 was not copyposting. Posts 2 and 4 weren't copyposting.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2018-01-22 05:11:01

Post 2 is a direct copypaste:
https://rosettacode.org/wiki/Sockets
You might have changed the formatting, but it's exactly the same code.
As for the boost asio which you copypasted for this post:
http://forum.audiogames.net/viewtopic.php?id=22076
this can be found here:
https://rosettacode.org/wiki/Sockets
The difference is you removed a linefeed and in your previous post you took away the namespace...
PS: c and c++ are vastly different languages. c++ might be a subset of c, but it's not a few extras... Unless you consider OOP concepts, classes, templates, all just "a few extras"
There are even many small differences. For example you don't need to refer to struct foo as you did in the code you copyasted.