ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i am using UDP sockets to communicate between client and server i am using c programming in linux.........my problem is that when i send the first message to the server it reaches the serverand the server sends a reply but when i send the same message again to the server it gives me "cannot bind the port" error........
is there any way to free the socket so that it can bind the thing again.....or is there any other way to do it
Is the socket being destroyed after the reply, somehow?
Does the program end and then you start it again right away? In school, I had to wait a minute or so before re-running the client so the server could free the port I was using.
the thing is i am trying to make the server and the client communicate both ways.....so after the client send the message to the server and after the server send reply to the client....if the client tries to send message to the server again it shows error
??: sending data to '192.168.0.8' (IP : 192.168.0.8)
??: sending data to '192.168.0.8' (IP : 192.168.0.8)
cannot bind port number 1501
Why are you binding more than once? Your program should bind the socket once after the socket is created, and that's it - just keep checking it for new packets.
You can only bind the same socket once, you must close it and create another one before bind it again, you can use the same variable. But remember the kernel delay, try to use the same bound socket in order to avoid two near bind calls.
Like Cromagnon and Nerox stated, you can and only need to bind a port to an address once. Once the port is bound, you can send and recieve until you want to close the connection and free up the port. That should fix your problem.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.