File: create_server.py

package info (click to toggle)
coot 1.1.18%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 219,964 kB
  • sloc: cpp: 495,934; python: 35,043; ansic: 26,143; lisp: 22,768; sh: 13,186; makefile: 2,746; awk: 441; xml: 245; csh: 14
file content (63 lines) | stat: -rw-r--r-- 1,755 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# create_server.py

import socket
import sys

hostname = sys.argv[1]
port = int(sys.argv[2])

def connection_proc(port, hostname):

    close_transmission_string = "# close\n# end\n"
    end_transmission_string = "# end\n"

    def end_transmission():
        request.send(end_transmission_string)

    def close_transmission():
        request.send(close_transmission_string)

    # main body

    print("BL DEBUG:: host, port", hostname,port)
    #Setup a standard internet socket.
    #The sockopt call lets this server use the given port even if
    #it was recently used by another server
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
    sock.bind((hostname,port))
    sock.listen(1)

    #Handle a client request
    request, clientAddress = sock.accept()
    print("################ Got a connection!")

    request.send("\n")

    print("BL DEBUG:: read ACT")
    request.send("read_pdb('monomer-ACT.pdb')\n")
    end_transmission()

    import time
    time.sleep(5)
    # more!?
    print("BL DEBUG:: read PIN")
    request.send("imol = coot.read_pdb('monomer-PIN.pdb')\n")
    request.send("set_rotation_centre(5, 5, 5)\n")
    request.send("move_molecule_to_screen_centre(imol)\n")
    end_transmission()
    # close transmission
    print("BL DEBUG:: send close")
    close_transmission()
    sock.close()

    #data = request.recv(1024)
    #print 'Received connection Msg: ', data
    #while msg != 'exit':
    #    msg = raw_input('Enter a Message: ')
    #    request.send(msg)
    #    data = request.recv(1024)
    #    print 'Received Msg: ', data
    #request.shutdown(2) #Stop the client from reading or writing anything.

connection_proc(port, hostname)