12 Replies - 952 Views - Last Post: 12 July 2010 - 08:20 PM

#1 khurram.1987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-July 10

Need Help in creating Text Chat site . . .

Posted 09 July 2010 - 09:01 AM

Hello,

I am creating TextChat site .. on java Servlet .. I want to know the mechanism of identifying each user to forward message updates between each other in that perticular chat room.
whether it i by knowing there ip-adress OR how.

THANKS to all Helpers ....
Is This A Good Question/Topic? 0
  • +

Replies To: Need Help in creating Text Chat site . . .

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10478
  • View blog
  • Posts: 38,841
  • Joined: 27-December 08

Re: Need Help in creating Text Chat site . . .

Posted 09 July 2010 - 09:07 AM

You'll want to use a client-server model here, along with Sockets and network programming. In fact, pbl wrote a neat snippet to demonstrate this. It is called TCP/IP Client and Server.
Was This Post Helpful? 0
  • +
  • -

#3 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: Need Help in creating Text Chat site . . .

Posted 09 July 2010 - 09:07 AM

If sockets aren't an option...you should look into whether or not Session could help you :)
You could also consider setting a cookie that identifies the user and chat room.

-Frinny

This post has been edited by Frinavale: 09 July 2010 - 09:08 AM

Was This Post Helpful? 0
  • +
  • -

#4 khurram.1987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-July 10

Re: Need Help in creating Text Chat site . . .

Posted 09 July 2010 - 04:31 PM

View Postmacosxnerd101, on 09 July 2010 - 08:07 AM, said:

You'll want to use a client-server model here, along with Sockets and network programming. In fact, pbl wrote a neat snippet to demonstrate this. It is called TCP/IP Client and Server.


I've recently studied network programming course .... in socket programming ther is problem that it won't work in internet environment ... beacause if we inthis we know the externet ip address of network/client but to reach to client system we have to know his system ip-address. so i this will not work in intenet environment according to my knowledg .. may b there i solution to this.
Was This Post Helpful? 0
  • +
  • -

#5 khurram.1987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-July 10

Re: Need Help in creating Text Chat site . . .

Posted 09 July 2010 - 04:38 PM

View PostFrinavale, on 09 July 2010 - 08:07 AM, said:

If sockets aren't an option...you should look into whether or not Session could help you :)
You could also consider setting a cookie that identifies the user and chat room.

-Frinny


lets discuss your idea .... :rolleyes:
i think i m right that sessions are at user end ... i mean at user's/client PC .... so one way to identify is that i send message update to all clients with some checking variable ... and at user end it first check from cookies the type of user ... if this msg if for his/her then displa to user otherwise discard it.

But i think this is not an efficient way to do this .... i want that message is sent from to just only required person' not to any extra.

<sorry my english may not that much goog ... but i think understandable :rolleyes: >
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10478
  • View blog
  • Posts: 38,841
  • Joined: 27-December 08

Re: Need Help in creating Text Chat site . . .

Posted 09 July 2010 - 04:45 PM

If you use a database, you can have columns SENDER and RECIPIENT. So when a user refreshes the screen, display all messages where they are either the SENDER or RECIPIENT, ordered by timestamp ascending. This makes it much easier than managing cookies or session variables.
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Need Help in creating Text Chat site . . .

Posted 09 July 2010 - 04:50 PM

View Postkhurram.1987, on 09 July 2010 - 02:38 PM, said:

i think i m right that sessions are at user end ... i mean at user's/client PC ....


You're thinking of cookies, sessions are on the server the site is being served from and not on the client machine
Was This Post Helpful? 0
  • +
  • -

#8 khurram.1987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-July 10

Re: Need Help in creating Text Chat site . . .

Posted 10 July 2010 - 08:45 AM

View Postmacosxnerd101, on 09 July 2010 - 03:45 PM, said:

If you use a database, you can have columns SENDER and RECIPIENT. So when a user refreshes the screen, display all messages where they are either the SENDER or RECIPIENT, ordered by timestamp ascending. This makes it much easier than managing cookies or session variables.



U mean when user generate query to server for update messages then server will response and send all messages to user. yes it's quite easy way ... but i want that server sends update automatically, not on request.
Was This Post Helpful? 0
  • +
  • -

#9 khurram.1987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-July 10

Re: Need Help in creating Text Chat site . . .

Posted 10 July 2010 - 09:16 AM

View PostPsychoCoder, on 09 July 2010 - 03:50 PM, said:

View Postkhurram.1987, on 09 July 2010 - 02:38 PM, said:

i think i m right that sessions are at user end ... i mean at user's/client PC ....


