Skip to content

Instantly share code, notes, and snippets.

@geokal
Forked from dufferzafar/mininetSocketTest.py
Created September 6, 2018 13:25
Show Gist options
  • Save geokal/5fae03e890027b1e8702fcd274ec6c77 to your computer and use it in GitHub Desktop.
Save geokal/5fae03e890027b1e8702fcd274ec6c77 to your computer and use it in GitHub Desktop.
Difference from the fork: PEP8 + Fix "Could not find a default OpenFlow controller" issue
#!/usr/bin/python
from mininet.node import OVSController
from mininet.topo import SingleSwitchTopo
from mininet.net import Mininet
from mininet.log import lg
from mininet.cli import CLI
def main():
lg.setLogLevel('info')
net = Mininet(SingleSwitchTopo(k=2), controller=OVSController)
net.start()
h1 = net.get('h1')
p1 = h1.popen('python myServer.py -i %s &' % h1.IP())
h2 = net.get('h2')
h2.cmd('python myClient.py -i %s -m "hello world"' % h1.IP())
CLI(net)
p1.terminate()
net.stop()
if __name__ == '__main__':
main()
import socket
import optparse
parser = optparse.OptionParser()
parser.add_option('-i', dest='ip', default='127.0.0.1')
parser.add_option('-p', dest='port', type='int', default=12345)
parser.add_option('-m', dest='msg')
(options, args) = parser.parse_args()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto(options.msg, (options.ip, options.port))
import socket
import optparse
parser = optparse.OptionParser()
parser.add_option('-i', dest='ip', default='')
parser.add_option('-p', dest='port', type='int', default=12345)
(options, args) = parser.parse_args()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((options.ip, options.port))
f = open('foo.txt', 'w')
while True:
data, addr = s.recvfrom(512)
f.write("%s: %s\n" % (addr, data))
f.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment