Gmod Lua: Setting a NetworkVar on the Client Side - networking

Whenever I set a networkvar form the client side and then get the networkvar from both sides it returns:
Client Side: new value
server Side: old value
Where as If I set it from the server side, both update like normal:
Client Side: new value
server Side: new value
I expected the variable to update on both ends. I have everything properly set up in the shared file.

Related

Processing: How do I set a client to read multiple messages sent at once from a server as separate?

I am working on setting up a basic network system in Processing:
import processing.net.*;
Server myServer;
Client myClient;
However, I'm having trouble with my server and client side communication set up. My client is interpreting all incoming messages as Strings, and the issue is that whenever multiple messages are sent from the server in the same frame, they become added into a single string, which my program cannot interpret. After testing, I found that sending multiple messages from a single client to the server are given the same treatment.
My client reader looks like this:
while (myClient.available() > 0) {
String dataIn = myClient.readString();
As of now, I don't know if the problem is in the reader (combining the strings), or in the fact that I'm using write() multiple times in a single frame (and the data is being sent as a single string).
I am wondering if the messages can somehow be sent/read separately or, if not, there is some method to test if a message has already been sent (that works for both the client and server side) so that I can set up a queue to keep track of messages to be sent.
Well, I decided to forgo the idea of checking if a message had already been sent as I did not see any functions that would be able to help do that. Instead, I went ahead and created an arrayList of strings for the server called serverQ to act as a queue for messages to be sent:
ArrayList <String> serverQ = new ArrayList<String>();
I also added a function writeSQ(String) that would place any input string into the queue:
void writeSQ(String s) {
serverQ.add(s);
}
I then proceeded to replace every usage of myServer.write(String) with writeSQ(String s). At the end of my ServerUpdate function, I added a section that would empty the queue, sending the next string to all clients, one frame at a time:
// send data
if (serverQ.size() > 0) {
myServer.write(serverQ.get(0));
serverQ.remove(0);
}
}
However, for some reason, messages still got compounded, so I speculated that it may be due to the closeness (frequency) of the sent messages (each frame); so I set a boolean serverSent to alternate the messages sent to every other frame. The new code looks like this:
// send data
if (serverQ.size() > 0) {
if (!serverSent) {
myServer.write(serverQ.get(0));
serverQ.remove(0);
serverSent = true;
} else
serverSent = false;
}
This worked perfectly and the messages were interpreted individually by clients. I added that exact same support code to the clients (changing everything from server to client when needed) and after a good amount of testing, can confirm that this new support works properly both ways.

How to reuse variables from previous request in the Paw rest client?

I need to reuse value which is generated for my previous request.
For example, at first request, I make a POST to the URL /api/products/{UUID} and get HTTP response with code 201 (Created) with an empty body.
And at second request I want to get that product by request GET /api/products/{UUID}, where UUID should be from the first request.
So, the question is how to store that UUID between requests and reuse it?
You can use the Request Sent Dynamic values https://paw.cloud/extensions?extension_type=dynamic_value&q=request+send these will get the value used last time you sent a requst for a given request.
In your case you will want to combine the URLSentValue with the RegExMatch (https://paw.cloud/extensions/RegExMatch) to first get the url as it was last sent for a request and then extract the UUID from the url.
e.g
REQUEST A)
REQUEST B)
The problem is in your first requests answer. Just dont return "[...] an empty body."
If you are talking about a REST design, you will return the UUID in the first request and the client will use it in his second call: GET /api/products/{UUID}
The basic idea behind REST is, that the server doesn't store any informations about previous requests and is "stateless".
I would also adjust your first query. In general the server should generate the UUID and return it (maybe you have reasons to break that, then please excuse me). Your server has (at least sometimes) a better random generator and you can avoid conflicts. So you would usually design it like this:
CLIENT: POST /api/products/ -> Server returns: 201 {product_id: UUID(1234...)}
Client: GET /api/products/{UUID} -> Server returns: 200 {product_detail1: ..., product_detail2: ...}
If your client "loses" the informations and you want him to be later able to get his products, you would usually implement an API endpoint like this:
Client: GET /api/products/ -> Server returns: 200 [{id:UUID(1234...), title:...}, {id:UUID(5678...),, title:...}]
Given something like this, presuming the {UUID} is your replacement "variable":
It is probably so simple it escaped you. All you need to do is create a text file, say UUID.txt:
(with sample data say "12345678U910" as text in the file)
Then all you need to do is replace the {UUID} in the URL with a dynamic token for a file. Delete the {UUID} portion, then right click in the URL line where it was and select
Add Dynamic Value -> File -> File Content :
You will get a drag-n-drop reception widget:
Either press the "Choose File..." or drop the file into the receiver widget:
Don't worry that the dynamic variable token (blue thing in URL) doesn't change yet... Then click elsewhere to let the drop receiver go away and you will have exactly what you want, a variable you can use across URLs or anywhere else for that matter (header fields, form fields, body, etc):
Paw is a great tool that goes asymptotic to awesome when you explore the dynamic value capability. The most powerful yet I have found is the regular expression parsing that can parse raw reply HTML and capture anything you want for the next request... For example, if you UUID came from some user input and was ingested into the server, then returned in a html reply, you could capture that from the reply HTML and re-inject it to the URL, or any field or even add it to the cookies using the Dynamic Value capabilities of Paw.
#chickahoona's answer touches on the more normal way of doing it, with the first request posting to an endpoint without a UUID and the server returning it. With that in place then you can use the RegExpMatch extension to extract the value from the servers's response and use it in subsequent requests.
Alternately, if you must generate the UUID on the client side, then again the RegExpMatch extension can help, simply choose the create request's url for the source and provide a regexp that will strip the UUID off the end of it, such as /([^/]+)$.
A third option I'll throw out to you, put the UUID in an environment variable and just have all of your requests reference it from there.

