Commits

Martin Gergov committed 0baec0b

Temporary fix for constant spaming of packets(it seems to be pyudt related)

Comments (0)

Files changed (4)

examples/appclient.cpp

       return 0;
    }
 
+   while (true){};
+   return 0;
+
    freeaddrinfo(peer);
 
    // using CC method
 poller = UDTepoll()
 s = UdtSocket(AF_INET, SOCK_DGRAM, AI_PASSIVE)
 print s.UDTSOCKET
-#s.setblocking(False)
+s.setblocking(True)
 s.bind(("127.0.0.1", 5000))
-poller.add_usock(s.UDTSOCKET, UDT_EPOLL_IN)
+# poller.add_usock(s.UDTSOCKET, UDT_EPOLL_IN)
 s.listen(20)
 
+try:
+    while 1:
+        sock, addr = s.accept()
+        sleep(20)
+        
+except KeyboardInterrupt:
+    exit("Bye!")
+
 # try:
-#     for i in range(250):
-#         if ok:
-#             sock, addr = s.accept()
-#             print sock, addr
-#             sock.sendmsg("Hello0")
-#             ok = False
-#         else:
-#             mess = sock.recvmsg(1000)
-#             mod_mess = mess + str(i)
-#             print mess
-#             sock.sendmsg(mod_mess)
+#     while True:
+#         #sets = poller.wait(True, True, 1000, False, False)
+#         #print sets
         
+#         # for socket in sets[0]:
+#         #     if (socket.UDTSOCKET == s.UDTSOCKET.UDTSOCKET):
+#         #         sock, host = accept(socket)
+#         #         print sock, host
+#         #         sock = UdtSocket(_sock=sock)
+#         #         sock.setblocking(False)
+#         #         poller.add_usock(sock.UDTSOCKET, UDT_EPOLL_IN)
+#         #         #sendmsg(sock.UDTSOCKET, "Hello", 5)
+#         #     else:
+                
+#         #         try:
+#         #             mess = recvmsg(socket.UDTSOCKET, 100)
+#         #             print "READ:", socket,";", "RECV:", mess
+#         #             #sendmsg(socket.UDTSOCKET, mess, len(mess))
+#         #         except udt4.UDTException as ue:
+#         #             print "ERR:",ue
+#         #             poller.remove_usock(socket, UDT_EPOLL_IN)
+#         #             if ue[0] == 6002:
+#         #                 poller.add_usock(socket, UDT_EPOLL_IN)
+#         #     gc.collect()
+                    
 # except KeyboardInterrupt:
 #     exit("Bye!")
-
-try:
-    while True:
-        sets = poller.wait(True, True, 1000, False, False)
-        #print sets
-        
-        for socket in sets[0]:
-            if (socket.UDTSOCKET == s.UDTSOCKET.UDTSOCKET):
-                sock, host = accept(socket)
-                print sock, host
-                sock = UdtSocket(_sock=sock)
-                sock.setblocking(False)
-                poller.add_usock(sock.UDTSOCKET, UDT_EPOLL_IN)
-                sendmsg(sock.UDTSOCKET, "Hello", 5)
-            else:
-                
-                try:
-                    mess = recvmsg(socket.UDTSOCKET, 100)
-                    print "READ:", socket,";", "RECV:", mess
-                    sendmsg(socket.UDTSOCKET, mess, len(mess))
-                except udt4.UDTException as ue:
-                    print "ERR:",ue
-                    poller.remove_usock(socket, UDT_EPOLL_IN)
-                    if ue[0] == 6002:
-                        poller.add_usock(socket, UDT_EPOLL_IN)
-            gc.collect()
-                    
-except KeyboardInterrupt:
-    exit("Bye!")
 poller.remove_usock(s.UDTSOCKET)
 
 cleanup()

examples/client.py

 import udt4
 from udt4.pyudt import UdtSocket
 import gc
+from time import sleep
 
