Arduino Ethernet Server - server

I have a small issue with ethernet server. I'd like to make Arduino server listening on port and catch connected devices but the problem is thats devices don't send anything first. just connecting and waiting for "welcome message" from the serwer.
Unfortunately I con not use this command
EthernetClient client = server.available();
Do you have any idea how to get client instance/object without sanding any message from client.
Thanks

server.available() should return only a client which has data waiting, otherwise you would get always the first client only.
You can use server.accept(). I returns a every client connection only once. See the AdvancedChatServer example.

Related

What causes "Transport endpoint is not connected" in ZeroMQ?

I am working on a product which uses ZeroMQ (version 4.0.1).
The server and client communicate based on ZeroMQ ROUTER-socket.
To read socket events, server and client also create socket-monitor sockets (PAIR). There are three ports on which server binds and listens. Out of these three ports, one port is in a non-secured mode. Other two ports are using md5-authentication.
The issue I am facing is that, both the server and the client spontaneously receive socket disconnect for one of the secure port sockets (please see a log below). I have checked multiple times that server and client both have L3 reachability to each other.
What else I should check for?
What really triggers this error scenario?
zmq_print_callback:ZmQ: int zmq::stream_engine_t::read(void*, size_t):923
Stream engine recv():
TCP socket (187) to unknown:0 was disconnected
with error 107 [Transport endpoint is not connected]
Below sequence of events can trigger this error on server
Server receives ACCEPTED event for clientY and gets FD1.
Link-flap/network issue happens and clientY disconnects but server does not receive this disconnect.
Network recovers and clientY connects back to server.
Server receives ACCEPTED event for clientY and gets FD2. However, packets sent to this sockets does not go out of the server.
After 1 min or so, clientY receives "Transport endpoint is not connected error" for FD1.
Application can use this to treat as client disconnect.

Returned UDP packets lacking port and fail to arrive

Golang application with a client and server.
Server uses net.ListenUDP -- client also uses net.ListenUDP, connects to server and sends a packet with conn.WriteToUDP with the server address.
Server receives the packet with ReadFromUDP and grabs the return address. Using this return address, it then sends a large number of packets back to the client.
When running both client and server on local machine, this works perfectly. Using Wireshark I can inspect the UDP packets and see that they contain the source and destination ports - and in the application I can see that they arrive and my various checksum tests show the data is accurate.
I then moved the server off site to a remote machine. The application stops working. I can successfully send the first message from the client to server - this is received just fine. The server sends the response back 'toward' the client - but the client never receives them.
Using Wireshark, I can see that the packets do arrive back on the local machine with the correct IP address. It appears that my network router has performed NAT on the outgoing packets - and has correctly re-addressed response packets to the internal IP.. BUT there is no port.
So I have UDP packets arriving on the correct machine, but no port - so the client application does not receive them. Application times out on ReadFromUDP.
I don't know if it is relevant, but on local machine, Wireshark labels the packets as BT-uTP Utorrent packets. When they come in from remote server, this is what I see in Wireshark - note the lack of Port.
Any thoughts how I can solve this. I didn't think this was a UDP hole punching problem because although I am establishing a connection across a NAT it is with a server not a peer.
This packet is fragmented, You can see this under Internet Protocol Version 4 > Flags.
If you look at the frame as shown on the bottom of the picture you provided you should see the ports.
net.ListenUDP doesn't appear to support fragmentation at the socket level.
Do you have a PPPoe connection? You may need to reduce your packet size being sent by 8 bytes or change the MTU on the routers external interface of the remote side. You may also need to change the local routers MTU if it's on a PPPoe interface.

Is TCP Reset (RST) two way?

I have a client-server (Java) application using persistent TCP connections, but sometimes the Server receives java.io.IOException: Connection reset by peer exception when trying to write on the socket, however I don't see any error in the Client log.
This RST is probably caused by an intermediate proxy/router, but if that's the case, should this be seen on the client as well?
If the RST is sent by the client, it can be seen on it using a packet sniffer such as wireshark. However, it won't show up in any user-level sockets since it's sent by the OS as a response to various erroneous inputs (such as connection attempts to a closed port).
If the RST is sent by the network, then it's pretending to be the client to sever the connection. It can do so in one direction, or in both of them. In that case, the client might not see anything, except for a RST sent by the actual server when the client continues to send data to a connection it perceives as open, while the server sees it as closed.
Try capturing the traffic on both the server and the client, see where the resets are coming from.

Ethernet not getting braodcast packets

I'm working on 2.6.15 kernel running on a cisco IPTV. When the box is coming up, the DHCP client hangs up. The reason for this is that the DHCP client does not get fetch the broadcasted DHCP offer message.
When I read /proc/net/dev file, it shows that ethernet device (eth0) has not received any packet. I then ran tcpdump on the box and it also shows that no packet is been received on the ethernet interface.
Then I ran wireshark on the test PC (on which DHCP server is running), it shows that a DHCP offer message is broadcasted by the DHCP server.
This DHCP client and server are working fine with other boxes so there are less chances that these programs have any issues. There must be an issue in the ethernet drivers.
I'm really confused. How should I proceed to this problem. Please help me.
Maybe you can start by checking whether the DHCP client is sending out a discovery.
The DHCP handshake goes like this:
client discovery,
server offer,
client request,
server ack
(Wikipedia has the steps of DHCP)
The next thing you can check any DHCP related settings on the router.
Is the DHCP client on the same subnet/vlan as the server? If not, would the router need a certain configuration to relay to/from the DHCP server subnet/vlan?

Port access in iPhone

I am trying a server to get data "www.example.com" with the port "xxxx" and my ip is "192.168.10.6". The server has to send the response to my app through port "yyyy". I sent a request to the server, but the sever sends the response to the ip "203.146.0.9" port "yyyy". And the server shows the log as "Connection rejected by 203.146.0.9:yyyy(port)".
I am very much beginner to the network programming. According to my knowledge the server sends the response to my DNS/router. Which not accepts the communication on that port.
My iPhone app listens the port of the device and not the dns port. How to make my app to listen the DNS port or else how to make the DNS to forward the response comes from the particular server to my local iP.
I gone through some post and some specified the "Bonjour". But I have no idea about that. Can anyone please help me by pointing out such example or documentation to clear this issue?
Short answer: you can't
Long answer:
Whenever you connect to a server through your iPhone, the phone forwards the request to the carrier's router via 3G or GPRS or some other protocol, which forwards the connection to the destination server. On the receiving end, the server sees the router's IP address, not the phone's. Actually, the phone's IP address only exists on the carrier's router, and nowhere else on the internet. You cannot create a public server from an iPhone (only maybe on a local WiFi connection, or if the carrier assigns the phone a public routable IP address). Therefore, you cannot initiate a connection from your server to some iPhone. If you want two way communication, you can however use the iPhone to connect to the server and on the server side, use that channel to send data to the iPhone. NAT may be another solution, but once again, it requires special provisions from your carrier, which may be an option for you, but usually not your clients having iPhones.