Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Dec 09, 2018 10:03 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 52 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Thu Nov 08, 2012 11:13 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
timhare wrote:
We've drifted through a lot of different scenarios here. Thom basically said, "RemoteAddress isn't necessarily unique


Well he more specifically said

Thom McGrath wrote:
IP Addresses are not unique.


For additional note, if you are concerned about what Thom said then may want to grab the router MACaddress to differentiate between routers/hardware.

I don't think that's necessary but whatever.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Fri Nov 09, 2012 1:00 am 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
J.Sh3ppard wrote:
Well he more specifically said
Thom McGrath wrote:
IP Addresses are not unique.

And I stand by that. They are unique to a subnet, but that's not unique enough.

Like a home address, you can only achieve uniqueness if you have the entire picture. You can have a 123 Fake St in two cities. You could even have the street address and city in different states. Yeah, it's rare, in fact there may be no instances of such an occurrence. But regardless, you need every piece to be certain the address is unique.

IP addresses are no different. And obtaining all the details can be problematic. You can have computers behind two layers of routers. You can have computers on different WAN addresses connected to the same proxy and who have the same LAN address. There are just way too many variables to account for. And even if you do have all the details, that still doesn't change the fact that it won't help you determine uniqueness between two instances on the same computer. Wether or not this is an issue depends on your application.

Because even if you use only a username, and a message needs to get between two sockets for the same user, the server won't be able to tell the difference between the sender and the recipient. That's why after writing dozens of servers/protocols, I recommend a random identifier. Then I can send a message from thom@1234 to thom@4321 and the server will know precisely what to do no matter what. Yes, there are other ways, but this method is very reliable and easy to implement.

And this has nothing to do with stateless vs persistent connections. Although stateless connections are even more susceptible to problems by using the IP address as an identifier. Feedback had that problem for a while.

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Fri Nov 09, 2012 11:30 am 
Offline
User avatar

Joined: Fri Oct 28, 2005 7:05 am
Posts: 565
Location: Emsworth, UK
The easy answer is. With TCP, it's the combination of IP and Port which identifies a session endpoint (application instance) as being unique.

When two application instances from the same PC connect to the same server, the server can identify each session by combining the source IP and source port. NAT routers in the path may alter the IP and port numbers but must maintain the mapping and so the return route, until the session expires.

Unfortunately there is no way to ascertain the remote port with RB natively. I have a function to do it across platforms somewhere but in most cases, it is sufficient to add a simple ID property to the Socket class and increment it each time a socket is created.

HTTP is a transaction based protocol. New sessions can be created for each transaction and quicker than any single session expires. Hence the need for GUIDs at the application layer, to maintain a single session across multiple transactions.

_________________
Yes it's me in the avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Sat Nov 10, 2012 9:05 am 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
Hi All

Firstly thanks for all your input...

I can see throughout the forum that this topic has come up time and time again yet nobody has ever managed to offer a working proof of concept example project not even based upon the default install ServerSocketServer/ServerSocketClient demo applications which almost suggests that it is NOT that simple to accomplish in RB.

Surely the development team at realstudio would have included something already demonstrating how to reference and communicate with a particular connected client socket as part of the standard product demo projects.

:roll:

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Sat Nov 10, 2012 9:16 am 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
It is actually quite simple, and I even provided some sample code here in the forum. All you need to do is add some sort of unique value to each socket, then loop through the array returned by ActiveConnections.

We can't make demos for every scenario. Certain things must be excersizes left to the user. You are very close in your original post, and I told you how to fix it. I could write you an example in a few minutes, but to be honest, I'd rather you learn it yourself.

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Sat Nov 10, 2012 9:47 am 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
"A Picture paint's a thousand words" :?

My son in learning to be a car mechanic. Without visual instruction and guidance from time to time he would certainly not have the now how in order to assemble a car engine from a bunch of parts.

Seeing a project loaded into the IDE IMO is so much more helpful for a beginner to learn and to better understand the basics of RB programming.

Being honest some of the language reference material in particular ServerSocket.ActiveConnections() realistically for a beginner is not friendly at all...

:roll:

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Sat Nov 10, 2012 2:31 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Perhaps it's not really beginner material.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Sat Nov 10, 2012 6:09 pm 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
:lol:

Great answer Timhare BTW I didn't expect anything worthy or constructive.

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 3:52 pm 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
:D A big thank you to Thom McGrath. I will admit it did take me several hours to work it out but through perseverance
all is working

Thanks Thom

:wink:

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 5:14 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
Thom McGrath wrote:
Done. Every connection now has a unique ID.


Nope. What your code generates is not a unique ID.

Thom McGrath wrote:
Well, the odds of collision are about as good as being killed in a supernova. But it's still dramatically more reliable than trying to build an identifier from client information.


I wrote build the unique ID from the client information plus the unique UserID which is server based. A properly designed login system won't allow duplicate UserIDs that makes it truly unique.

