File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 1- import socket
1+ #This script is an example for the nxt.server module. You need to run
2+ #nxt.server.serve_forever() in another window. Or, if you want to use
3+ #this across a network, pass the IP of the computer running the server
4+ #as an argument in the command line.
5+
6+ import socket , sys
7+
8+ try :
9+ server = sys .argv [1 ]
10+ bindto = ''
11+ except :
12+ server = 'localhost'
13+ bindto = 'localhost'
214
315insock = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
416outsock = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
5- insock .bind (('localhost' , 54374 ))
17+ insock .bind ((bindto , 54374 ))
618
719while 1 :
820 command = raw_input ('nxt> ' )
9- outsock .sendto (command , ('localhost' , 54174 ))
21+ outsock .sendto (command , (server , 54174 ))
1022 retvals , addr = insock .recvfrom (1024 )
1123 retcode = retvals [0 ]
12- retmsg = retvals [1 :retvals . index ( '~' )]
24+ retmsg = retvals [1 :len ( retvals )]
1325 print 'Return code: ' + retcode
1426 print 'Return message: ' + retmsg
Original file line number Diff line number Diff line change 1010# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1111# GNU General Public License for more details.
1212
13- '''Use for a socket interface NXT driver.'''
13+ '''Use for a socket-interface NXT driver. Command and protocol docs at:
14+ http://code.google.com/p/nxt-python/wiki/ServerUsage.'''
1415
1516import nxt .locator
1617from nxt .motor import *
@@ -56,6 +57,7 @@ def _process_command(cmd):
5657 try :
5758 brick = nxt .locator .find_one_brick ()
5859 brick = brick .connect ()
60+ retmsg = 'Connected to brick.'
5961 retcode = 0
6062 except :
6163 retcode = 1
@@ -172,7 +174,7 @@ def serve_forever():
172174 code , message = _process_command (inmsg )
173175
174176 #send return code to the computer that send the request
175- outsock .sendto (str (code ) + message + '~' , (addr [0 ], 54374 ))
177+ outsock .sendto (str (code ) + message , (addr [0 ], 54374 ))
176178
177179 #print a summany of the response
178180 print 'Send return code ' + str (code )+ ' with message "' + message + '" to ' + addr [0 ]
You can’t perform that action at this time.
0 commit comments