is it possible to send argument to java socket like we do in url argument passing
XXX.XXX.XXX.XXX:XXXXX?id=d1948b485d6
I have application which broadcast message from XXXX1 to XXXX10 port and every port i have assigned to specific user , so i want to restrict user from to access any other port .
XXX.XXX.XXX.XXX:XXXXX?id=d1948b485d6 by using unique id was decided to validate user with port,id buts its not possible so any other way do so.
That is a unique feature of web page access and can't be used with regular sockets. It can be used with servlets, though, because they are basically web pages.
Edit: Now that the question has been revised, I can now answer the underlying question much better than the original question. It is not a good idea to assign each user a port. Then you are limited to about 64000 users. Instead, the user should transmit authentication information with each request, or transmit it when opening the connection and then use only that connection.
Related
Is it possible to send extra data attached to a http response via Java or Php?
My Website is a homework-platform: One User enters homeworks into a database, and all users can then see the homeworks on the website. The current load is very inefficient, as the browser makes two requests for eveything to load: One for the index file and one for the homeworks. For the homeworks request the client also sends settings of the user to the server, based on which the returned homeworks are generated by a Php script.
Now, I wonder, if it is possible, to combine those two requests into one? Is it maybe possible to detect the http request with Java or Php on the server, read the cookies (where the settings are saved), then get the homeworks from the database and send the data attached to the http response to the client? Or, even better, firstly only return the index file and as soon as possible and the homework data afterwards as a second response, because the client needs some time to parse the Html & build the DOM-tree when it can't show the homeworks anyway.
While browsing the web I stumbled across terms like "Server-side rendering" and "SPDY", but I don't know if those are the right starting points.
Any help is highly appreciated, as I'm personally very interested in a solution and it would greatly improve the load time of my website.
A simple solution to your problem is to initialize your data in the index file.
You would create a javascript object, and embed it right into the html, rendered by your server. You could place this object in the global namespace (such as under window.initData), so that it can be accessed by the code in your script.
<scipt>
window.initData = {
someVariable: 23,
}; // you could use json_encode if you use php, or Jackson if you use java
</script>
However, it is not a huge problem if your data is fetched in a separate server request. Especially when it takes more time to retrieve the data from the database/web services, you can provide better user experience by first fetching the static content very quickly and displaying a spinner while the (slower) data is being loaded.
I am transmitting a password through HTTP(S) to a HttpServlet as parameter. To get the password I am using the Servlets getParameter(String) method, which returns a String. But passwords should be handled with char[] like mentioned here.
Well, what I want to know is: How can I process a password securely within a Java Servlet? Is my solution with getParameter(String) the only one or are there better options?
Please keep in mind that I am NOT interested in how to transmit a password securely (I am expecting that the transmit is secure - maybe with SSL or something else).
Thanks in advance :)
Edit:
I forgot to mention that I am not using the password myself (for some kind of access restrictions for my application). I am just forwarding the password (so you could say my WebApp is something like a remote control).
If your login parameter is sent in a POST request and contained in the request content you could parse the content yourself and put the password in a char array.
You need to do this before any call to request.getParameter(String)is made since this will make the container read and parse the content. This only works if the servlet container lazily initializes its parameter map.
"Teleporter" approach:
Have Javascript break the password into parameters of 1 character each. Reassemble directly into char array at server side.
Scenario:
We have one analysis which gives different results based on different inputs. So if the user open the same analysis in two different browser tabs, the session variables being common will get overridden and output will be same in both tabs though we want different outputs based on different user inputs in tabs.
So we plan to send a tab-id at the backend so that we save session variables per tab-id.
Is there some automatic way that tab information is being sent to the server like may be in request header or something like that??
Or we will have to generate a tab-id ourselves and send it with every request?
You'll have to generate your tab-id and pass it back with each request, but the following might make it a bit easier:
You can use sessionStorage from Web Storage API to store values unique to each tab. Every tab in the browser starts a new session so they are always distinct.
https://developer.mozilla.org/en/docs/Web/API/Window/sessionStorage
It should work with most common browsers (even IE8+): http://caniuse.com/#search=web%20storage
Hope that helps!
I have a java code where I am making a tcp connection to a site. Then, after that, I want to pass the value of a variable so that the site will permanently display that value. For example, if I define int x = 10; in my java program, I want to pass this value to the site so that it echos that value for ever until a new value is passed. I have no idea how to do this however, is this even possible? Where should I look, in terms of both java and php? Thanks
I suppose, when you are creating a tcp-connection, means you are the client and the site you are connected to is the server. I also hope that you are the one in charge of the server here. If that is the case, then what you are looking for is a simple Java server-client system. This will get you started with that.
If, you are not in charge of the server then you'll just have to create the client part and send data. But that itself probably, won't be sufficient because the server should be able to parse your data. So, you'll have to find out in what format is the server expecting data from the client.
I am a novice programmer in java.
I have created a program which is similar to a chat application using socket programming.
I haven't used threads.
My question is:
Whenever a client1 wants to communicate to another client2 via the sever how can i know which client is communicating.
I thought if i could differentiate all clients from server side by using sessions it would be easier. Just a random thought.
why this question??
I want to know this because i have stored the adressess of clients in a file along with a sequence number to make the messages visible to the pair alone globally. Whenever a client sends a message it prefixes it with a sequence number which is got from the client1 client2 pair stored in that file.
Any help would be greatly appreciated. Im just a learner in java. I apologize for any obscurity in my question.
First of all, try to make a thread to open a socket because it helps in your GUI processing. And the point that you want to see client names can be done by this steps:-
Add an editbox and enter your name (client name) and send this name along with the message and at server-side, split message and name so that you can determine which message is sent by whom.
Ex:- Client name is Alex and the message is "hi" then the data which will be sent is something like "Alex+hi". Now split this message using split() function in java at the server-side.
Hope this encoding and decoding will help you.