Wikipedia:Reference desk/Archives/Computing/2015 June 29

Computing desk
< June 28 << May | June | Jul >> June 30 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


June 29

edit

GET and POST

edit
   function show(e)
   {
   $.ajax({
       type:"POST",
       url:"select.php",
       data:{action:e},
       success: function(data)
           {
               $("#content").html(data);
           }
       });
   }

I'm calling this function onClick on any button and passing value from there to the function, using this function show() the control goes to another file select.php from where the result come back to the current page, everything is working fine, I want to pass all the values from all the buttons or select options or checkboxes which all are already selected, and remove the variable when any option is deselected, ? how to do this ?? — Preceding unsigned comment added by 106.51.131.180 (talk) 07:58, 29 June 2015 (UTC)[reply]

Get the value of each element and create either a GET or POST query. Send that with the AJAX request. It will show up in your PHP script in either $_GET or $_POST, depending on how you sent it. 209.149.113.185 (talk) 12:06, 29 June 2015 (UTC)[reply]
I added a title. StuRat (talk) 17:54, 30 June 2015 (UTC) [reply]

How to copy guidelines to another document in Photoshop?

edit

Hi, I need to get the exact guidelines used in a document on another one in Photoshop. How could I do it..?--Joseph 15:28, 29 June 2015 (UTC)[reply]

Just to clarify the question, are these "guidelines" just text in one Photoshop file that you want to replicate in another ? If you then modify the original, do you need the "copy" to also automatically update with those changes ? StuRat (talk) 20:12, 29 June 2015 (UTC)[reply]
The question does not need clarifying; guides in PhotoShop are lines used to help position objects. This is a rather frequently asked question, but the versions I know about don't provide a direct way of doing it. However, it is possible to find a number of guide-copying scripts that can be downloaded, for example at http://pspanels.com/copy-guides/. Looie496 (talk) 21:59, 29 June 2015 (UTC)[reply]
Oh, those type of guide lines. I thought he meant guidelines. StuRat (talk) 22:05, 29 June 2015 (UTC)[reply]
  Resolved

How to send strings over network using TCP/IP protocol in Python 3.4?

edit

Hello everyone. How would I send strings between python consoles in python 3.4? I think I would use the TCPServer class in the socketserver module. I am running Python 3.4.3 under windows 7. I basically want to run a function on PC A and have it send an argument to PC B and have the console on PC B display the message that it just received. Thanks for your help in advance, —SGA314 I am not available on weekends (talk) 19:30, 29 June 2015 (UTC)[reply]

Edit: I have managed to get a TCP/IP server that allows the client to send a message to the server. However, I can't seem to get the client to send messages after it has connected. Here is my client and server code: Server:

import socket
import threading
import socketserver
ConnectedClients = {}
class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
    def handle(self):
        data = str(self.request.recv(1024), 'ascii')
        message = data.split(":")     
        if message[0] == "ConnectClient":
            if not message[1] in ConnectedClients:
                ConnectedClients[message[1]] = self.request.getsockname()
                response = bytes("Added " + str(ConnectedClients[message[1]]) + " To the server.", "ascii")
                self.request.sendall(response)
        else:
            #print(message[0])
            exec(message[0])
            cur_thread = threading.current_thread()
            response = bytes("{}: {}".format(cur_thread.name, "recived " + data), 'ascii')
            self.request.sendall(response)

class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
    pass

if __name__ == "__main__":
    # Port 0 means to select an arbitrary unused port
    HOST, PORT = "localhost", 9999
    
    server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
    ip, port = server.server_address

    # Start a thread with the server -- that thread will then start one
    # more thread for each request
    server_thread = threading.Thread(target=server.serve_forever)
    # Exit the server thread when the main thread terminates
    server_thread.daemon = True
    server_thread.start()
    print("Server loop running in thread:", server_thread.name)

Client:

import socket
import __main__
def client(message, ip = "localhost", port = 9999):
    if not hasattr(__main__, "Connected"):
        setattr(__main__, "Connected", False)
        
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((ip, port))
    data = bytes("ConnectClient" + ":" + "Client1", "ascii")
    #print(data)
    if __main__.Connected == False:
        sock.sendall(data)
        __main__.Connected = True
        
    sock.shutdown(socket.SHUT_WR)
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((ip, port))
    #response = str(sock.recv(1024), 'ascii')
    #print("Received: {}".format(response))
    try:
        msgdata = bytes(message, 'ascii')
        #print(msgdata)
        sock.sendall(msgdata)
        response = str(sock.recv(1024), 'ascii')
        #print("Received: {}".format(response))
    finally:
        pass
        #sock.close()

SGA314 I am not available on weekends (talk) 20:16, 29 June 2015 (UTC)[reply]

What problem are you having? Your client code defines a function and never calls it. If you put if __name__ == "__main__": Sendmsg("hello") at the bottom, it should work.
Note that your server will not necessarily get the whole message, even if it's under 1024 bytes, because it might be sent in pieces and recv will return only the first piece. You need to call recv in a loop until you've gotten the whole message. To prevent the server hanging if the message is less than 1024 bytes, you should either send the actual length first (probably in a fixed-length encoding to avoid a chicken-and-egg problem) or else call sock.shutdown(socket.SHUT_WR) after sock.sendall in the client to tell that server that no more data will arrive. -- BenRG (talk) 05:35, 30 June 2015 (UTC)[reply]
This does work but not the way I want it to. Its only a 1 way communication. I can only send messages from the client to the server. But I can't do the reverse. Also when either the client or the server gets a message, I want to do something with it, like execute it using the exec function. But I can't do this because the server is being tied up by polling for request. Now I have tried shutting down the server when it gets a message but that didn't work either. So my problem is this, the setup is only 1 way not 2 way, and the server can't do anything because its tied up from the serve_forever function call. —SGA314 I am not available on weekends (talk) 13:13, 30 June 2015 (UTC)[reply]
Edit: I have fixed the problem of the server being tied up by handling request asynchronously. But I still don't know how to send the client messages from the server. And here is another question, How would I get a list of connected clients on the server and use that list to allow clients to send other clients messages through the server? —SGA314 I am not available on weekends (talk) 13:50, 30 June 2015 (UTC)[reply]
Edit: I have now fixed the problem of getting a list of connected clients. Now I only have to figure out how to get the server to send messages to clients. Does anyone know how to do this with the code above? —SGA314 I am not available on weekends (talk) 18:29, 30 June 2015 (UTC)[reply]
Any suggestions on how to get the server to send messages to clients? —SGA314 I am not available on weekends (talk) 19:23, 1 July 2015 (UTC)[reply]

php simplesaml and wamp

edit

Hi there, I've been trying to install SimpleSaml on wamp:
https://simplesamlphp.org/
But when I try to install it, I get 404 error, about welcome_page.php.
After I checked the web it seems I should have added virtualhost to apache.conf.
Unfortunately, whenever I do it, all of the rest of the files on my server isn't available.
1)Does anyone have a solution to the described problem?
2)Does anyone know a good way to implement Saml into php? — Preceding unsigned comment added by Exx8 (talkcontribs) 21:53, 29 June 2015 (UTC)[reply]