Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Aug 19, 2018 3:02 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Socket to make Chatting application !!
PostPosted: Fri Sep 14, 2012 10:45 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
Hi,

I made a Chatting application using udp socket. The example project "Simple Chat" comes with RealStudio help me lot to start with. I made almost similar but added few extra feature.

What I have found, sometimes the message did not reach the destination. Later I read and came to know UDP is not guaranteed to send the message to it's destination.

So, my question, What socket should i use if i want to make serious chatting application?

For now it is for same network only. What should i do if i want to send message between two app connected to internet?

Thank you.

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Fri Sep 14, 2012 10:51 am 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
amitavak wrote:
Hi,

I made a Chatting application using udp socket. The example project "Simple Chat" comes with RealStudio help me lot to start with. I made almost similar but added few extra feature.

What I have found, sometimes the message did not reach the destination. Later I read and came to know UDP is not guaranteed to send the message to it's destination.

So, my question, What socket should i use if i want to make serious chatting application?

For now it is for same network only. What should i do if i want to send message between two app connected to internet?

Thank you.


Do not use UDP for chat.


Use the TCPsocket for chat.

If you search the forum you will probably find a lot written about this.


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Fri Sep 14, 2012 11:10 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Quote:
For now it is for same network only. What should i do if i want to send message between two app connected to internet?


A bit more complicated.... TCP is required for sure. But what you are describing is PEER to PEER communication.

SENDER  ==> RECIEVER


But the issue is you have TWO IP addresses involved (at each end). You have the senders local LAN IP address (the one you are using now)... AND their public Internet IP address (which is how they are seen by the rest of the world).... The same goes for the Reciever


Most chatrooms (Yahoo, MSN etc) use a central server. The senders message goes to the SERVER, which in turn rebroadcasts it to the Reciever.... it is NOT a peer to peer chat

SENDER ==>  SERVER ==> RECIEVER

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Fri Sep 14, 2012 12:35 pm 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
DaveS wrote:
Most chatrooms (Yahoo, MSN etc) use a central server. The senders message goes to the SERVER, which in turn rebroadcasts it to the Reciever.... it is NOT a peer to peer chat

SENDER ==> SERVER ==> RECIEVER


What type of server it is? a webserver?

Suppose i also made a webapplication. Then I will use HTTPSocket to send sender message to send to that web application(message will also contain the receiver address). But how do i send the message to that receiver from the server?

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Fri Sep 14, 2012 12:53 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
amitavak wrote:
What type of server it is? a webserver?


It is not a webserver in the sense that it is serving web pages.
Chat servers are typically only serving the chat data and it's metadata.

It is possible to make a chat server using something like php but it's not capable of having a persistent connection so using php for a chat server isn't the desired route. If you've got a VPS or your own dedicated server and an RS license, you should probably use RS to make your chat server.

Look at the serversocket example.

amitavak wrote:
But how do i send the message to that receiver from the server?


You would normally keep all connections in an array each having a unique ID.
Looping through the array allows you to send messages to individuals or do a 'shout' to all.

You really should search the forum and look at the examples before asking these questions. I am pretty sure they've been talked about previously.


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Fri Sep 14, 2012 3:29 pm 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
amitavak wrote:
What I have found, sometimes the message did not reach the destination. Later I read and came to know UDP is not guaranteed to send the message to it's destination.


UDP does have advantages, it can greatly improve performance if your chat application is going to allow large file transfer, or live video streaming.

UDP does not offer any error checking and correction (as you discovered), you implement this in to your Application. UDP avoids the overhead of checking and correction at the network interface level, so you need to do this in your code instead.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Sat Sep 15, 2012 1:20 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
Thank you everyone for such a nice discussion.

Now I thinking to make a chat server. I Will have look at the serversocket example. And will also search about chat server.

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Mon Sep 17, 2012 10:51 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
for now i'm thinking to complete the app using UDPSocket only. That way I will learn the UDP well. Later on I made another one using TCPSocket and a Chat Server (if possible).

Now the only problem in the app is "Sign out" from Chat. When user sign out, udp multicast a message in the format "I'm sign out:Username". Then it disconnect itself. close all the chatting windows, show the login windows,....

And when some user receive a sign out message, he check his contact list, if that user listed there, he marked him offline.

This is the flow of sign out functionality.

The problem is, sometimes some user did not receive that sign out message, so that signout user remain online in his contact list.

So can anyone suggest me something, so that I can successfully make a user offline from all the user's contact list, he was added, when a user goes offline?

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Mon Sep 17, 2012 11:02 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Use TCPSocket for that kind of communication. You can't guarantee UDP will be delivered.


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Mon Sep 17, 2012 1:25 pm 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
Actually I tried with implementing TCPSocket for sending "log out" message. But don't know why that also throw error sometimes....may be i'm doing wrong something. ok..let me explain the process.

After login, a "userlist window" appear showing the contact list. In the open event, i wrote

TCPSocketTest.Port = 12346
TCPSocketTest.Lisen

Then in the action event log log out button,

TCPSocketTest.Address = Remote Address
TCPSocketTest.Connect


Then I start a timer. In the action event of that timer i check if the TCPSocketTest is connected then send the logout message. Then in the send complete event of the TCPSocketTest, I close the userlist window and show the login window.

