I am in the design stages of an app involving QR codes. It will be a contest where a user sees a QR code and scans it. The first user to scan the QR code is the winner.
Because the contest is on a first come first serve basis I want to make sure that the first user who scans the code is the winner. I have noticed that (at least from what I have read) there are Javascript and C# ways to read QR codes (Is there a JQuery way?).
Which way would be the fastest/fairest/most efficient? Assume that there will be many many people scanning a QR code at once. I want to makes sure that the first guy who scans it is the winner, and not get into issues because his request wasn't processed fast enough.
I guess the real question I would be asking would be this: When there are many users attempting one action on one app, would a client side or server side method work better? Would the differences have an effect like I am worried about? ect.
There are two stages to scanning a QR code.
Capturing the image
Converting the image to text
Step 1 has to be done on the client.
Then it becomes a question of "Client CPU power + time to send the text data" Vs. "Server CPU power (shared between clients) + time to send the image data".
Client CPU power is variable. Bandwidth is variable. Latency is variable. You'll need to provide the server with more CPU power and bandwidth per user if you want the decoding to happen there.
You can, of course, measure the time from when the image was uploaded instead of decoded if you go with the "send the image" approach.
So, in conclusion:
would a client side or server side method work better?
Both will some of the time.
Either way the process of decoding the image will take some time, and that varies depending on the client CPU or the network speed.
Once you have captured the image on the client, you could request a token/timestamp from the server. That will be a small request, so the network speed will not affect it much. Then you can proceed to either decode the image on the client or send i to the server to be decoded.
If two users come in close in time, you know which one captured the image first from their tokens.
On a modern smartphone, detecting and decoding a QR code is something that can happen in under 100ms. I doubt variability in the client-side would produce any meaningful unfairness. But, I certainly think the client-side variability is smaller than the network variability which would come into play when uploading images rather than decoding client side.
Related
I am trying to recreate some features of Spotify in C# using the PostgreSQL database.
The reason is simple, I want to gain more knowledge, and I think this is a good challenge.
But I ran into an obstacle that I've been standing for days. Spotify he doesn't download the music, he does her streaming, plays the music while it's downloaded.
However, I can't do this in C#, I'm using the PostgreSQL database.
I'm well locked in this part, I tried several implementations, but I think I'm not on the right track, and on the internet I imagine I'm looking wrong, otherwise I would have found it.
Do you have any guidance for this streaming process in C#? I've tried to read the large_object bytes from PostgreSQL, but couldn't.
Any suggestions or guides about the process are welcome.
You start by getting the file into the database or its network location into the database, whichever gives you better performance; Then start with creating an implementation of a bytestream. You want to be transmitting raw data to c#.
you then build a real time interpreter that takes in using your file format, one byte at a time, and plays the value associated with that section. does that make sense? this is simple to do with many libraries and the brunt of it is just figuring those out.
You seem like you've PROBABLY got that first part down, and are instead having issues with the database. A lot of things we did at my last company involved saving file network locations and indexing files on disk. You might be able to instead point your streamer to a file locally using a server, and instead transmit data from one point to another in that manner instead.
You seem more than capable of doing this just judging by your speech. I hope this comment was helpful, and if it was not I apologize as well. I would be interested in seeing your finished result.
for clarification here would be that workflow:
request for a song listed in table dbo.Songs
matches that song onto dbo.songlocation
streams from dbo.songlocation.location from the filename dbo.songlocation.songname = dbo.song.name and verified directory returns true
enjoyment of that music
I'm used to output variables to the console in Java, a quick and dirty way to debug and often showed me what was wrong with my code. Unfortunately using Debug.Log in Unity takes a lot of resources somehow. I'm currently generating a simple map in about 80ms, but since there are some problems I'd just like to output some variables, now this makes my map generate in a minute or two. Doing something like this in the update method makes Unity unresponsive and can crash without saving scene edits.
Debug.Log() is incredibly slow in Unity, and can really throw a wrench in performance if you're printing data at high rates (such as in a loop). A big part of the problem is all the extra processing that goes into generating those messages - aside from converting the given value to a string (which has negligible impact on performance), it also has to generate a stack trace so it can link back to the line of code where the logging occurred (see this Unity Answer), which is comparatively slow.
In games, it's a common practice to create an in-game debug output (think of the console in Bethesda games where you can see game events and enter developer commands). Skipping the overhead from Debug.Log() by writing the text you need to output into that output display saves a lot of processing power, and also lets you view debug output with less hassle on mobile devices.
The simplest solution here (short of just not logging so frequently) is to make a Canvas object, add a Text object to it for your debug output, then add a script with a few static methods to append to the Text content so you can reference them (and write to your display) from anywhere in your code.
Alternatively, you can write the output to a file at regular intervals if the text will be too lengthy/generated too quickly to read in real-time, then review it after the code runs.
In my asp.net application when i'm going to upload any size of video need to decrease(reduce) the size of video, any one have code please help me
Thanks
You can not.
Any reduction in video size would be either compression or recoding to a lower resolution etc.
This is way beyond the scope of a web browser upload - unless you want to implement one or both of those in javascript (!).
Any size reduction would have to be done as a separate step - outside of the website - before uploading.
The whole question begs the concept whether you have understood how web pages work, in principle. There is a very strong separation of responsibilities between the web browser and the server. In particular, the following answer to a comment is - funny:
Okay no need to instantly decrease size, just before save path in
database and store file in folder decrease the size, save decreasing
file in folder
Ok, lets upload the parth. HOW DOES THIS HELP?
The path will be local to the uploaders machine. C:\Videos\LargeVideo.mpg is neither the video file, nor a location your asp.net server can access.
This does totally not solve the problem. Unless the user transcodes the file, it still is on the user's machine and too large. This is like saying "ok, the package weights too much - let's write the recipient address in another font". Does not even try to solve the problem.
Only realistic solutions are:
Provide the bandwidth.
Provide a client side upload application (NOT a webpage) that the user installs that then can not only do the upload, but can do any trans-coding necessary before uploading.
You are stuck in two elements:
A very strong client/server separation and
A very limited runtime environment on the client (javascript in the web browser).
No whining and not acceptance will every be able to change that. There is no magical way to "nothing to convert any format, all type of videos accepted just simple decrease file size only". This is called transcoding (change from one encoding to another one - and you can for example change the resolution when doing so) and it is a VERY intensive process not just doable in a browser.
What is a good way to run a time-consuming function from a C# webpage on the users CPU instead of running it on the web-server? Is it possible to get a C# function to run locally or do I have to write the function in JavaScript? The function itself is not secret in any way but I would prefer if the input and the output will be kept secret from the user. The solution should not require the user to download anything.
This functions uses data from the database + user input and when it's finished it writes the output to the database.
The functions best case is ~1s, average ~30s and worst ~10min (for every user) so it's not an option to run this function on the web-server.
You can get this to work, by either
coding the function in JavaScript
compiling the C# source to JavaScript (off the beaten track)
running the C# code in silverlight (done and done again, remember Java Applets? same science)
You won't really be able to keep the data totally secret, though.
Now, how to go about this... You will need a web service to provide the data to your silverlight component and another one to accept the computed results. You know, I don't really see why everyone else here thinks this is such a no-go...
As for data secrecy... The best you can do is obfuscate, though you should use a secure communication layer for aquiring the data and posting the results back, what ends up on the users computer will eventually be open for inspection by the user. If you use obfuscation techniques for your code, this will make reverse engineering an encryption/decryption scheme for the data payload harder, but you're playing essentially the same game as game devs / game crackers...
Personally, I would code the client side stuff in JavaScript. Chances are, what you want done is more of an algorithmic thing than a library thing, so porting to js should not be difficult to pull off.
You can't and shouldn't run arbitrary cs code on the user's computer. You also can't really run a long lived process in javascript on the client. User interaction with the page will be blocked and if they navigate to a different page it will stop.
What you should do is write a windows service to run these tasks in the background. Have a queue table where you save the input data from the web side, then have a service that polls the table for work and processes the input data.
You can't execute any C# code on the client computer when you they enter a webpage. You are correct in your assumption that you need to write it in javascript to execute it on the client.
This doesn't work. Web server does the processing. Unless you are doing distributed computing and stuff like that, it is not designed to work on a client. Client needs to download software to process stuff. Webpage is webpage. Text.
The only code you can run on the client is js.
That being said, you definitely don't want to run your function on the client if you have sensitive information involved.
Hi I'm creating online shop. In this shope people online must be buy files with zip extension. They pay with their credit cards or other methods get key and download product. How can I know when they finish product download?
Thanks
Unfortunatelly there is no really good way to do this as some clients might not download the file at once (e.g. Downloadmanagers split the download into several parralel part downloads).
Options are:
If it is very important to you that it can only be downloaded once: You could
simply not support resuming. Then you
can log if the file has entirely been
downloaded (as soon as the last byte
has been sent). This might work well if the download is small.
Otherwise you could offer some grace
data (we usually allow to download
clients to download 5 times the size
of the real download) and log every
download attempt.
You should NOT just count the bytes downloaded (because the download might be disrupted). And NOT just determine if all sections have been downloaded once (also because the download might be disrupted)
Just to clarify: All this means that you have to write your own download handler (fileserver).
you can use custom file server that works on either http or ftp and have it send a notification once the client received the last file fragment.
all other options are problematic; the client might download the file using a download manager,so you cannot even register for any browser event, if there was any.
A custom server application seems indeed a solution for this,
or possibly some kind of scripting.
A normal http server does not notify the end of a connection,
but possibly, if you generate the output in a cgi/php/asp/* script,
you read the file in cgi/php/asp/* scripting language and
send it to the output. when you reach the end of the file, you
do the notification, and then end the script.
When you do it that way, it will only detect fully downloaded files,
and if the connection gets interrupted half-way, it would not mark
the file as downloaded.
a 'cgi-script' can be a compiled c program, (or any other langauge
for that matter). Compiled code anyways. A compiled program
would give better performance then a interpreted script solution.