You're thinking of cookies, sessions are on the server the site is being served from and not on the client machine


Thanks you very much .... plz some more help .. i think you lead me to the solution.

Ok Now i understand .. let suppose i use session for it to keep recored of users in meeting ... e.g. there ID<PrimaryKey>, userType, etc ... and use this to identify user right ... but again question is that from this recored which thing is acting as to identify user destination(that where to send data of this XYZ-user) e.g. whether i use IP-Address respective to each user in this DB to identify them or any thing else ... !!

I MEANS IN SESSIONS WHICH RECORD IS ACTING AS DESTINATION POINT OF ANY USER ??

In my mind this question is like this,
I have craeted chating page, And there are offcours many users that use this page at same time like there are many instances of this page. Now when server sends update to user's then how it know that which page is which user. (may be my logic is also wrong to do this)

This post has been edited by khurram.1987: 10 July 2010 - 09:18 AM

Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10478
  • View blog
  • Posts: 38,841
  • Joined: 27-December 08

Re: Need Help in creating Text Chat site . . .

Posted 10 July 2010 - 10:07 AM

View Postkhurram.1987, on 10 July 2010 - 11:45 AM, said:

View Postmacosxnerd101, on 09 July 2010 - 03:45 PM, said:

If you use a database, you can have columns SENDER and RECIPIENT. So when a user refreshes the screen, display all messages where they are either the SENDER or RECIPIENT, ordered by timestamp ascending. This makes it much easier than managing cookies or session variables.



U mean when user generate query to server for update messages then server will response and send all messages to user. yes it's quite easy way ... but i want that server sends update automatically, not on request.

I think you can use something like AJAX polling to force a refresh, which will cause query, and therefore an update.


Quote

Ok Now i understand .. let suppose i use session for it to keep recored of users in meeting ... e.g. there ID<PrimaryKey>, userType, etc ... and use this to identify user right ... but again question is that from this recored which thing is acting as to identify user destination(that where to send data of this XYZ-user) e.g. whether i use IP-Address respective to each user in this DB to identify them or any thing else ... !!

I think you need to determine a couple things here- which users are online, and what chatrooms they are a part of. So start with your database design. You obviously need a users table, a users_online table, and a chatroom table. If you set up users as the FK in the chatroom table, with ID as the PK, it should just be a matter of querying and joining.

As for the destination part, this is more abstracted in many conventional web languages. You don't need to know the IP address or where to send the messages if you are using something like PHP. If you are using a Java Client/Server model, for example, then you may need more information. I guess the next question is- what language do you want to use?

This post has been edited by macosxnerd101: 10 July 2010 - 10:08 AM

Was This Post Helpful? 0
  • +
  • -

#11 khurram.1987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-July 10

Re: Need Help in creating Text Chat site . . .

Posted 12 July 2010 - 03:13 AM

View Postmacosxnerd101, on 10 July 2010 - 09:07 AM, said:

View Postkhurram.1987, on 10 July 2010 - 11:45 AM, said:

View Postmacosxnerd101, on 09 July 2010 - 03:45 PM, said:

If you use a database, you can have columns SENDER and RECIPIENT. So when a user refreshes the screen, display all messages where they are either the SENDER or RECIPIENT, ordered by timestamp ascending. This makes it much easier than managing cookies or session variables.



U mean when user generate query to server for update messages then server will response and send all messages to user. yes it's quite easy way ... but i want that server sends update automatically, not on request.

I think you can use something like AJAX polling to force a refresh, which will cause query, and therefore an update.


Quote

Ok Now i understand .. let suppose i use session for it to keep recored of users in meeting ... e.g. there ID<PrimaryKey>, userType, etc ... and use this to identify user right ... but again question is that from this recored which thing is acting as to identify user destination(that where to send data of this XYZ-user) e.g. whether i use IP-Address respective to each user in this DB to identify them or any thing else ... !!

I think you need to determine a couple things here- which users are online, and what chatrooms they are a part of. So start with your database design. You obviously need a users table, a users_online table, and a chatroom table. If you set up users as the FK in the chatroom table, with ID as the PK, it should just be a matter of querying and joining.

As for the destination part, this is more abstracted in many conventional web languages. You don't need to know the IP address or where to send the messages if you are using something like PHP. If you are using a Java Client/Server model, for example, then you may need more information. I guess the next question is- what language do you want to use?


THANKS

I use Java Servlet for back end i means for core functionality and JSP for front end such that form/user side.
Was This Post Helpful? 0
  • +
  • -

#12 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: Need Help in creating Text Chat site . . .

