Jump to content

  • Log In with Google      Sign In   
  • Create Account

hplus0603

Member Since 03 Jun 2003
Offline Last Active Yesterday, 06:22 PM

#5199175 Is it possible to use Dart lang for Apach server?

Posted by hplus0603 on 19 December 2014 - 04:14 PM

In the release article, there is this disclaimer:

Note: I wouldn't put this on a public host for now, there are probably bugs!


Also, the last commit was 2 years ago, so I don't think it's actively maintained.

That being said, if you clone it and build it and install it for your Apache host, you can likely use Dart in Apache:

https://github.com/sam-mccall/mod_dart

If you go the other how to access PHP code from dart client, how to implement it?


Easiest is to decide on an intermediate representation, such as XML or JSON.
Then write POST handlers in PHP, and POST to your Apache/PHP server from your Dart client.


#5199114 Is it possible to use Dart lang for Apach server?

Posted by hplus0603 on 19 December 2014 - 10:25 AM

Yes, you can use Dart language server-side within Apache, with the (unsupported) mod_dart plug-in:

http://news.dartlang.org/2012/05/run-dart-in-apache-web-server.html


#5198221 best way to send an receive multivarible data by socket

Posted by hplus0603 on 14 December 2014 - 07:18 PM

you just can set some varibales into an string


Several suggestions above indicated why this is a bad idea. For example, string manipulation in C# generate lots of garbage, and the string encoded values will use more bandwidth (as they are longer than equivalent binary encoded values.)


#5198162 extreme NAT punchthrough, UDP over DNS :p

Posted by hplus0603 on 14 December 2014 - 12:41 PM

Points for creativity :-)

Here are some challenges you'd have to overcome:

1) DNS is heavily cached. The time-to-live for various DNS entities is measured in hours, not milliseconds.
2) Many ISPs actually intercept DNS and resolve it themselves, rather than forwarding to an external DNS server. For example, Comcast does this, to send you to their own ad-filled "search help" page if you mis-type a domain name.
3) Most pay-for hotspots that I know about hijack both DNS and HTTP/HTTPS to bring up a "please pay now" paywall for whatever the first request is that your browser makes.
4) Some ISPs with strong "intrusion detection" systems (to clamp down on botnets and whatnot) may detect your unusual traffic as malicious.

Good luck, and please let us know how it goes :-)


#5198042 best way to send an receive multivarible data by socket

Posted by hplus0603 on 13 December 2014 - 04:00 PM

Check out the BinaryWriter and BinaryReader classes.
http://msdn.microsoft.com/en-us/library/system.io.binarywriter(v=vs.110).aspx

Note, though, that the TCP stream will not tell you where one packet ends and another starts. Thus, you need to prefix each packet with a length in itself.
Thus, you typically generate a packet by writing data using a BinaryWriter to a MemoryStream, then get the length, and write length (as a two byte ushort, typically) and the actual data from the MemoryStream. When receiving, you do the reverse: wait until there's at least two bytes read the length, then read that many bytes, stuff it into a MemoryStream, and use a BinaryReader to read the data back out.


#5197715 TCP clients-servers-servers

Posted by hplus0603 on 11 December 2014 - 08:51 PM

Generally, for each user, there is some management state. Every so often (server tick rate) the game examines the world state, examines what it's told that specific user about, and figures out what to tell the user next. It then makes up a packet of messages, and sends that packet on the socket. Repeat for all users, for all time steps, forever.

If the server has X connected users, and Y steps per second, and Z cores, the max amount of CPU time it can spend on a user is Z/(X*Y) seconds, or it will start to fall behind. Some games can get away with very low values of Y -- 1 or 2, say.

The "world state" for each user could include a queue of messages. A broadcast would then mean creating the broadcast message, and linking it into the outgoing queue of each user. (Ref counting may help save memory here.) However, if a particular player logs in even one simulation step after the world broadcast is sent, that user will not see the broadcast. Thus, it's much better to sync state (and control information) than it is to sync events, for most cases. (Events can still be useful for some things.)


#5197170 How2Ensure UDP-Packets reach target (high performance)?