-# startup()
-# s = UdtSocket(AF_INET, SOCK_DGRAM, AI_PASSIVE)
-# print s.UDTSOCKET
-# #s.setblocking(True)
-# s.connect(("127.0.0.1", 5000))
-# try:
-#     while True:
-#         mess = s.recvmsg(1000)
-#         print mess
-#         s.sendmsg(mess)
-# except udt4.UDTException as ue:
-#     print ue
-#     exit("Bye!")
-# except KeyboardInterrupt:
-#     exit("Bye!")
-# cleanup()
+startup()
+s = UdtSocket(AF_INET, SOCK_DGRAM, AI_PASSIVE)
+print s.UDTSOCKET
+s.setblocking(True)
+s.connect(("127.0.0.1", 5000))
+try:
+    while True:
+        sleep(20)
+        #mess = s.recvmsg(1000)
+        #print mess
+        #s.sendmsg(mess)
+        pass
+except udt4.UDTException as ue:
+    print ue
+    exit("Bye!")
+except KeyboardInterrupt:
+    exit("Bye!")
+cleanup()
 
-import sys
-sys.path.append("../")
+# import sys
+# sys.path.append("../")
 
-from udt4twisted import udtepollreactor
-udtepollreactor.install()
+# from udt4twisted import udtepollreactor
+# udtepollreactor.install()
 
-from twisted.python import log
-from twisted.internet import reactor, defer
-from twisted.internet.protocol import DatagramProtocol
-from twisted.python import log
+# from twisted.python import log
+# from twisted.internet import reactor, defer
+# from twisted.internet.protocol import DatagramProtocol
+# from twisted.python import log
 
-log.startLogging(sys.stdout)
+# log.startLogging(sys.stdout)
 
 
-class UDTClient(DatagramProtocol):
+# class UDTClient(DatagramProtocol):
 
-    identifier = 0
+#     identifier = 0
 
-    def doSend1(self):
-        self.transport.write("?>!{0}".format(self.identifier),
-                             ("127.0.0.1", 5000))
+#     def doSend1(self):
+#         self.transport.write("?>!{0}".format(self.identifier),
+#                              ("127.0.0.1", 5000))
 
-    def datagramReceived(self, data, (host, port)):
-        print "Received %r" % data
-        self.transport.write("bomb!!!{0}".format(self.identifier),
-                                                ("127.0.0.1", 5000))
+#     def datagramReceived(self, data, (host, port)):
+#         print "Received %r" % data
+#         self.transport.write("bomb!!!{0}".format(self.identifier),
+#                                                 ("127.0.0.1", 5000))
 
-udtclient = UDTClient()
-udtclient2 = UDTClient()
-udtclient2.identifier = 1
-print udtclient2.identifier
-reactor.connectUDT("127.0.0.1", 5000, udtclient)
-reactor.connectUDT("127.0.0.1", 5000, udtclient2)
-reactor.callLater(1, udtclient.doSend1)
-reactor.callLater(1, udtclient2.doSend1)
-reactor.run()
+# udtclient = UDTClient()
+# udtclient2 = UDTClient()
+# udtclient2.identifier = 1
+# print udtclient2.identifier
+# reactor.connectUDT("127.0.0.1", 5000, udtclient)
+# reactor.connectUDT("127.0.0.1", 5000, udtclient2)
+# reactor.callLater(1, udtclient.doSend1)
+# reactor.callLater(1, udtclient2.doSend1)
+# reactor.run()
 
 # from udt4 import socket, listen, UDTepoll, bind, recvmsg, UDTException
 # from udt4 import startup, cleanup, accept, UDT_EPOLL_IN, UDT_EPOLL_OUT, UDT_EPOLL_ERR

udt4twisted/udt.py

 
         @see: L{twisted.internet.interfaces.IWriteDescriptor.doWrite}.
         """
+        
         if len(self.dataBuffer) - self.offset < self.SEND_LIMIT:
             # If there is currently less than SEND_LIMIT bytes left to send
             # in the string, extend it with the array data.
             self._tempDataLen = 0
 
         # Send as much data as you can.
+        if self.dataBuffer == '':
+            return
         if self.offset:
             l = self.writeSomeData(lazyByteSlice(self.dataBuffer, self.offset),
                                    self._ttl, self._inorder)