Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programmers' lounge. (Programming-related discussions only)
New Posts  All Forums:Forum Nav:

Programmers' lounge. (Programming-related discussions only) - Page 113

post #1121 of 1124
Quote:
Originally Posted by alcal View Post

Ok thanks for the clarification. You'll probably want to set it up so that your when your listener connects and sets up the connection, you spawn a new listener in another thread to handle the subsequent connection. You can't talk to more than one device on a single connection (as you stated) so you'll need to always have a listener ready to offer a new connection to each device.

Once you do that, you'll have some sort of threadpool of active connections, and I think that what I said earlier about identifying them however you want should work fine. Depending on how you have things set up/what you're doing, you might want to use a thread-safe data structure of some sort to pass information between threads, though Android has policies against blocking operations in the main thread (which most thread safe data structures need to be able to do to ensure that they are indeed thread safe) so I'm not 100% sure what your options are there.

When I did some googling, I came across using hashtable to make identifier for each connections, someone else also mentioned GUID. I mean easier said than do when you say "identifying them however you want" I mean someone mentioned using device ID + timestamp but how would I implement that into the socket?

would it be something like...

socket.getoutputstream(randomgenerateID);
? idk
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
post #1122 of 1124
Quote:
Originally Posted by andyroo89 View Post

When I did some googling, I came across using hashtable to make identifier for each connections, someone else also mentioned GUID. I mean easier said than do when you say "identifying them however you want" I mean someone mentioned using device ID + timestamp but how would I implement that into the socket?

would it be something like...

socket.getoutputstream(randomgenerateID);
? idk

um socket.getOutputStream() takes no parameters as I recall so that wouldn't be possible. There is probably a better way to do this, but here is what I might do:
On initial connection:
Server generates a random ID for new device. It tells the device its ID over the connection (i.e. you write a message to the outputstrem from the server to the device informing the device of its ID).

On subsequent connections:
Device sends a message (again by writing to the outputstream of its socket) to the server saying effectively "Hi, I'm device ########"

You will need to design a simple handshake procedure for this, and possibly something resembling a protocol for the rest of the communications between client and server. Pretty much all talking between devices will be done by writing a specially formatted message to the outputstream, waiting for a reply and then responding depending on what the reply contains. None of this has to do with the socket object itself once the connection is established.

Edit: once again, how you actually name the devices doesn't really matter so long as you are sure it will avoid collisions. You could use random numbers assigned by the server, and then make sure you aren't reusing them by linearly searching a list of used numbers [this is obviously easy to implement] or you could use GUIDs or timestamps or whatever else you think suits the needs of your app.

Edit 2: if security is a concern, most of this advice is terrible and you'll have a whole new set of problems.
Edited by alcal - Yesterday at 7:08 pm
Fractal Fury
(9 items)
 
TJ08-e Reborn!
(12 items)
 
CPUMotherboardGraphicsRAM
i7-5930k ASRock X99m Killer AMD Radeon Fury X G-Skill Ripjaws 4 32Gb 
Hard DriveCoolingKeyboardPower
Kingston Hyper-X Predator M.2 Corsair H100i GTX Ducky Shine III (MX Blue) EVGA Supernova 750 G2 
Case
Fractal Node 804 
  hide details  
Reply
Fractal Fury
(9 items)
 
TJ08-e Reborn!
(12 items)
 
CPUMotherboardGraphicsRAM
i7-5930k ASRock X99m Killer AMD Radeon Fury X G-Skill Ripjaws 4 32Gb 
Hard DriveCoolingKeyboardPower
Kingston Hyper-X Predator M.2 Corsair H100i GTX Ducky Shine III (MX Blue) EVGA Supernova 750 G2 
Case
Fractal Node 804 
  hide details  
Reply
post #1123 of 1124
Quote:
Originally Posted by alcal View Post

um socket.getOutputStream() takes no parameters as I recall so that wouldn't be possible. There is probably a better way to do this, but here is what I might do:
On initial connection:
Server generates a random ID for new device. It tells the device its ID over the connection (i.e. you write a message to the outputstrem from the server to the device informing the device of its ID).

On subsequent connections:
Device sends a message (again by writing to the outputstream of its socket) to the server saying effectively "Hi, I'm device ########"

You will need to design a simple handshake procedure for this, and possibly something resembling a protocol for the rest of the communications between client and server. Pretty much all talking between devices will be done by writing a specially formatted message to the outputstream, waiting for a reply and then responding depending on what the reply contains. None of this has to do with the socket object itself once the connection is established.

Edit: once again, how you actually name the devices doesn't really matter so long as you are sure it will avoid collisions. You could use random numbers assigned by the server, and then make sure you aren't reusing them by linearly searching a list of used numbers [this is obviously easy to implement] or you could use GUIDs or timestamps or whatever else you think suits the needs of your app.

Edit 2: if security is a concern, most of this advice is terrible and you'll have a whole new set of problems.

I figured it didn't. hmm idk this may take a couple of days/weeks to do since I am still trying to figure this out.
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
post #1124 of 1124
Quote:
Originally Posted by andyroo89 View Post

I figured it didn't. hmm idk this may take a couple of days/weeks to do since I am still trying to figure this out.

I'm still somewhat new to Android myself and am always looking to learn, so if you want to talk about something in more detail /want me to actually research my suggestions before I make them, feel free to PM me. In principle though, this shouldn't be too difficult. You just need to come up with a simple, clear way to format messages and write yourself a document establishing the protocol so you can follow it clearly when writing the client and serverside implementations.

Anyways, yeah feel free to PM me as you work through it.
Fractal Fury
(9 items)
 
TJ08-e Reborn!
(12 items)
 
CPUMotherboardGraphicsRAM
i7-5930k ASRock X99m Killer AMD Radeon Fury X G-Skill Ripjaws 4 32Gb 
Hard DriveCoolingKeyboardPower
Kingston Hyper-X Predator M.2 Corsair H100i GTX Ducky Shine III (MX Blue) EVGA Supernova 750 G2 
Case
Fractal Node 804 
  hide details  
Reply
Fractal Fury
(9 items)
 
TJ08-e Reborn!
(12 items)
 
CPUMotherboardGraphicsRAM
i7-5930k ASRock X99m Killer AMD Radeon Fury X G-Skill Ripjaws 4 32Gb 
Hard DriveCoolingKeyboardPower
Kingston Hyper-X Predator M.2 Corsair H100i GTX Ducky Shine III (MX Blue) EVGA Supernova 750 G2 
Case
Fractal Node 804 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programmers' lounge. (Programming-related discussions only)