Posted by hplus0603 on 09 December 2014 - 08:16 AM

You have two options:

1) Wait until you know that you have received all commands from all players.
or
2) Process commands/data with some risk of not having got a particular command.

Using 1 can lead to frustrating lag.
Using 2 can lead to frustrating missed commands.
You have to design your game for choosing some particular balance between one and the other.
RTS games are typically written using 1).
FPS games are typically written using 2).


#5197165 how to specify clients on server

Posted by hplus0603 on 09 December 2014 - 08:12 AM

When a client connects, put that connection (socket) into a map/hash table/other container.
When a client disconnects (or you get a write error to that client,) remove it from the map/table/container.
Each time you want to send a message to all clients, you have to iterate over the currently connected clients, and send the same message to each of them.
With TCP, there is no other way -- you have to send the same message many times (one per client.)


#5196749 Networking for CoC-like mobile games?

Posted by hplus0603 on 07 December 2014 - 01:49 AM

I don't know how Clash of Clans does it.

One option (some games do this) is to run a simulation that the player can't really affect -- and thus, the entire battle can run much faster than real-time on the server, and is pre-determined before the player even sees it play out.

In CoC, if you are not online, can you play a battle? Can you actually affect the outcome (direct where units go, add reinforcements, etc) in real time? If so, they run the battle on the client. One option to do that, yet be cheating resistant, is to record all the client commands, and re-play the battle on the server; if the server finds a different outcome than the client, it can assume the client is cheating (or has a bug.)


#5196320 Get External IP Address Without 3rd Party Websites

Posted by hplus0603 on 04 December 2014 - 03:07 PM

You can't do anythong on the local client machine to make this robust. The closest you can come would be to attempt to discover/configure a gateway that uses UPnP. Different platforms have somewhat different libraries/support for that -- there's no single API like for UNIX sockets / WinSock.
However, UPnP is only a half-solution, because very often, it doesn't work. The real solution is one of the following:

1) Tell users to set up port forwarding on their gateways/firewalls.
2) Use an external NAT introducer/match-making server.


#5196177 Distributed transaction & message queue

Posted by hplus0603 on 03 December 2014 - 09:02 PM

You are forgetting that ACID databases do not lock reads while you have a transaction open.

Locking the data from read access while you are writing to it in a transaction is not the default action of ACID databases. You have to manually lock it.


This is not a true statement.

The DEFAULT behavior of MySQL might be "REPEATABLE READ" transaction isolation level, which has some of the behavior you're suggesting. However, this does *not* count as ACID, because it's missing the "I" value.
In MySQL, you should make sure to run all transactions in "SERIALIZABLE" transaction isolation level, which does fully implement ACID and behaves properly with regard to read-after-read hazards (and all other hazards described here.)
More documentation on MySQL transaction isolation levels: http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_transaction-isolation

Other databases (Postgres, Oracle, DB/2, SQL Server, etc) mostly have similar trade-offs available, although some of them may default to different levels.

Note that, at the DBA level, there are many other things that could turn your "durable" transaction non-durable. Hard disks with caches that don't survive power loss (this may include SSDs) and disk chipset drivers that play fast and loose with out-of-order command queueing come to mind for example.
Running a real, online, system of any kind (game or not) requires a separate set of knowledge, skill, and actions that are totally different from developing a game or application. Arming developers (and operators) with understanding of both sides of this equation is what the DevOps movement is about.


#5196104 Appwarp latency

Posted by hplus0603 on 03 December 2014 - 11:47 AM

There is always delay between the time user A presses a key, and the time that user B on another computer will see that action.
This is because of both processing time on systems, as well as transmission time over the internet.
Newcomers to networking will try to reduce the latency by, for example, sending commands as soon as they are detected rather than as part of the regular game update loop cycle, or by trying to establish peer-to-peer connections to cut out the server in multi-player games.
In the end, such attempts end up making the code more fragile, and doesn't actually solve the problem, because there is an unavoidable delay between users -- the travel time of electric signals in copper between New York and California is significant, even before you add the additional processing overhead of the network infrastructure!

