![]() |
|
#1
|
|||
|
|||
Socket Programming questionsI am developing a socket application using C++ "winsock API" obviously on Microsoft Windows platform, this application should listen on two different ports e.g. 666 and 999, and it will behave differently according to which connection it receives from which port.
So how can I do this?, should I divide my application into two different applications or is there a more cleaner/cooler/neat solution other than this? Thanks alot in advance |
|
#2
|
|||
|
|||
Re: socket programming questions?there are two approaches to this: you can use threads, or you can use non-blocking sockets.
for threads, you would create two threads that would each listen on one of those ports, with their own sockets. the problem would be how to terminate the other thread when you got a connection. For non-blocking sockets, you create a socket for each port, but you call a special function, ioctlsocket (with the value FIONBIO), to make it non-blocking. Now, instead of calling accept() and having your program hang, you call bind() and listen() on both sockets as normal, but then you call select() with the two sockets in the readfds set. That way, select() will tell you when either socket is ready to be accept()ed. |
|
#3
|
|||
|
|||
Re: socket programming questions?Unless you're dying to use WINSOCK, take a look at nsoftware.com's IP*Works! product(s). They make all sorts of socket programming and related protocols a breeze.
:davis: |
|
#4
|
|||
|
|||
Re: socket programming questions?thanks Davis but its commercial
|
|
#5
|
|||
|
|||
Re: socket programming questions?Quote:
...all the more reason to use well-proven/tested commercial third party royalty-free libraries. The length of time you spent debugging your WINSOCK code will pay for the library. In addition, writing your "daemon" class for SMTP is a total breeze. See the documentation on IPDaemon and IPPort. They are incredibly easy to use. CPP / C++ / C Code:
...this is a simplified example of how easy it is to implement a daemon/server using IP*Works!. Note that you could very easily SetLocalPort to 25 and handle your incoming FireDataIn events within a FSM. Note that I SetLocalHost simply because my dev machine has several Ethernet cards, and the "handling" of multiple NICs is a bit "different" so it is just easier to specify the host address. :davis: |
Recent GIDBlog
Halfway done! by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Student programming questions | Shawn | Miscellaneous Programming Forum | 1 | 02-Apr-2007 21:31 |
| [PROGRAM] Winsock Programming | Max Payne | MS Visual C++ / MFC Forum | 1 | 08-Mar-2007 23:38 |
| A few questions for someone in the programming industry. | WAEvans | Miscellaneous Programming Forum | 0 | 08-Oct-2006 09:19 |
| Couple of Socket Questions | nugol | C++ Forum | 2 | 26-Aug-2006 12:38 |
| Where to go for Registry editing and socket programming ? | realnapster | C++ Forum | 2 | 08-Feb-2006 08:54 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The