I have a server.c I can connect to it if I know the port that I assign to the server; lets say 6000. I go to FireFox and type 127.0.0.1:6000 and I can connect perfectly.
How do I build my server that a client will type 127.0.0.1 on a browser and then the server will assign the port or notify the user on the browser to type the port?
Perhaps I don't fully understand servers but it seems to me that the client must know the port from the get-go.
You need a port to connect. HTTP connects to port 80 by default and that's why you can get away by typing 127.0.0.1 into your browser.
The default standard port is 80 for an IP in a browser. Maybe your program (server.c) waits a request with the default port 80, and transfer the request into another user-defined port.
Related
I use WSAConnect to connect to a server whose site has the prefix http: \ That is, it seems like the remote server should connect only on port 80. But, in fact, I see that for some pages of this http site - WSAConnect completes successfully on port 443.
Is it okay? Is this allowed?
WSAConnect is for low-level socket communication, for example low-level TCP/IP sockets.
Web servers use HTTP for communication with clients, such as browsers. HTTP is an application protocol on top of TCP/IP.
By default web servers use port 80 for plain HTTP communication. Webservers can also support HTTP over a secure connection (HTTPS). The default port for this is 443.
So it is perfectly fine for a web server to be reachable on port 80 and 443.
In general, a single server can be reachable on any number of ports. Different ports are used for different protocols.
I'm creating my custom http server in C. sockaddr_in looks like this:
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(8080);
my_addr.sin_addr.s_addr = htol(INADDR_ANY);
And my question is how I can send my request without writing port after address.
For example 192.168.1.100 instead of 192.168.1.100:8080 or mydomain.loc instead of mydomain.loc:8080
how I can send my [HTTP] request without writing port after address[?]
You cannot communicate with a TCP endpoint without designating a specific port. Various kinds of services have conventional (default) ports, however, and oftentimes client software will use a service's conventional port if the user does not explicitly specify one.
The conventional port for the HTTP protocol is 80. If your server runs on that port, then it is likely that HTTP user agents such as web browsers will not require you to specify that port; instead they will silently insert it for you. You will need root / administrator privilege on the server machine to run the server software on port 80, or on any other port less than 1024.
If you want to access your custom server with any web browser then you must have to specify the listening port of your custom server because every browser will consider a server listening on port 80 on the address (URL) you provided.
how I can send my [HTTP] request without writing port after address[?]
And if you want to provide only the host IP address and using the 8080 port as default listening port of your server, you can make a simple custom client. Pass the host URL i.e. 192.168.1.100 to that client. In the body of client, connect the socket to 192.168.1.100 and 8080 address. Client will send query to your custom server and will save the reply in .html file. You can then open this file with browser.
I am developing a private chat application. My Server side code(NodeJs + Express + Socket.io) is running on port 7000. And my client side code(AngularJs) is running on port 8000.
When I am trying to connect my socket client(running in port 8000) to socket server(which is running on port 7000), I am getting 404, which is obvious.
I have following questions related to this:-
I am now unable to figure out how I can make Socket client # port 8000 listen/get connect to socket server # port 7000.
Will there be any impact on all this configuration if tomorrow in production I will introduce Ngnix which will be running on port 80?
Thanks,
Vikram
Found the solution.
Instead of include socket.io in your HTML as :-
You can also include it as
I'm making a DNS client and connecting it to a server. Whenever I provide port number 53(default for DNS server) it works fine.. But, whenever I provide port number 5300, the program freezes. Port number 5300 is asked to provide in the question for which I'm doing this code.
So, can anybody help why does my client freezes when I provide port 5300?
I'm using C language.
Thanks
Without looking at your code, I can't be 100% certain. I'm assuming that when you say you switch to port 5300, you're setting in both the client AND the server. Also, is the port listening on the server UDP instead of TCP? If you haven't already, try running netstat on your server to see what ports it is listening on.
I am trying to write a TCP proxy in c. The server only works with non-ephemeral ports. The proxy is trying to mount a file-system. So when I call the mount command by-passing the proxy it chooses an appropriate port and it connects. But when I try to connect via the proxy an appropriate port is selected for the connection between the client and the proxy, but the proxy uses an ephemeral port when it connects to the server.
I have read that it is not wise to specify a port, so I am looking to define a range of ports for it to choose from. Is this possible?
Any advice and help is appreciated. Thanks.
I figured it out. I needed to bind to a reserved port prior to running the connect to the server.
use bindresvport(3) with the server socket.