send data lwip STM32 PC - c++

I am trying to send or receive data from STM32f(via raw lwip) to computer.
I connected stm32f device to modem and send "ping" and it is ok.dhcp in lwip have got the ip number from modem.And I would like to use QT Creature to send data to STM32 via lwip(connected modem).I dont know what my port number is.What will I write in this codes as port number.
Could you offer me a way,what will I do.
Also, is it possible if I connect the stm32f device directly to computer and communication?
tcpSocket->connectToHost(QHostAddress("192.168.1.30"),portnumber);

What is the value you put in the tcp_bind function call? This should be the port you are listening on. It would be best if you would use a port over 1024 because of the privileged access needed on normal systems with operating systems.

Related

Checking if a program is running on local network

I want to write a simple program in c++ that use tcp socket to communicate with the same program on another computer in lan.
To create the tcp socket I could make the user write the ip and the port to make the connection. But I also need to be able to autodetect in the local area network if there is any computer also running the program.
My idea was:
when the program is autodetecting for available connection in lan, it will send all ips a message via udp to a specific port, meanwhile it will also keep listening to a port waiting to eventual answer.
when the program on the other computer is opened for lan connection, it will keep listening to the a port in case another computer is trying to detect, then it will send also via udp the response messagee notifying the possibility of connection.
All the security system is another problem for which I don't need answer now.
// Client 1:
// Search for all ips in local network
// create udp socket
// send check message
// thread function listening for answers
// if device found than show to menu
// continue searching process
// Client 2 (host) :
// user enable lan connection
// create udp socket
// thread function listening for detection requests
// if request structure is right send back identification message
// continue listening for request
My question - Is there a more efficient or standard way to do something like that?
Testing whether another computer is listening on a given port is what hackers do all day to try to take over the world...
When writing a software like you describe, though, you want to specify the IP and port information. A reason to search and automatically find a device would be if you are implementing a printer, for example. In that case, as suggested by Hero, you could use broadcasting. However, in that case, you use UDP (because TCP does not support that feature).
The software on one side must have a server, which in TCP parlance means a listen() call followed by an accept() until a connection materialized.
The client on the other side can then attempt a connect(). If the connect works, then the software on the other side is up and running.
If you need both to be able to attempt a connection, then both must implement the client and server (which is doable if you use ppoll() [or the old select()] you know which event is happening and can act on it, no need for threads or fork()).
On my end, I wrote the eventdispatcher library to do all those things under the hood. I also want many computers to communicate between each others, so I have a form of RPC service I call communicatord. This service is at the same time a client and a server. It listens on a port and tries to connect to other systems. If the other system has a lower IP address, it is considered a server. Otherwise, it is viewed as a client and I disconnect after sending a GOSSIP message. That way the client (larger IP address) can in turn connect to the server. This communicator service allows all my other services to communicate without having to re-implement the communication layer between computer over and over again.

asio udp multicast sending and receiving on the same host using loopback on the same interface

I'm currently trying to implement the SOME/IP protocol which uses multicast for the service discovery. The Language is c++ and the asio library (without boost) is used in my case.
Currently the code works, but only on 2 diffrent machines. When i try multicast between the 2 apps on the same host i also receive the messages that i just send out. I understand that this is the purpose of the loopback interface, which is enabled when running on the same host but i'm wondering how you could filter out the own messages that were just send and not receive them again? As implementing the standard with that behaviour on one machine is nearly impossible.
When i bind the one programm to my ethernet interface and the other to my wifi interface a normal connection is possible without receiving the your own messaged again after sending.
Is it normal when you implement a network protocol to have 2 machines for testing or am i missing a simple settings which enables me to send / receive from 2 programms to the same multicast , on the same interface, without receiving its own send messages?
Essentially i want to send / receive with 2 programms on the same interface to the same multicast address without also receiving my own messages in each programm after sending them.
Thanks in advance for the help. If you have further question or if my explanation is not good to understand just ask please
I already tried using diffrent ports on the same machine, which resulted in no receiving of any data.

how to get IP address of a computers that is directly connected to my PC

I'm trying to write a function that can get me the IP adress (and the name of the device as bonus) of devices that are in my network, the network is gonna be a direct connection between two computers using Ethernet cable or creating an access point (using wi-fi)
I tried to search about how to do it but it seems like I need to listen to the network or something which seems to be difficult.
hope you can guide me to what I should do or read to get started.
Note: I'm using Windows on both computers.
Edited:
P.S: I need the IP Address so I can send a message to the other computer using winsock in a Client/Server program I wrote.
can't I make the server send its IP to the client or the opposite ?
If your software is running on both machines, you can have one (or both) machines send out a particular broadcast (or, if you prefer, multicast) UDP packet on a specific port. Your program should also be listening on that same port. When it receives that packet (using recvfrom()), recvfrom()'s fifth argument will contain the IP address of the machine that sent the packet, i.e. the IP address you want.
(If OTOH your software is not running on the remote machine, you'll need to use some more general-purpose discovery mechanism such as mDNS or LLDP -- hopefully you won't have to do that, though, as it's a good deal more complicated)

Virtual COM port to Socket communication

I have a virtual COM port and socket in my app , i want to transfer data from this Virtual COM port to a socket and vice versa.
How can i do this?
Is there some sample code or good library out there to do so? Eventually this should work on Windows CE, but initially it should work on regular Windows.
It depends what you need the service to do.
Is it bi-directional, does opening the port have to automatically setup a new network link, do you need to set serial port parameters over the network?
If you only really need to remote a serial port and don't need any command and control data then most introductions to network programming start with some sort of chat server where everything typed at the client end goes to the server as text - it should be trivial to modify this so that the source text comes from a serial port

UDP NAT Traversal

I have a PC and a phone and I am trying to set up bi-directional communication between the 2 over 3G.
On the PC end I have full control over the NAT. So I have port mapped incoming communications on my specific port to the PC on my desk.
I then send to our PC network's outside IP address with my specific port.
I see the packets arrive at my PC, which is perfect. So now I want to send back a communication from the PC to the phone. I have got the address and port via a "recvfrom" and i then do a sendto back across to the address and port that I received the data from.
However this data is then not being received by the phone. I assume the incoming communication is not getting re-directed by the NAT box on the mobile providers network.
Why is this? I thought seeing as I've initiated communication from the phone that I should be able to go back along that route to communicate with the phone?
So, how do I get this working?
Any thoughts appreciated!
Well I did figure out what I was doing wrong. I was communicating from the phone to the PC's port "x" and then trying to go back the other way on port "y". Using the same port for both ways allowed communication to occur :)