7

Working on creating an asyncio UDP server/client. Going to have it talk to another server/client. Why? Because I don't want there to be a round trip to my data. I want send and forget.

So I created a combo server/client in C++. I am testing out the client and I find that it connects and sends data with zero errors as a client even if there is no endpoint (server) active. Okay, well its connection-less so it kinda makes sense. So I am not even sure what connection means at this point. I figured it was sending data into the ether. Fine, I don't have to worry about dropped endpoints or some shit. The server does see messages once it creates itself (tested with Python server). Not old messages, just the ones currently being sent.

So I do the same thing in Python and use asyncio to create server/client with opposite ports to talk to my C++ server/client. However, if C++ server doesn't exist the Python client throws an error. Okay, wtf... So Python UDP client is gonna be extra steps because why? Because fuck you! That's why! lol

UDP Client Comparison:
C++: I don't give a shit, if you don't get the data then fuck off. I won't error no matter what.
Python: Oh shit, there is no server, so I won't even run. Because fuck you and wanting to send messages to the ether.

Now I need to do the same thing in C# and see what kind of "fuck you's" it will have.

What did I learn? I learned Python has a nice asyncio system similar to asio from boost.

Comments
  • 3
    How does Python even know? Did I miss something about UDP?
  • 1
    @lorentz no idea

    edit: All I can think is it checks for existence of port maybe.
  • 2
    Okay, it throws an error on the Python client side, but continues to operate. If I start a server on the C++ side it will get whatever messages the Python side wants to send. So I just need to ignore the error message on the Python side. I was libeling Python. It operates the same way except an extra one-time message.
  • 3
    Very rough memory, but I do believe there can be a signal sent back to the sender if the there is an issue, that's how you can discover the MTU (The maximum size that the packet will be guaranteed to not be bifurcated during transmission). I don't remember the tech details about it, I believe it's also doing UDP but might be some other protocol (since I "needed" my UDP packets to not be split).
  • 2
    @BordedDev I determined I only see it on first send if server isn't there. So its not even in the connect like I thought. I dunno, I can ignore and it still works which is why posted a followup.
  • 2
    To clarify the signal wouldn't come from the server but from some intermediary routing layer, I found this article which mentions a PMTUD response, although I highly doubt that python would implement the extra layers.

    https://goziro.com/udp-fragmentatio...

    Maybe the issue is that it thinks you're reusing the port (not sure if the python side is doing something silly), I'm guessing it's not giving the exact message?
  • 1
    @BordedDev

    Error received: [WinError 1234] No service is operating at the destination network endpoint on the remote system

    Must be coming from OS.
  • 2
    @Demolishun Looks like it's windows processing/creating the ICMP packet https://github.com/python/cpython/... and should exist for the C++ server as well, but you'd have to set up the ICMP handler yourself

    Seems like you found a bug in my networking code/handling/enhancement thanks, more fun things to work on :D
  • 2
    @lorentz you probably missed a packet.
  • 2
    Actually, I wouldn't even use asyncio for that. Aio will choose the first readable connection but the os is already doing that in case of udp. You can just loop the recvfrom from the old school socket object and it wil prolly even perform better in theory, in reality it won't matter much. My udp thingy maxed out at 4k messages btw. That's nice, needed only 1024 anyway so I considered a safe margin. Nobody talks about it but with setopt you can set socket buffer sizes. No one does this. But I'm sure you're not buffering anything.
  • 0
    @retoor I am hoping for a few hundred bytes most of the time.
Add Comment