Using two different computers, I have to implement sender and receiver algorithms to send and receive frames. I’m a strong programmer, but relatively new to network programming and python. The algorithms are below.
Sender-site algorithm:
while(true)
{
WaitForEvent();
if(Event(RequestToSend))
{
GetData();
MakeFrame();
SendFrame();
}
Receiver-site algorithm:
while(true)
{
WaitForEvent();
if(Event(ArrivalNotification))
{
ReceiveFrame();
ExtractData();
DeliverData();
}
I have to implement these algorithms on two separate computers, one as a sender and the other as a receiver. I have no idea where to start or look for examples. I’ve done some research with little luck. If someone can supply example code or a good article on implementing this, that would be lots of help.
I find myself using Python’s Socket Server examples. This will get you going on the
SendFrame(),ReceiveFrame(), andDeliverData()routines.The
MakeFrame()andExtractData(), will vary widely based on how much data you’re needing to send back and forth. I will try to dig up some good examples I have used in the past.If you’re looking for a 1 stop solution, I would suggest looking into Twisted. There is a definite learning curve to it, but it might be worth it to you. Note that if you’re wanting to package the Python code into an exe using
pyInstallerorpy2exe, Twisted may give you trouble based on a number of threads I have read.So after looking back through my notes, the framing aspect was a sore subject for me as I could not find any good examples to help. I instead wrote one from scratch and have (and still am) tweaking it.
As you read up on socket programming you will surely see that just because you send all the data (
socket.sendall()) does not mean that you will receive it all after the firstsocket.recv(). This adds some complexity to the message framing question. Due to lack of examples on the web, below I have a stripped down version of what I am using right now in several processes.Update
So after further testing the under heavy / bursting I moved away from the regex and process the stream character by character which has greatly improved its performance.
SendFrame(),ReceiveFrame(),ExtractData(),DeliverData()Examples: