Comments (9)
Yes you're right, two threads may not use the same socket simultaneously. The application will crash.
Here are two alternative implementations:
- Create two sockets, one for receiving data and one for transmitting data. Bind the receiving socket to the local address, and do not bind the transmitting socket. I have not tested it but I think it will work. Depends on how LwIP handles this use case.
- Create two sockets and bind them to different local ports, if that works with your use case.
So the key is to create multiple sockets and somehow make that fit into the application. I think it's hard to allow multiple threads to use the same socket. Maybe it is, but I have to think about it. =)
from simba.
The client is at the back of the NAT server, which means that I have to use the same listening port, to allow the server to respond to the data back to the client to handle correctly
If the client uses a different socket or is not bound to a fixed address
Can cause the server to respond directly to the data can not be received, so I also feel very difficult
from simba.
Hmm, tricky... How is this normally implemented?
Would it work to have one thread and check if there is input data interleaved with sending packets? socket_size()
should return a non-zero value if there is a UDP packet available in the input queue. Unfortunately there is no possibility to configure a socket as non-blocking as of today.
from simba.
how about direct use udp_sendto method to send the message?
this method from lwip api, and not change any thing about socket ....
from simba.
Is it allowed to call LwIP functions, like allocating a pbuf or sending a udp packet, from all threads in an application? I'm not comfortable doing that from the Simba thread as I do not know how LwIP works. Maybe it is ok?
from simba.
I tested it, it seems to work, but this practice is not beautiful, It's really not so comfortable
, but it can only be so, or I have to switch to a espconn_sendto function
thanks ~~~~~
from simba.
Another alternative is to put thrd_p
on the stack of the sending/receiving thread. That way it will be unique for each thread.
I'll have a look at it later. It should be easy to implement.
from simba.
Okay, I just pushed a fix! Let me know if there is still a problem!
Note: Only one sender and one reader may be using the socket at the same time. Two or more senders and/or receivers are not allowed.
Implemented in: ff0df96
from simba.
yes, it's working now
nice ~~~, thanks 💯
from simba.
Related Issues (20)
- Use external interrupts with esp01 HOT 5
- Upgrade support for esp family HOT 3
- std_read() HOT 3
- Reduce Memory Usage HOT 2
- SoftwareSerial RS485 Arduino.h to Simba.h HOT 3
- STM32F103C8T6 Support
- Not all ports have nvm_port_vwrite HOT 1
- Fuzzy testing brainstorming
- New user, unable to compile blink in Arduino ESP12E
- Pro Micro blink example not working HOT 2
- Uploading SPIFFS to ESP8266 HOT 1
- Unable to build with DHT from PlatformIO HOT 2
- Is there missing struct initialization? (http_websocket_client_connect) HOT 2
- Timer timeouts in threads are broken. HOT 2
- Vendor link on platformio broken HOT 1
- Request: Comparison Chart HOT 1
- nanoatmega328new board should be mapped to arduino nano HOT 1
- PIN_INPUT_PULL_UP has been deleted HOT 5
- Question about pure MCU work HOT 1
- Year 2038 problem
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simba.