Am i doing it correctly?

I have one confusion also, how do i send that logout message to multiple user means to all online contact in the contact list?

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Mon Sep 17, 2012 1:26 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
amitavak wrote:
for now i'm thinking to complete the app using UDPSocket only.


Why are you trying to force the square into the round hole?

We all told you UDP for chat will cause problems since it is unreliable.

If you don't mine your chats not arriving or possibly arriving in the wrong order, by all means you UDP. Just don't cry to us when your users complain how horrible it is.


amitavak wrote:
Now the only problem in the app is "Sign out" from Chat. When user sign out, udp multicast a message in the format "I'm sign out:Username". Then it disconnect itself. close all the chatting windows, show the login windows,....

And when some user receive a sign out message, he check his contact list, if that user listed there, he marked him offline.

This is the flow of sign out functionality.

The problem is, sometimes some user did not receive that sign out message, so that signout user remain online in his contact list.

So can anyone suggest me something, so that I can successfully make a user offline from all the user's contact list, he was added, when a user goes offline?


Sounds like your UDP chat application is working perfectly to UDP specifications - UNRELIABLE.

DUH.

I am very curious why you've asked for help yet refused our answers?

Each developer here that offered you an almost identical answer has many years of experience.

If you aren't going to follow our advice, then why ask it?


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Tue Sep 18, 2012 5:28 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
Quote:
Hi J.Sh3ppard,

I'm always eager to know the best way to accomplish something. From the discussion, I came to know TCPSocket is the best way to make a chatting app. I made that one using udp for learning purpose.


Now i'm going to replace udp with tcp in that existing chat app. Few thing struck in my mind.

When a user login, udp sends a multicast message say "Someone signed on:username". When some user receive that message, it checks it's contact list if that username is listed there, it marks him as online. At the same time it also store the remote address, the message came from with the corrosponding contact. So that during chat, i can know at which address i need to send the message.

So how can I handle this thing using tcp? How will i send the message to all the user in the same network? Do i really need to make a chat server for that?

Edit: Now sign out functionality works perfectly with TCPSocket(I used TCPSocke to send "sign out" message only). But I need to get some idea about the above question before i move to TCP totally?

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Tue Sep 18, 2012 12:28 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
amitavak wrote:

When a user login, udp sends a multicast message say "Someone signed on:username".

So how can I handle this thing using tcp? How will i send the message to all the user in the same network? Do i really need to make a chat server for that?


You will want to use a server socket.
You will want to handle the socket connections in an array.

To be able to send a message to one or all of the sockets (users) loop through the array send messages to whichever sockets you want.


All of these questions have been answered before on this forum.

Do a search in the network section.


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Mon Sep 24, 2012 2:49 am 
Offline
User avatar

Joined: Fri Oct 28, 2005 7:05 am
Posts: 565
Location: Emsworth, UK
Quote:
I'm always eager to know the best way to accomplish something.


As Friedrich Nietzsche once said. “You have your way. I have my way. As for the right way, the correct way, and the only way, it does not exist.” Sorry, that's a bit cryptic.

Quote:
From the discussion, I came to know TCPSocket is the best way to make a chatting app.
It depends. On a single segment LAN, serving a half dozen users, UDP is a good choice for a simple chat application. UDP starts to get tricky when multiple network segments are introduced and becomes down right difficult when there are multiple physical and logical domains to traverse (The Internet). UDP also has inherent scalability issues. As the number of 'peer' hosts increases linearly, the complexity and overheads of transmission (can) increase logarithmically. Hence UDP is a poor choice for a chat application intended for use across the internet. So poor in fact, you will find ISPs, router and firewall manufacturers, conspiring to prevent it from working.

Quote:
I made that one using udp for learning purpose.
For learning purposes, imagine a private telephone system (PBX). TCP would be a phone call, UDP would be a public address announcement, a NAT router would be the switchboard.

Quote:
So how can I handle this thing using tcp? How will i send the message to all the user in the same network? Do i really need to make a chat server for that?
You can solve your logout problem using UDP. Basically you are looking at an address resolution problem and might solve it by borrowing some concepts from the ARP protocol. Your online hosts could periodically poll each host in their contact list, asking the question, 'Are you online?' or they might send a gratuitous request to all hosts, asking, 'Who is online?' Using the replies to update their own contact list. However, if you were to model the data flow between hosts, you may notice how an increase in the number of hosts, causes a disproportionate increase in the bandwidth consumed by all hosts. There is a tipping point here, where the number of hosts will cause a network segment to become (physically) flooded with your address resolution traffic. The additional complexity of managing persistent TCP connections, with a centralised 'chat' server, becomes 'worth it' well before you reach the tipping point.

Of course, if you ever hope to use your chat application across The Internet, the difficulty of moving UDP packets between multiple ISPs, across multiple firewalls and routers, is going to make TCP worth it, from the outset.

HTH

_________________
Yes it's me in the avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: Socket to make Chatting application !!
PostPosted: Tue Sep 25, 2012 12:50 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
Quote:
“You have your way. I have my way. As for the right way, the correct way, and the only way, it does not exist.”


I like it. :) Nice speech.

Thank you msssltd. These information is really helpful.

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group