send value using __doPostBack

I'm sending a value (id) from javascript like this:
__doPostBack('',id)
and at the server side I get it like this:
var id = Request["__EVENTARGUMENT"];
the problem is that sometimes other controls also do stuff and the var id also get's value but not with the value I sent, but some control did.
how do I send this value separately so that in var id only the value that I sent using js can be.
One way to hack this I guess is to concat some token prefix like myId_ with id instead of just id as parameter, and parse id back in ASP.NET

How do you determine the client side NAME of a server control?

Let's say I have a DropDownList server control, called "CategoriesDDL" and the ClientID proeprty determines its client side id, which is its ID prefixed with the id's NamingContainer's ids. In this case the client side ID is CP1_CategoriesDDL. But what is the rule regarding the client side name, in this case "ct100$CP1_CategoriesDDL"?
Any chance you're simply after the Control.UniqueId property?
Server side, this will return the client side "name" attribute value of the control.
Are you using ASP.NET 4? If thats the case, the default for the ClientIDMode property on server controls is "Predictable". If you change that to Auto, you will get same client id and client name except "_" and "$". So on the Server Side, you can use client id, replace "_" with "$" to get the client name.
Also look out for the ClientIDMode="Static", this will simplify it greatly.
If you are not using ASP.NET 4, seems there is some different reason for your issue.

How to capture submit form response "different domain"?

I have a case where i want to submit a form and get the response from this submit, because based on this response "at least submit complete response" i will make some other logic.
What makes my case is different that this form is on a domain and i am submitting it to another domain name so can't use ajax submit due to cross script security issues.
Anyone face a case like this and have a solution?
I used JQuery code to submit the form:
$('#MyForm').submit();
Form code:
<form target="MyIframe" name="MyForm" id="MyForm"
action="http://mydomain/page.aspx" method="post"> </form>
For cross-domain communication there is no easy client-side way for you to retrieve results. Server-side support would be required - exposing additional services that you can hit on the client (for example by embedding a element into the page).
This allows you to make GET requests to the server and get the result as JSON. One way to do it would be:
Client creates <script src="http://otherdomain.com/gettoken"></script>
This returns something like
var myToken = "ABC123";
This value is inserted into the form, which is then submitted to the same server
The server stores the results of the form under the key of the specified token
Client creates <script src="http://otherdomain.com/getresult?token=ABC123"></script>
Server fetches the form results for ABC123 and returns then as JSON
You need to make the request on the server side...
Dim Response as String
Using Client as New System.Net.WebClient()
Response = Client.UploadData("key=value")
End Using
Then if you want to use AJAX, you will point it to this local handler to bypass the cross-domain issue.

Resources