1

Im trying to create a script that will send a specific amount of packets with tcp/udp

i used the next script as a start to check how the socket module works and its working. but the massage is not at the size of 1 packet. can anyone help?

Client:

import socket

UDP_IP = "0.0.0.0" # = 0.0.0.0 u IPv4
UDP_PORT = 5005
MESSAGE = "Hello, World!"

print "UDP target IP:", UDP_IP
print "UDP target port:", UDP_PORT
print "message:", MESSAGE

sock = socket.socket(socket.AF_INET, # Internet
                    socket.SOCK_DGRAM) # UDP
print "Socket is connected!", sock  
for x in range(0,300):          
    print "send"
    sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
falsetru
  • 357,413
  • 63
  • 732
  • 636
Azuk
  • 11
  • 3
  • That code sends 300 udp packets. Its possible to write faster than your NIC can send the packets and eventually cause discard in your machine, but I doubt that's happening here. How do you know there is a problem? I don't understand what you mean by "the message is not at the size of 1 packet". There should be 300 packets, each wtih IP + UDP headers plus the text message. – tdelaney May 15 '17 at 15:09
  • Possible duplicate of [Python socket receive - incoming packets always have a different size](http://stackoverflow.com/questions/1708835/python-socket-receive-incoming-packets-always-have-a-different-size) – Simon Hibbs May 15 '17 at 15:09
  • 1
    @SimonHibbs - that's talking about TCP. Even though OP mentions TCP, the code posted is for UDP and it should be 1 receive per send, with possible dropped packets. – tdelaney May 15 '17 at 15:11
  • How do i know if the msg itself that is being sent is 1 packet size? same for TCP. – Azuk May 15 '17 at 15:13

0 Answers0