Posted 12 July 2010 - 08:17 AM

View Postkhurram.1987, on 10 July 2010 - 03:16 PM, said:

View PostPsychoCoder, on 09 July 2010 - 03:50 PM, said:

View Postkhurram.1987, on 09 July 2010 - 02:38 PM, said:

i think i m right that sessions are at user end ... i mean at user's/client PC ....


You're thinking of cookies, sessions are on the server the site is being served from and not on the client machine


I'm just going to elaborate a little on PsychoCoder's answer...

Session exists on the server. It is a place where you can store information while the user is actively using you website. It is available to all pages within your website so it is an excellent way to pass data between web pages as well as a being a great way to retain (persist) data between requests to the web page.

Session exists on the web server, but it needs a way to associate the user's web browser with the user's Session. Some sort of session identifier is given to the user's browser. Typically this identifier is stored as a cookie but I have seen solutions that use cookieless session identifiers by storing the identifier in the URL/QueryString. Using cookieless session is not advisable in most situations because if a user were to copy the URL and pass it on to another person, the other person will be able to access the first person's session.

View Postkhurram.1987, on 10 July 2010 - 03:16 PM, said:

Ok Now i understand .. let suppose i use session for it to keep recored of users in meeting ... e.g. there ID<PrimaryKey>, userType, etc ... and use this to identify user right ... but again question is that from this recored which thing is acting as to identify user destination(that where to send data of this XYZ-user) e.g. whether i use IP-Address respective to each user in this DB to identify them or any thing else ... !!

I MEANS IN SESSIONS WHICH RECORD IS ACTING AS DESTINATION POINT OF ANY USER ??


You should probably create a class that represents the user.

This class will have members like the user-id, user-type, current-chat-room-id, last connection date/time. When the user logs in you will create an instance of this class and store it in session. You will retrieve this object from session every time the browser that the user is using sends a request to your website. This way you can tell who the user is, what type of user they are, what chat room they are currently connected to, when the user last connected to the web page etc.

As for the chat itself...well you need a way for users to connect to a "chat" and to retrieve information from the "chat" when it is available. Therefore, you will probably want a Chat class to manage a chat as well. The chat is going to have to store data somewhere in order for people to see what was said. You could store it in a database, or a text file, or an XML file...or if you don't need to keep a history of the chat you could just have the conversation exist in memory (session......) Just don't let the conversation grow too much or you could run into issues (so you'll have to delete old messages to make room for new messages). It's probably easier to use a file instead of memory :)

View Postkhurram.1987, on 10 July 2010 - 03:16 PM, said:

In my mind this question is like this,
I have created chatting page, And there are of course many users that use this page at same time like there are many instances of this page. Now when server sends update to user's then how it know that which page is which user. (may be my logic is also wrong to do this)


The server cannot send information to the user's browser unless the user's browser is connected to the server. The browser does not maintain a connection at all times.

Websites operate in a disconnected environment:
  • the web browser sends a request to the server (connects to the server),
  • the server does some processing and sends a response to the browser
  • the browser disconnects from the server


You cannot send information to the web browser if the web browser does not first ask for the information.

This is why the usage of sockets was mentioned earlier in the thread...sockets allow you to "push" data to the connected client when the data is available; however, implementing a server-push application can get complicated especially when you are using a web browser...these types of applications would require a client-application, that runs in the web browser, be developed using a language that can use sockets. Some languages that let you implement an application that runs in the web browser are Flash, Silverlight, and probably a Java application that can run in the web browser: an applet (I thought these were being phased out though...it's been a long time since I've used Java) Right now HTML, which is what your website is being built with, does not have sockets available. This is why you, in order to implement a server push application, you would need to develop an application that runs within the browser instead of a website. HTML 5 is supposed to include sockets... but it's still in the mix.

So, since you aren't going to use sockets, you need to add a feature to the web page that will cause it to "poll" for data periodically. This might not be very clear so I'll reword it: you need to add a feature that will cause to page to send a request to the server to get any updated chat data. This feature will probably be a Javascript "timer" of some sort that submits the page to the server every so often to check for new data.

-Frinny

This post has been edited by Frinavale: 13 July 2010 - 06:18 AM

Was This Post Helpful? 0
  • +
  • -

#13 khurram.1987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-July 10

Re: Need Help in creating Text Chat site . . .

Posted 12 July 2010 - 08:20 PM

THANKS TO ALL FOR HELPING ME.
NOW ITS MUCH CLEAR IN MIND.
THANKS AGAIN :bigsmile:

This post has been edited by khurram.1987: 12 July 2010 - 08:22 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1