tcp - C# packet structure system -


i working on packet system (udp or tcp, either way fine) came conclusion current (tcp) system awefull.

basicly, i'm sending packet looks this:

string packet = "login_auth;true" ipaddress target = ipaddress.parse(endpoint); // send packet 

when recieve packet in client, use determine packet type:

string[] splitpacket = packet.split(';');  if (splitpacket[0] == "login_auth" && splitpacket[1] == "true")    authlogin(packet); //does stuff loading next screen 

but i'm sure there must better way this, because of thread:

http://social.msdn.microsoft.com/forums/en-us/netfxnetcom/thread/79660898-aeee-4c7b-8cba-6da55767daa1/ (post 2)

i'm wondering if give me push in right direction on should categorize packets in way that's more easy on eye.

thank in advance.

edit: did research, cant find solution problem in wcf. once again, best way create packet structure, , how utilize it?

i don't want recreate protocol, this:

public string sepchar = ";" public static struct loginpacket {     string type;     string username;     string password; }  public void reqlogin() {     lock (_locker)      //need make thread-safe in case     {          loginpacket.type = "login";          loginpacket.username = "username";          loginpacket.password = "password;           sendpacket(loginpacket);     } }  public void sendpacket(string packet) {     // script send packet using struct information } 

i hope that's detailed enough.

i recommend wcf; if not now, decide learn in future. has huge learning curve because covers not you're trying do, many other things.

if want quick-and-dirty solution, use binary serialization. take approach, you'll need define message types in dll shared between client , server. then, remember use form of message framing messages don't munged in transit.

things more complex when consider versioning. you'll want use wcf.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -