Port number 5300 not woking in DNS client - c

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.

Related

C: Why does this server / client setup only work inside one computer?

I'm new to networks and I'm wondering why this TCP Server-Client implementation in C
only works on one computer? (1)
I mean I have to open one terminal for the server program and another one for the client program. But why this doesn't work between computers? Starting the server program on one computer and the client program on another computer.
How we need to modify the code to work between computers? (2)
And what are great resources to start on the whole topic? (3)
It will work on other computers.
Just ensure you do the followings:
Two computer be on a network and see each other with PING
Change 127.0.0.1 in client program with the IP of the server machine
Check listening ports with netstat of server machine and Make sure the port 8080 is in Listening mode
Make sure there is no firewall in server machine, you can use telnet in client machine to make sure port on the server is accessible.
Before test your C program, make sure the communication is OK between servers by third party application. For example, make an echo server in linux by ncat -l 2000 -k -c 'xargs -n1 echo' on port 2000.
It highly recommended change Port from 8080 to another one (for example 8192). 8080 is used with some third party applications.
The host used by the client is hardcoded:
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
You can change the host into the code to reach another computer, or you can read it from command line to have a more flexible use.

SQL client seems to be using random port to connect

Sorry if this is not the place to ask, but I am not sure if there is a forum for SQL port questions. It seems that my SQL client is using a random port to connect to the SQL server, in spite of me stipulating a specific port in the ODBC DSN connector. this is from Microsoft Network Monitor I have included the image to better illustrate what I mean.
You are reading it wrong. I see two kinds of connections, from WEBSERVER to 192.*.6 which I assume to be the Sql Server (the requests), and vice versa (the responses from Sql back to the Web Server).
When WEBSERVER is making a request, the DstPort is always 49252. The SrcPort fluctuates in that case because that is just how TCP/IP works (and that is also how multiple parallel connections can be distinguished). The Sql Server then always replies to whatever port number initiated the request.
It is expected that the source port (client) be random. The destination port (server) will be constant. When a TCP/IP client connects, it chooses an unused client port and connects to the server listening on a known port. This is basically how TCP/IP sockets work.

Setting a range for ports for a client side connection in c

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.

Getting the port number of a server through a browser

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.

Can two processes on same machine connect to the same port?

I have a few basic questions about sockets programming. I am trying to write a program (in C, linux) in which several client processes connect to a server process and also the clients need to connect to themselves. Though the clients would reside on separate machines, them being on the same machine is also a case. These are my questions.
Can two client processes communicate with each other on the separate port? In that case none of them listens to a port (like how the server does). They just connect to a port using a socket and talk to each other. Is that possible?
If not, how can I make communication between the clients?
Any idea on this would be of help. Thanks.
no, in TCP this is not possible. When establishing the connection in TCP, you are always connecting to listening port, so one of the clients must listen.
one of the clients needs to open listening port, but which one? Use the server as an arbiter! Employ a protocol where server moderates:
server decides which client will open the port
that client opens the port, listens to it and sends its address (host:port) to the server
servers sends it to the other client
the other client can connect now!
And if you were asking if two processes can listen on the same port on the same machine, then the answer is no. But using the above protocol you can avoid this situation.
A socket connection always needs a connecting and a listening side - one side needs to listen. Have one client process create a listening port and the other connect to this port.
If you want to make clients to communicate each other, make use of a server which listens on a port and directs to the other client nothing but to direct to right clients.
If you dont want to use a server, then in you client application u have to make one port for listening and another port for spitting data. So it will be only one-one talking.
If I'm correct for the answer you are looking for: Yes, two processes on same machine can connecto to same port. It is nothing but two different entities trying to connect to a server.

Resources