I have a server that can communicate (Python) with its serial port. However, I want that anybody accessing this server from a web socket receives a website based on data from the server's serial port. So a (http?) request from the client should cause the server to get data from the serial port (I know how to communicate in python with the serial port) and then respond to the client based on that data.
I have implemented a basicpython socket that can get requests by a server and then get the data from its serial port. But how do I send to the Webbrowser client a response (that must be HTML, right?) based on that data? So hardcoding a whole Webserver would be too much, right? What's the best way to to this in python?
Related
A server, say for example an FTP server is listening on a port 21. Multiple clients can connect to it simultaneously and get ftp services asynchronously without being blocked.
My assumption is that the server has a separate thread to handle each client request. (Question: Does the new thread start negotiating new port with this client or continue using the same port (21) for data exchange ?)
my understanding is that the server uses a single port (21) to serve all the clients, including new connection requests.
if that is the case how does the server using a single port differentiates between clients and how does it delegate relevant data for each relevant thread ?
The same was as any other TCP/IP server.
Each client have a unique IP address and/or a port number.
The combination of client address and port and server address and port creates a virtual channel. The channel is used to exchange data between client and server software running on different machines. This is typically built into OS. The client and server software does not have to handle it specifically.
In short we have two separate servers for our web app. The first one is the main server that uses Websockets for handling "chat rooms", and the second server only handles WebRTC audio chat rooms via Websocket. Both servers use Express to create a HTTPS server, use secure Websocket and the port 443.
I recently encountered a problem where a corporate client's firewall blocked the wss-connection to only the WebRTC server. The error logged in the user's browser was "ERR_CONNECTION_TIMED_OUT", which means the user never connects via Websocket. This has not happened with any other clients.
The Websocket connection works normally between the user and the main server, and no rules have been added to their firewall to use our app.
Has anyone encountered something similar? What kind of a firewall setting might cause this? Could this be a cors problem, since the servers are on their own sub-domains?
The main server could be restricting the type of data sent on port 443, which will use SSL to secure that transmitted data.
Refer to this page for information on the "Well-know port numbers".
The WebRTC audio data may need to be transmitted on its own dedicated port number that has been configured on the main server for this.
The problem was that the main server WebSocket used TCP and the WebRTC server used UDP, and UDP was blocked by corporate firewall on default.
WebRTC should use TCP as a backup, but I'm assuming UDP is still needed for the handshake.
I know already about the web-sockets, and they are great, the problem with them is that they have to keep the connection open in order to be able to communicate.
I have a small system where from time to time the server has to update the status and notify the clients about that, and keeping the connection open from every client is not so optimal. At same time is very important that the update on the client side to be made just in time.
So my question is, if the server has a unique address does the client have a public temporary address where the server can send request? So when the client will connect to the server it will provide it's unique address and the server will cache it, and when there will be an update the server will send the request to that address?
I understand that there many problems as the address will constantly change, but this is already other question.
If client does not have a dedicated IP-address then it is not available from WAN unless it has an open connection with any node in it.
When client from local network sends request to a server it's (client's) router remembers client's local IP-address and port and translates it using NAT protocol to one of router's free ports and then sends data further with router's own 'IP-address of the sender' in IP protocol header and 'Sender's port' in TCP header. When router get's server's response it uses NAT table from it's memory to translate addresses back and deliver data to the client. Addresses are normally kept in NAT table while connection between server and client is open. So if there are no opened connections between server and local network client then server will not be able to connect with client because server does not know how to reach it.
You say you have a small system. Why then do you think that you will not have enough free ports at your server to work with websockets? If you just want to get updates from the server (not to both send and get data through a persistently opened connection) you'll probably find long polling or SSE more suitable. It is definitely easier to implement than websockets.
I am trying to develop a lan chat application. As I looked for the topic, I found that whatsapp, viber etc. use a server which controls all the traffic. The server tells the status of devices and manage all traffic etc. So, what am I trying to know is :
How the server gets the info of devices like, IP address, MAC address etc?
How the data is transferred from one client to server and then server to another client?
Which language should I use server side?
As shown in image, I want to connect two devices, A and B and interchange data between them.
Actually, I'm not sure data always through the server. From what I know, the client logs in at the server the first time it connects only. If client A wants to send a message to client B, it retrieves the IP corresponding to username_B from the server, then exchange of data is done directly between client.
What you should do is to develop a protocol to login at the server and register the client IP, and to retrieve an IP from a username.
For the routers between server and clients, I think it is out the server scope, you just need for NAT.
With regards to the problem Bart is having in NAT router blocking JMS messages
I am trying to find the port number that clients receive openJMS messages on. After searching for ages on the web I can only find information about the server ports, nothing on the client. This is for a tcp connection.
If anyone can point me in the right direction I would be very grateful.
Thanks!
In general, the client port number will be different for each new connection. I could find no evidence that OpenJMS clients use specific port numbers when communicating with servers. Here are a few explanations.
Port Numbers
When a client process first contacts a server process, it may use a
well-known port number to initiate communication. Well-known port
numbers are assigned to particular services throughout the Internet,
by IANA, the Internet Assigned Numbers Authority. The well-known port
numbers are in the range 0 through 1023.
Well-known ports are used only to establish communication between
client and server processes. When this has been done, the server
allocates an ephemeral port number for subsequent use. Ephemeral port
numbers are unique port numbers which are assigned dynamically when
processes start communicating. They are released when communication is
complete.
TCP/IP Client (Ephemeral) Ports and Client/Server Application Port Use
In contrast, servers respond to clients; they do not initiate contact
with them. Thus, the client doesn't need to use a reserved port
number. In fact, this is really an understatement: a server shouldn't
use a well-known or registered port number to send responses back to
clients. The reason is that it is possible for a particular device to
have both client and server software of the same protocol running on
the same machine. If a server received an HTTP request on port 80 of
its machine and sent the reply back to port 80 on the client machine,
it would be sending the reply to the client machine's HTTP server
process (if present) and not the client process that sent the initial
request.
To know where to send the reply, the server must know the port number
the client is using. This is supplied by the client as the Source Port
in the request, and then used by the server as the destination port to
send the reply. Client processes don't use well-known or registered
ports. Instead, each client process is assigned a temporary port
number for its use. This is commonly called an ephemeral port number.
Similar answer on another question: How to decide on port number between client and server communication on internet:
Also, a client can connect to many servers on the same port. When the
clients connect, they will use a random port on there end.
Only the server needs to worry about using a free port, and the
clients need to know what this port is else they will not be able to
connect to your server.
Other possible help:
How to find number of ephemeral ports in use?