Difference between revisions of "Minibot"
Line 2: | Line 2: | ||
This is MiniBot it is the robot that we maid for out Senior design project. | This is MiniBot it is the robot that we maid for out Senior design project. | ||
+ | '''Networking''' | ||
+ | we used [https://docs.python.org/2/library/socket.html import socket] for sending information over a network with a client and a server | ||
+ | |||
+ | ''server'' | ||
+ | the code for the server is | ||
+ | |||
+ | host = '192.168.0.102' #gets comp ip address | ||
+ | port = 20000 #random port this can be set to almost anything between 1023 and 6000 ish once you start a server if you need to restart it you will need to close that terminal and open a new one so the port will no longer be in use | ||
+ | |||
+ | s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) this part is what tells the socket what kind of data we want to use AF_INET tells network/internet and sock_DGRAM tells it to use udp packets (these are somewhat unstable as they are not checked) | ||
+ | |||
+ | s.bind((str(host), port)) #binds s to the server so it can be called | ||
+ | |||
+ | data, addr = s.recvfrom(1024) this tells the program to wait till it gets a packet from the client the 1024 can be lowered but should be in base 2 if you leave it at 1024 it will be fine it just tells it to take data that is only 1024 or less |
Revision as of 10:36, 27 November 2014
This is MiniBot it is the robot that we maid for out Senior design project. Networking we used import socket for sending information over a network with a client and a server
server the code for the server is
host = '192.168.0.102' #gets comp ip address port = 20000 #random port this can be set to almost anything between 1023 and 6000 ish once you start a server if you need to restart it you will need to close that terminal and open a new one so the port will no longer be in use
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) this part is what tells the socket what kind of data we want to use AF_INET tells network/internet and sock_DGRAM tells it to use udp packets (these are somewhat unstable as they are not checked)
s.bind((str(host), port)) #binds s to the server so it can be called
data, addr = s.recvfrom(1024) this tells the program to wait till it gets a packet from the client the 1024 can be lowered but should be in base 2 if you leave it at 1024 it will be fine it just tells it to take data that is only 1024 or less