x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Question about networking

Hello everyone. I'm trying to write a MMO game, trying to write a connection to the MySQL server through a dedicated UE4, but apparently that is not possible, since I always new mistakes. So I decided to try to divide the logic on two servers: the first server (dedicated server UE4) will synchronize the movement, interaction, and so on, and the second server will interact with the database. Please tell me if I'm doing the right thing? Because of the two servers will not suffer optimization? Can someone tell me how to write the interaction with the database server on a dedicated UE4?

Product Version: UE 4.14
Tags:
more ▼

asked Jan 19 '17 at 12:20 AM in C++ Programming

avatar image

NODARYN
122 10 21 33

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

What you want to do instead is write your data access layer using an appropriate system (not UE4). A WebAPI would be a good choice. If you are using mySQL as your database then you may want to look into using PHP to write your WebAPI. If you search on Google you can find thousands of examples showing how to use PHP to build an API to interact with MySQL. Then you can access this WebAPI easily from blueprints in UE4 using the free VaREST plugin. Personally I prefer Microsoft SQL server so I wrote my WebAPI with Microsoft .NET and MVC.

more ▼

answered Jan 19 '17 at 12:40 AM

avatar image

Dartanlla
2.6k 62 26 281

avatar image NODARYN Jan 19 '17 at 01:33 AM

Can I use the PHP server instead of C ++?

avatar image Dartanlla Jan 19 '17 at 01:52 AM

PHP is a different language than C++. It is a higher level language so it will be much easier than C++. What you want to download to get started is a combo of Apache, PHP, and mySQL. That is everything you need to get started and you can download it all in one bundle for a wide variety of operating systems.

If you aren't set on using MySQL and you are developing on a Windows PC you might find IIS, Microsoft. NET, SQL Express to be easier to learn and they are also free. I have developed with both and much prefer the Microsoft toolset. Also, you can use the same Visual Studio Cummunity 2015 that you use for UE4 to build the WebAPI using Microsoft. NET. So you can build all of your games components with one tool.

avatar image NODARYN Jan 19 '17 at 02:48 AM

I just do not want for this to learn PHP and do not want to have PHP server proxy. It turns out I will have such a scheme: client-> dedicated server (UE4) -> PHP-> MySQL. I wanted to use a dedicated server as the core, ie to have such a scheme: client-> dedicated server (UE4) -> MySQL.

avatar image Dartanlla Jan 19 '17 at 02:55 AM

You can do that then. It isn't as flexible, but with C++ anything is possible. When I first started with my database project I directly integrated UE4 with Microsoft SQL before I realized that one dedicated server wasn't going to be enough and I would need dozens of dedicated UE4 servers.

What you will have to find is an unmanaged C++ library that can interface with MySQL. Then you add that library to your C++ project and then you can connect MySQL directly to UE4.

There are probably many libraries to choose from, but here is an example of one that looks promising:

https://dev.mysql.com/doc/connector-cpp/en/

Keep in mind this will take a pretty good knowledge of C++ programming to get this up and running.

avatar image NODARYN Jan 19 '17 at 03:33 AM

Thank you, I have attached a library to the C ++ project. My question is this: they say that C ++ - the fastest language of OOP. Is PHP equal speed with C ++? After all, he is not a compiled language. I apologize for such silly questions. I am familiar only with C ++ :)

avatar image Dartanlla Jan 19 '17 at 03:39 AM

You are correct. PHP is an interpreted language and is not compiled. It will never match the speed of C++. However, C++ is going require significantly more code to create the same interface to MySQL, so there are always trade-offs.

avatar image NODARYN Jan 19 '17 at 04:05 AM

Well, I knew what I wanted, thank you :) Additional question for off-topic: Tell me please, how can I automatically run what ever function as a server and to run this logic is performed only on the server? GameMode how strange works. It runs only on the server or on the client too?

avatar image Dartanlla Jan 19 '17 at 04:46 AM

Yes the GameMode only runs on the server. However, that doesn't limit you to only using the GameMode for your server side code. In blueprints you can us the Is Auth node to make sure code only runs on the server and in C++ you can use the following:

 if (Role == ROLE_Authority)

What you may find is that you make calls to the database from various objects like the Character or the Player Controller. Just make sure you always have a check to be sure database accesses only run from the server side.

avatar image NODARYN Jan 19 '17 at 04:55 AM

My GameMode reason invoked 2 times: when the editor is started and at the beginning of the game. I do not like it, I want to GameMode summoned 1 time. I want to start with the Dedicated Server is attached to my database one time, and the result is 2-3, and maybe more.

avatar image Dartanlla Jan 19 '17 at 06:32 AM

Yeah, I had the same issue, that is why I decided not to use the GameMode. Instead I make all my database calls from the Character, PlayerController, and for centrally located database calls, I just placed a custom Actor in the level to function the same as you are using the GameMode.

avatar image NODARYN Jan 19 '17 at 08:48 AM

Yes, I had such an idea, but it is necessary to create in C ++, but not in the editor, otherwise a dedicated server will not know about the existence of this actor. Thank you very much. P.S. I'm sorry for my English, it's Google translator to blame! : D

avatar image NODARYN Jan 20 '17 at 01:07 AM

I found a solution to the problem: I was trying to establish a connection through the class constructor, as needed through BeginPlay function!

avatar image NODARYN Jan 20 '17 at 01:23 AM

It should still check whether it is a dedicated server. Otherwise, the function will be called when the client is started, if it is not connected to the server.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question