How to encapsulate this ?


 
Thread Tools Search this Thread
Top Forums Programming How to encapsulate this ?
# 1  
Old 11-14-2006
How to encapsulate this ?

Hello !

I have a pretty question.I am working on a client-server chat aplication for Linux shell's.

When a user connect , is receives a window for the username . It has to enter the username, which will be used for future chat and private message ( + other option's ). I'm using socket's for network connection.

The point is , after a user is connect to server socket , the user has to enter a username . The problem here comes like that. Where does the chat server knew , if the username string is an ordinary string , used for chat , or the username string itself ?

I figure to do , some easy encaspulation.When the client connect , and receive username window , the username string is encapsulated with , let's say "***" at the end .

Let's say user !_30 is connected . First the client sends "!_30***" to server , the server dencapsulate those 3 '***' , and knows client username.

The problem here is that , when a user accidentaly send's "***" in main chat , whole sistem is doomed . The server sees "***" at the end .. of ( nothing ) and think's a new user is connected to the server.

How can I make this encapsulation/dencapsulation , transparent to send proces , not altering the string , and be doomed like up ..?

Any idea's , raw socket's ? Because the idea I mention is the only one that came , in that moment in my head .


Any ideas , is apreciate ! Cheer's ! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question
Net::HTTPServer::Session(3pm)				User Contributed Perl Documentation			     Net::HTTPServer::Session(3pm)

NAME
Net::HTTPServer::Session - HTTP server side client session SYNOPSIS
Net::HTTPServer::Session handles server side client sessions DESCRIPTION
Net::HTTPServer::Session provides a server side data store for client specific sessions. It uses a cookie stored on the browser to tell the server which session to restore to the user. This is modelled after the PHP session concept. The session is valid for 4 hours from the last time the cookie was sent. EXAMPLES
sub pageHandler { my $request = shift; my $session = $request->Session(); my $response = $request->Response(); # Logout $session->Destroy() if $request->Env("logout"); $response->Print("<html><head><title>Hi there</title></head><body>"); # If the user specified a username on the URL, then save it. if ($request->Env("username")) { $session->Set("username",$request->Env("username")); } # If there is a saved username, then use it. if ($session->Get("username")) { $response->Print("Hello, ",$session->Get("username"),"!"); } else { $response->Print("Hello, stranger!"); } $response->Print("</body></html>"); return $response; } The above would behave as follows: http://server/page - Hello, stranger! http://server/page?username=Bob - Hello, Bob! http://server/page - Hello, Bob! http://server/page?username=Fred - Hello, Fred! http://server/page - Hello, Fred! http://server/page?logout=1 - Hello, stranger! http://server/page - Hello, stranger! METHODS
Delete(var) Delete the specified variable from the session. Destroy() Destroy the session. The server side data is deleted and the cookie will be expired. Exists(var) Returns if the specified variable exists in the sesion. Get(var) Return the value of the specified variable from the session if it exists, undef otherwise. Set(var,value) Store the specified value (scalar or reference to any Perl data structure) in the session. AUTHOR
Ryan Eatmon COPYRIGHT
Copyright (c) 2003-2005 Ryan Eatmon <reatmon@mail.com>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-03-03 Net::HTTPServer::Session(3pm)