what makes a udp socker server or client - network-programming

A udp sever can receive and send udp messages.
A udp client can receive and send messages.
So what makes a client and what makes a server
Is the server the side who initiates the first message or the side which does the binding on the socket or both ?

The server always serves client requests. By definition. This means (from this follows) that the client always sends the first message (request). To be able to receive messages, the server binds a socket. Socket binding is an instruction for the operating system to reserve a specific (local) port for your process (it does not matter if the server or client).
UPDATE #1
So SERVER must perform bind() but CLIENT can perform bind(). If you need to identify if the code is a SERVER you should check if this code perform bind() and recv() or recvfrom() BEFORE performing send() or sendto().

Related

Mqtt client does not receive offline messages from VerneMq

We have an mqtt server (VerneMq on Linux VM on Azure) which is configured like below
max_inflight_messages=500
upgrade_outgoing_qos=on
max_offline_messages=1000000
max_online_messages=1000000
persistent_client_expiration=1w
in addition to it's default configuration.
In order to test the persistent message mechanism, we created the following scenario:
We fed the server with some test messages and wait couple of minutes before subscribing with the client (with cleanSession = false), we were able to receive all the messages.
But if we do the same thing and wait 24 hours, we can not receive all stored messages, even if we can see awaiting messages for that client with
vmq-admin trace client client-id=<client_id>
Broker and client both use qos=2.
Is there any other configuration on client or server we have to change?

Indy HTTP(s) reverse proxy

I'm trying to create a HTTP(s) proxy server that will act like this:
Browser configured to use proxy on 127.0.0.1:1080. On this port, I need to have a server (TIdTCPServer?) that will pass data coming to a client, that is connected on this same server (maybe into another port to make things easier). The client need to be connected, and not serving connection because of possible NAT restrictions.
The idea is that the client will execute the requests and send back to the server, which should send to the browser.
Browser > connect to local server > send to client connected which make the request
I thought about IdHTTPProxy, but no idea on how to pass request to a client, and client execute, gets back the data to the server / browser.
I read about TIdMappedPortTCP, but looks like this should connect into another host/port, and in my case the client can't receive connections.

MQTT Can broker send any message to client before server disconnect the existing client?

MQTT Broker can disconnect the existing client if the following condition is came up.
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718090
If the ClientId represents a Client already connected to the Server then the Server MUST disconnect the existing Client
[MQTT-3.1.4-2].
At this time, can broker send any specific message excluding "DISCONNECT" to client before server disconnect the existing client ?
Most brokers are going to follow the spec, if you want one to do something different then you will have to either write your own or modify one of the open source versions.

How socks protocol is working

Currently I need to implement socks client. According RFC, Socks protocol has two main commands: CONNECT and BIND. CONNECT is used to forward an outbound connection from socks' client to desired Server. BIND is used to forward an inbound connection from desired Server to socks' client.
My client work as follows:
Firstly It makes connection to socks Server, let us call it a "client connection".
After that it issues commands.
I have some misunderstanding with a "client connection" utilisation. Hence, I have the following questions:
A "client connection" could be used only for one CONNECTION command, is that right ? So for each desired communication I need to create a new "client connection" and after that issue command CONNECT.
For BINDing, firstly, i need to issue CONNECT and after issue command BIND. These commands must be issued in a one "client connection", am I right ?
How many inbound connections socks server could receive on BIND socket ? Only one ?
How traffic flows in case of BIND is used ? We have a "client connection" to socks server. For the "client connection" socks server has one connection to desired server and one incoming connection from desired server. Hence, socks server could receive data from two connections. How this traffic is mixed to the "client connection"?
Yes.
No. BIND is separate from CONNECT. It is for when you want to listen, so you tell the server to listen on your behalf and tell him what port you're listening on.
Pass.
There is only one connection between the client and the SOCKS server. Everything arriving from the client is sent to the 'desired server'. Everything arriving from the 'desired server' is sent to the client. There is nothing to mix. You wouldn't want the client's sends to be sent back to him, would you?

Asynchronous Socket Programming

I've created a project using socket programming. If I connect a single client to my server, the data I send from my client is successfully received by the server. But whenever I connect more than one client, only one client's data is received by the server. The other clients fail to connect. How can I make the server accept all new incoming connections, and how can I make the server receive two files from the same client?
If your code uses BeginAccept, EndAccept methods to accept new connection asynchonously, don't forget to call again BeginAccept after EndAccept call in your AcceptCallback.
Regards

Resources