1832994 Members
2780 Online
110048 Solutions
New Discussion

Socket program - Problem

 
Vasudevan MV
Frequent Advisor

Socket program - Problem

Hi,

I have a socket program (client & server) which will broadcast a message from client to server. In both of the program, port no 1500 is allotted for this socket purpose. However the server side is getting terminated after sometime, giving the error "cannot bind port". Can any one tell me What could be the reason? & how can we check what are all the ports that are currently engaged by some other process?.

Thanks
Vasu
5 REPLIES 5
Steven Sim Kok Leong
Honored Contributor

Re: Socket program - Problem

Hi,

Use either netstat or lsof (more reliable) to identify whether the port is still in use:

# netstat -f inet | grep TCP | grep 1500

# lsof -i | grep TCP | grep 1500

You can get a copy of lsof from:

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/lsof-4.61/

Once you identify the process binding to the TCP port 1500, you can send a SIGTERM or SIGKILL to it so that the port is released. You can perform another lsof after the kill to verify the release.

Hope this helps. Regards.

Steven Sim Kok Leong
Magdi KAMAL
Respected Contributor

Re: Socket program - Problem

Hi,

Check your /etc/services to fetch out all already programmed port numbers allocated to be used.

Then, use the following command :

# netstat -a

to display active and passive ports and look if any of them is already in use ( ie. 1500 ).

Magdi
Steve Steel
Honored Contributor

Re: Socket program - Problem

Hi

Your port is locked by something else
"cannot bind port". already in use


netstat -an is a good way to look but best is get lsof from the public domain

www.software.hp.com

public domain software

lsof


steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Steve Steel
Honored Contributor

Re: Socket program - Problem

The HPUX Porting and Archive Center (http://gatekeep.cs.utah.edu)
has an 'lsof' command available to download. Go to:

http://hpux.cs.utah.edu/hppd/hpux/Sysadmin

and select 'lsof-4.45' from the list. The description is included below (and
there are 10.20 and 11.00 binaries available to download).

DESCRIPTION of LSOF:
-----------------------------
List files, sockets, etc opened by processes. Also gives a large amount of
other related information. Can select by process ID, username or filename. It
is a complete redesign of the fstat/ofiles utilities. This release now has lots
of additions and bug fixes including support for HP-UX 11.X.


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Steven Sim Kok Leong
Honored Contributor

Re: Socket program - Problem

Hi,

I made a slip on the netstat portion.

It should be:

# netstat -a | grep tcp | grep 1500

Instead of:

# netstat -f inet | grep TCP | grep 1500

The -a option will show the sockets in listen mode in addition to establishing or established connections.

Hope this helps. Regards.

Steven Sim Kok Leong