LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-22-2008, 12:30 AM   #1
sweetytweety
LQ Newbie
 
Registered: May 2008
Posts: 17

Rep: Reputation: 0
port reuse problem :TCP socket


hi,
socket programming im using infinte loop to send and receive between client and server.so if i want to quit from server i have to use ctrl+c or(ctrl+z) to come out. Then next time i try to run the program , im getting the error "Could not bind listener socket to port". Im closing my socket at the end of progrm. (if i press ctrl+c,my socket should close so that i can reuse the same port for anytime i want). how to make the port reusable?
 
Old 05-22-2008, 05:05 AM   #2
digvijay.gahlot
Member
 
Registered: Mar 2008
Posts: 53

Rep: Reputation: 15
You quit the server by CTRL+C/CTRL+Z so the port remains open.

What is generally done is that we pass messages from client to server. At the end of the program we send some string or some token to indicate that we want to terminate.
A simple algo will be
SERVER::
while(1)
{
receive message from client;
if( message says "end")
break;
else process the message;
}
close(socket);

CLIENT::
while(1)
{
Get the message user wants to send to server, enter "end" to exit.
send the message to the server.
if(message is "end")
break;
}
close(socket);

By this sockets close gracefully. By CTRL+C/CTRL+Z program ends without closing the sockets.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket reuse ed.poore Programming 5 02-14-2007 05:42 PM
TCP socket problem maprich Linux - Networking 1 05-08-2006 01:50 PM
Problem to transfer binary file over TCP socket yhus Linux - Networking 3 02-28-2006 09:41 AM
filetransfer with socket and tcp biiiep Programming 2 06-11-2004 01:33 PM
close port 6000/tcp 515/tcp SchwipSchwap Linux - Newbie 1 09-12-2002 09:24 AM


All times are GMT -5. The time now is 10:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration