Giữ đăng nhập trong client-server java (posted for pekudu)

Joe

Thành viên VIP
21/1/13
2,969
1,311
113
@pekudu,
I don't know what you've done in the past but your registration was marked as a spammer. Only the one who blacklisted your registration can remove your registration from the blacklist.
Joe
______________________________________________________________
This following comment was written by pekudu to my box.

Mình thấy bên PHP có session vậy bên java có cái gì vậy mấy bác :(
Giữ phiên đăng nhập tại server kiểu gì để client chỉ cần đăng nhập 1 lần thôi :)
Và mình muốn hỏi thêm là nếu client open 1 lần thì lần sau click vào biểu tượng sẽ hiển thị frame đó luôn chứ không mở frame mới thì làm thế nào
 

Joe

Thành viên VIP
21/1/13
2,969
1,311
113
To your question
JAVA client-server works like PHP with session. A session is kept open by sockets. As long as 2 communicative sockets stay connected their session remains open. A session depends also on your app, not on PHP or on JAVA.
 
  • Like
Reactions: chuong.dev

chuong.dev

New Member
7/5/14
24
5
3
32
Yup, Joe mentioned above, The Idea of session is to remain an interval of time to connection between Client and server. this idea might is implemented in all of programming languages. but in the situation of Soudu, you have to find out the idea that come from Cookie. Session only keep client's information in an interval time, this information is detected via SessionI_ID. When session expire, this session will be destroy on server . If you only want to log in one time in first, other next times you can access to server without login, Cookie will help u. Let u reach Cookie and Session to implement your app.
 

Joe

Thành viên VIP
21/1/13
2,969
1,311
113
Chuong,
very good. An App decides how it keeps a session. HTTP protocol uses the keyword "Connection: Keep-alive" or "Connection: close" to tell the participants how the session should be implemented and handled (see the last lecture ThreadListener-and-ThreadListening...). For example, when you sign in to Congdongjava you see a little box saying "Giữ đăng nhập". This is the hint for the server to keep the session alive, in order to reduce the load on the server.
 
Sửa lần cuối:
  • Like
Reactions: chuong.dev

chuong.dev

New Member
7/5/14
24
5
3
32
Hi Joe, I think you have a confusing here :"For example, when you sign in to Congdongjava you see a little box saying "Giữ đăng nhập". This is the hint for the server to keep the session alive, in order to reduce the load on the server.". I don't think like you in this case. When we checked the little box "Giữ đăng nhập", this is not the hint for the server keep the session alive. this case will not be resolved by session. this case will use Cookie to solve ^_^. You might know that, Cookie contains some stuff of information and that is stored at Client. So that, when we check "Giữ đăng nhập" box, a cookie will be created to contain the information of log in. Next time accessing to server, client will get this information of log in from cookie and automatically send it to server to validate. Obviously, You can see this case in our web browser . You log in on congdongjava.com and check on "giu dang nhap" box, next time you access the forum without log in again. But if you clear cookie (clear catching of browser), you must sign in again when accessing to the forum, because you cleared the information of sign in in cookie.
 

Joe

Thành viên VIP
21/1/13
2,969
1,311
113
Chuong,
Nope! I didn't. I did understand what you meant. Cookie is used for the only one purpose: To keep the information for the NEXT protocol session. What information does cookie have? Every cookie has an unique "name" (long combination of letters/digits) and an amount of days (Yahoo cookie has in some case an exaggerated amount of more than 10 years). Nothing more and nothing to do with a communication session. With a cookie's unique name the server can save time for e.g. password check or similar. A communication session is always driven and kept by the underlying sockets -regardless of what language. It's the nature of communication. The communication between a browser and CongdongJava.com bases on HTTP protocol and each site (browser, server) keeps its socket open to secure an uninterrupted communication session, NOT the protocol session. This protocol below shows you how Browser and CongdongJava keep keep their protocol session open ("Giữ đăng nhập"). How they keep the sockets open depends fully on their implementation: Socket stack? Socket ArrayList? Or whatever.
Code:
    Resp.Time  Websites
_____________________________
   1382 msec. @congdongjava.com
_____________________________
   RequestHeader
_____________________________
GET /forum/ HTTP/1.1
Host: congdongjava.com
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,vi;q=0.2
Cookie: faceLike=liked; xf_user=24670%2Cf079547d3014ed56f448688fb3e653235ee220b1; xf_session=719383846a62ee57986dcdc8c12de597; countrytabs=0
If-Modified-Since: Sun, 10 Aug 2014 08:07:24 GMT
_____________________________
   ReplyHeader
_____________________________
HTTP/1.1 200 OK
Date: Sun, 10 Aug 2014 08:08:21 GMT
Server: Apache/2.2.15
X-Powered-By: PHP/5.3.3
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-control: private, max-age=0
X-Frame-Options: SAMEORIGIN
Content-Encoding: gzip
Vary: Accept-Encoding
Set-Cookie: xf_user=24670%2Cf079547d3014ed56f448688fb3e653235ee220b1; expires=Tue, 09-Sep-2014 08:08:21 GMT; path=/; httponly
Set-Cookie: xf_session=ef17f075f40730b7d454a2d1cedea3b4; path=/; httponly
Last-Modified: Sun, 10 Aug 2014 08:08:21 GMT
Content-Length: 29911
Connection: close
Content-Type: text/html; charset=UTF-8
_____________________________
As you see, CongdongJava server "smuggles" 2 cookies into my computer:
1) Set-Cookie: xf_user=24670%2Cf079547d3014ed56f448688fb3e653235ee220b1; expires=Tue, 09-Sep-2014 08:08:21 GMT; path=/; httponly
2) Set-Cookie: xf_session=ef17f075f40730b7d454a2d1cedea3b4; path=/; httponly
Each cookie has an unique name, one of them is the Session cookie for the case of HTTP and the other is the userID (you can close and restart your browser and you haven't to re-authenticate yourself thanks to this cookies.). And the attribute "httponly" tells the browser that it could rely on the cookies, when it "comes" back. Hence the reply: "Connection: close". Otherwise the browser has to keep its socket open. What the server does is relies fully on its implementation...as long as the browser sends the correct cookies as it does here:
Cookie: faceLike=liked; xf_user=24670%2Cf079547d3014ed56f448688fb3e653235ee220b1; xf_session=719383846a62ee57986dcdc8c12de597; countrytabs=0

Don't confuse a communication session with a protocol session. One is a technical implementation and the other is an agreement between 2 gentlemen (Browser/CongdongJava server). A technical implement is always obligatory, an agreement is only a courtesy. OK?

BTW, Pekudu asked for the possibility of a JAVA session like a PHP session. And his question is a technical question (language), not a protocolar one (like HTTP or HTML).
 
Sửa lần cuối: