![]() |
| | #1 |
| Registered User Join Date: Apr 2005
Posts: 134
| Using a single socket for accept() as well as connect()? How can a single socket be used to accept() as well as to connect().? Is it possible and what is the best way to implement it? Any sample code would be helpful. Here is what I want to do. Open a socket on a port and accept() on it for a certain amount of time. If a connection is received in that time from the remote peer then send/recv with new socket descriptor. Otherwise, attempt a connection to the remote peer using the same socket and once established, start send/recv. I am developing on linux. Thanks, |
| nkhambal is offline | |
| | #2 |
| Unregistered User Join Date: Sep 2005 Location: Antarctica
Posts: 341
| what do you mean by attempt a connection using the same socket? You can use the same variable name but you can't create a listener socket and then turn around and try to use it as a client socket with the same socket identifier. Just create a new socket to connect, I don't understand why that would be a problem. |
| rockytriton is offline | |
| | #3 |
| Registered User Join Date: Apr 2005
Posts: 134
| yeah, creating 2 separate sockets was my way out of this problem. I thought may be someone else might have some better solution than that. I guess not. I have no choice but to go ahead with 2 separate sockets. |
| nkhambal is offline | |
| | #4 |
| Registered User Join Date: Nov 2002
Posts: 491
| Why is that a problem in the first place? Sockets are very lightweight in just about any OS, and if you want 1 socket for 2 things then you are not going to be using the same socket to accept still so you can just close it and it gets freed anyways. |
| orbitz is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| socket programming question, closing sockets... | ursula | Networking/Device Communication | 2 | 05-31-2009 05:17 PM |
| My socket attempt refuses to connect | kzar | C Programming | 3 | 06-01-2005 04:15 AM |
| socket connect returning odd | WaterNut | C++ Programming | 5 | 05-10-2005 08:49 PM |
| single Socket for listening and sending/receiving, Simultaneously? | Aidman | Networking/Device Communication | 10 | 10-01-2003 11:17 PM |
| socket newbie, losing a few chars from server to client | registering | Linux Programming | 2 | 06-07-2003 11:48 AM |