Register a domain and help support LQ
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-23-2005, 05:51 AM   #1
Registered: Mar 2005
Posts: 61

Rep: Reputation: 15
Help me ... about Socket programming..

Hi all,
Can i open two listening sockets to accept further new connections from other process, in a process....??? By using same IP address and two diffrent port... on a single a machine...

With Regard
Old 04-23-2005, 06:14 AM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
Yes, either fork() another process listening to the other port to prevent blocking on accept() one the first port, or use non-blocking sockets, and use select() to block until a new connection request arrives on either socket.

See "man select_tut" and "man select".

Last edited by Hko; 04-23-2005 at 06:15 AM.
Old 04-24-2005, 05:50 PM   #3
Registered: Jul 2004
Location: Spain
Posts: 111

Rep: Reputation: 20
You can open so many listening sockets as ports exist. There are 2^16 = 65536 different ports, so in theory you can open up to 65536 listening sockets, but don't worry, i think you cannot run such an amount of processes on your computer at the same time (at least you will be running other processes, so you can never reach that number). You can even open two sockets of different protocol families using the same port; e.g: opening an UDP socket and a TCP socket, but remember that UDP sockets can't listen.


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 programming iiit Programming 2 07-05-2005 05:02 PM
socket programming???? harbir Linux - Networking 2 07-05-2004 03:52 AM
want help in socket programming valib4u *BSD 2 09-12-2003 12:17 AM
Socket Programming cxel91a Programming 4 03-19-2003 11:05 AM
socket programming herambshembekar Programming 3 04-13-2002 04:13 PM

All times are GMT -5. The time now is 06:45 PM.

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