c++ - Strategy for simple yet effective UDP server for gaming (and other tasks) -
i'm trying implment thought of simple yet pretty effective multithreaded server working on udp. main goal gaming(-like) applications, if used in other purposes too.
i want utilize api/technologies etc
std::thread multithreading, since part of c++ standard, should future-proof , far seen it's both simple , works c++. bsdsock (linux) & winsock2 (windows). create 1 abstract class called socket , each platform (linux - bsd, windows - winsock) create derived class implementing native api. utilize api provided base of operations class socket, not native/platform api. allow me utilize 1 code whole server/client module , if want alter platform i'd have switch class type of socket , thats it.as strategy of server-client comunication thought of this: each programm has 2 sockets - 1 listens on specified port , 1 used send info server/other clients. both sockets run on different threads can both read , send info @ same time (sort of), way waiting info won't ruin performance. there 1 main server, , other clients connect straight server. clients send info , recieve info straight server.
now have question:
is wise utilize std::thread? heard it's on linux, not on windows. pthreads much better? any other interesting ideas making 1 code many platforms (mainly linux&windows)? or mine enough? any other ideas or tips strategy how server/client work? wrote simple network apps, didn't need strategy, i'm not sure if it's best simple ideas. how should send info client server (and server client)? dont want flood network , create server load 100%?also: should work nice 2-4 players @ same time, don't plan utilize more @ moment.
intuitively, multi-threading purposes linux + pthread nice combination. vast number of mission critical systems running on combination. however, when come std::thread, having platform dependent nature nice have feature. certainly, if bad smells in windows dialect, ms right them future. but, if you, select linux + std::thread combination. selection of linux on windows different topic , no need comment here (with respect server development perspective). std::thread provides nice set of feature,yet having powerfulness of pthreads.
regarding udp, have both pros , cons. but, i'd if going open sever public, have think network firewalls well. if can address inherent transport layer issues of udp (packet re-ordering, lost packet recovery), udp server lite weighted in of cases.
it depends on game decide how need send messages. can't comment it.
moreover, pay attending security on info communication more seriously. sooner or later sever hacked. matter of fact of time.
c++ multithreading sockets client-side
No comments:
Post a Comment