Possible to use multiple sockets with the Ethernet library?

Hi

I’m making a VoIP (Voice over IP) telephone as my thesis out of the Arduino Mega2560. VoIP however requires me to use at least three (3) UDP sockets at the same time. One for SIP (Session Initiation Protocol), one for RTP (Real-time Transport Protocol) and finally one for RTCP (RTP Control Protocol). Now I know for a fact that the WIZnet w5100 (present in the ethernet shield) is capable of running 4 sockets simultaneously as I have used the same chip in my previous PSoC (Programmable System-on-Chip) projects. The PSoC was however too slow for this project so I though I’d try out Arduino, since it had so many similarities.

Anyway I was reading through the ethernet library and in the Udp.cpp file I saw _sock = 0; //TODO: should not be hardcoded. But I see the socket number taken as a variable all over the ethernet library so that would indicate there’s a possibility of a slim hope for me. Has anyone tried toying around with the other sockets? Is the library written so that it reads the correct socket registers for sockets that are not zero?

If so I’m thinking of a dirty solution of just copying the UDP library a few times and adding numbers to them and changing their socket values. This might not be the best solution but that’s something that came to mind. I really can’t be asked to rewrite the whole library since I have a time constraint.

Thanks in advance guys.

sentros: The PSoC was however too slow for this project so I though I'd try out Arduino, since it had so many similarities.

And the Arduino will be faster? Have you had a look at the clock?

I can't say for sure, but I seem to remember some code to choose the lowest available socket number when we requested a socket. However, I may have seen it in the Wiznet examples instead of the Arduino documentation.

But why not giving it a try? Or, why even using the Ethernet library for such a specific and demanding task?

bubulindo:

sentros:
The PSoC was however too slow for this project so I though I’d try out Arduino, since it had so many similarities.

And the Arduino will be faster? Have you had a look at the clock?

I can’t say for sure, but I seem to remember some code to choose the lowest available socket number when we requested a socket. However, I may have seen it in the Wiznet examples instead of the Arduino documentation.

But why not giving it a try? Or, why even using the Ethernet library for such a specific and demanding task?

All I can get my hands on is the PSoC1 and even tho it operates on a higher clock frequency it can only do 4MIPS whereas the Arduino can do 16MIPS.

And what comes to using the Ethernet library my project might be used as an example in Arduino coding courses at my school later on so I want to use as much of the built in libraries as possible to keep it simple to people reading it later on.

Thanks for the reply. :slight_smile:

sentros: All I can get my hands on is the PSoC1 and even tho it operates on a higher clock frequency it can only do 4MIPS whereas the Arduino can do 16MIPS.

And what comes to using the Ethernet library my project might be used as an example in Arduino coding courses at my school later on so I want to use as much of the built in libraries as possible to keep it simple to people reading it later on.

Thanks for the reply. :)

Do remember that AVR uses RISC architecture... so depending on application, the other chip may be faster. Although it doesn't seem to be the case here.

Well... apart from the fact that some sockets don't support all modes (from the top of my head, I'd say that it is only IP Raw that is not supported by all), you could implement the missing socket part in the library and turn that into a lesson in itself. The change is simply to verify if the socket is between 0 and 3 and if it is being used or not. So it's not exactly rocket science and would be a valuable experience for the students.

Also, as the comment in the library says "TODO: should not be hardcoded", which means that if someone fixes that correctly, it can be included on the next versions of Arduino.

bubulindo: Do remember that AVR uses RISC architecture... so depending on application, the other chip may be faster. Although it doesn't seem to be the case here.

Well... apart from the fact that some sockets don't support all modes (from the top of my head, I'd say that it is only IP Raw that is not supported by all), you could implement the missing socket part in the library and turn that into a lesson in itself. The change is simply to verify if the socket is between 0 and 3 and if it is being used or not. So it's not exactly rocket science and would be a valuable experience for the students.

Also, as the comment in the library says "TODO: should not be hardcoded", which means that if someone fixes that correctly, it can be included on the next versions of Arduino.

Indeed. It seems this is what I have to do. I'm just kind of disappointed that in the Arduino official library page it says "The library supports up to four concurrent connection (incoming or outgoing or a combination).".

I remember seeing that same piece of code before... but I haven't got the latest Arduino libraries (I don't use them), so I may be wrong and the latest and greatest actually implements the concurrent sockets.

Have you gone through the Wiznet sample code?