You can't really know the true odds of a collision using the RS random function. Most computer randomization functions do not work very well and they certainly are not truly random. I don't know what RS is using under the hood, but it may not be a very good randomizer. That significantly increases the odds of collision.

I can absolutely say that using your suggested technique there will be collision and duplicate IDs generated. It is a matter of time and how many IDs have been generated.

What I wrote, using a unique user ID which is truly unique as the developer did not allow any duplicate IDs along with the IP addresses which are most often unique themselves provides a more unique ID than what you've suggested.

Thom McGrath wrote:
Then I can send a message from thom@1234 to thom@4321 and the server will know precisely what to do no matter what.


Are you suggesting allowing different users to have the same UserID (Thom) ?

If the answer is no, then you're using my system. The UserID IS unique. Since the username IS unique you don't have to waste time generating a fake number ID for the already unique user.

If the answer is yes :
Why would you ever want to allow different users to have the same exact UserID login name? That's creating problems. Think about it, can you name even two login systems where different users can have the same exact UserID name? Probably not. I can't.
At login time how would differentiate between them? By password? Why?
You can easily allow the unique UserID a nickname which can collide with any other user's nickname since the nickname doesn't really matter, though I personally would not want to.

Maybe I've forgotten the details of what I used to do exactly but I thought I remembered correctly.

Using a unique UserID login name with the IP info is better than some faked up random number which will be repeated and collided with. Using the IP for security is also a good thing to do. For example prevent flood attacks, seeing if the same IP logs into multiple accounts, tracking who broke into who's account, etc.
Random number ID's don't do any of that.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 5:31 pm 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
J.Sh3ppard wrote:
Are you suggesting allowing different users to have the same UserID (Thom) ?

How many times to I have to say "two (or more) connections from the same machine"? No, a username should never be duplicated. And if you want your sever to boot a user who has signed in more than once - like Steam - then your solution works. If you want your server to allow multiple sign in - like AIM - then you'll need to use something other than the username.

And, the code I posted is a quick-and-dirty implementation. If you need more certainty that you won't be hit by a supernova, use a GUUID implementation, that's what they are for.

But this discussion has been avoiding my *entire* point. Your SERVER can issue the ids without caring about what is on the other end. The instant a socket receives a connection, generate, store, and transmit the ID. When the socket disconnects, dispose of the ID. Then just mandate in your protocol that all messages must include that ID, and you're golden. Even if somebody sniffs that ID and tries to use it as their own, it won't matter, as your server will reject it since it'll be a different connection.

How you implement authentication is a totally different discussion. The user wanted to identify another socket. My advice was to not use the IP address, since they're not universally unique. It's a typical gotcha for somebody new to networking.

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 5:56 pm 
Offline

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

And, the code I posted is a quick-and-dirty implementation. If you need more certainty that you won't be hit by a supernova, use a GUUID implementation, that's what they are for.


That's kinda my point. You're arguing against my unique UserID and IP identifier but what you've suggested is less unique.

Thom McGrath wrote:
But this discussion has been avoiding my *entire* point. Your SERVER can issue the ids without caring about what is on the other end. The instant a socket receives a connection, generate, store, and transmit the ID. When the socket disconnects, dispose of the ID.


But you're not getting my point. With a properly designed login system which the user is trying to develop you already have a unique user ID in the unique username and IP address combination or even just the unique username. Why make the server work harder using more CPU to generate a fake number ID then dispose of it when you've already got your unique UserID and more that doesn't require those CPU wasteful steps?

Thom McGrath wrote:
Then just mandate in your protocol that all messages must include that ID, and you're golden. Even if somebody sniffs that ID and tries to use it as their own, it won't matter, as your server will reject it since it'll be a different connection.


Same thing I'm suggesting except you don't need to waste time generating fake numbers and the disposing of them.

Thom McGrath wrote:
How you implement authentication is a totally different discussion.


But it isn't. It's tied together, the user is creating a server /client online architecture.
Using my way seems to be more efficient for the server and easier to do for the developer. You thought it was wham bam done in seconds, it took the OP hours and he's still left with a non-unique ID.

Oh well. Did the cows come home yet? :)


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 6:04 pm 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
Thom McGrath wrote:
How many times to I have to say "two (or more) connections from the same machine"?

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 6:25 pm 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
Dim r as New Random
ID =Str(r.InRange(2222,3333))

AND THE MACHINE HOSTNAME I THINK THAT IS UNIQUE ENOUGH....

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 6:35 pm 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
p0wn3d wrote:
Dim r as New Random
ID =Str(r.InRange(2222,3333))

AND THE MACHINE HOSTNAME I THINK THAT IS UNIQUE ENOUGH....

Probably. The risk of collision is very high (mathematically) under this scenario, but practically, should be fine. You basically need to have two clients on the same network randomly choose one of 1,111 numbers to cause a problem. It's within the range of possibility. If you want to use this system, I'd suggest making the pool a little larger. Perhaps 1000 - 9999?

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 52 posts ]  Go to page Previous  1, 2, 3, 4  Next

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