Thus, the art of creating a networked game is to design the game to work well within the limitations.
There are several different ways of doing this. Real-time strategy games will, for example, play a "yes, sir!" acknowledgement animation on the sending client, giving the command packet time to travel to the server and to other players.
Many MMO RPGs and some FPS-es will just accept the latency, and tune the game for a given latency target (200 ms is reasonable here.)
Other games will attempt to forward-predict the location/actions of remote player son the local target, and then somehow "fix up" when they receive information that is counter to the prediction. Some players like this; personally I don't particularly do so, because remote players will be snapping/warping/jumping around in an uneven manner.

The FAQ for the networking and multiplayer forum contains some links to good references on different models. The Source Networking Model document, the Zen of Networked Character Physics document, and the 1,500 Archers on a 28,800 Modem document are good starting points.


#5195804 Issue With Simple Client To Server Chat Program

Posted by hplus0603 on 01 December 2014 - 07:06 PM

The real trouble here is the general challenge of safe multi-threaded programming, and has nothing to do with networking.
Multi-threading is actually hard, and requires not only an understanding of the problems involved, but also a careful and deliberate approach throughout your entire application.
If you want to learn and practice multi-threading, then that's fine! If you just want to write a server that is robust and works fine, I suggest using a single thread, and select() over all open sockets (including the listening socket.)


#5195632 30k concurrent players on a (private) MMO server...is this possible ?

Posted by hplus0603 on 30 November 2014 - 11:59 PM

Here's all the game logic you need:

auto newpos = player.pos + player.vel;
if (!map.blocked(newpos)) player.set_pos(newpos);
map.blocked() is a simple grid or hash table look-up.
player.set_pos() is a variable update and an update of the map -- either hash table delete/insert, or map grid write-write.
There's approximately three cache misses worst case (this includes dereferencing player, which can be pre-fetched if you loop through all players.)
Three cache misses at the time was about a microsecond total. That leaves a frame rate of 33 Hz for 30,000 players, minus whatever overhead for networking.
(My guess is it ran nowhere near 30 Hz on the server, though.)

On modern machines, there's some chance you can keep the map in L3 cache, which means only one cache miss per player -- the actual player record. And, as I said, that could be pre-fetched.

For networking, you'd likely want to use epoll, kevent, or I/O Completion Ports (depending on O/S).

Physical simulation makes for a significantly more CPU hungry implementation, especially if 3D geometry collision is involved.


#5195630 Issue With Simple Client To Server Chat Program

Posted by hplus0603 on 30 November 2014 - 11:48 PM

client[2] is LOCKED in the accept() loop. And if you attempt to change the index of the array through another thread, and a client connects to the server, it still accepts client[2] rather than whatever index you are wanting.


I see -- "client" as in the specific variable in your program.

I don't see how the temp_id variable gets modified at all in the code you posted. It will always have the value 2. Unless the "thread" function takes temp_id by reference. However, because temp_id seems to be globally declared, something outside the loop could affect it. Mutating global state is generally a terrible idea, and is almost never the right choice for threaded code.

The way I would write a similar function would be something like:

void accept_loop() {
    while (true) {
        SOCKET incoming = accept(listensocket, NULL, NULL);
        if (incoming < 0) break;
        lock l(client_list_lock);
        for (auto &ptr : client_list) {
            if (ptr.socket == INVALID_SOCKET) {
                ptr.socket = incoming;
                ptr.thread = thread(ptr); // if you really have to
                goto done;
            }
        }
        std::cerr << "Could not find a slot for incoming client." << std::endl;
        closesocket(incoming);
done:
        ;
    }
}
Although I'd probably use find_if, or more likely just keep a dynamic hash table of clients and create a new record for it.

Also, thread-per-client is an anti-pattern in multi-user games programming. You either want single-thread (and scale on a machine by using multiple processes) or thread-per-subsystem (physics, networking, AI, etc,) or thread-per-CPU (with a work item queue.)

For the single-threaded case, you can just use select() for all the sockets -- including the listening socket.




PARTNERS