473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

socket.EndAccept(ar) is Exclusive....any way to change?

Hi, im making an AIM like server using TCP sockets, however i found a big
issue. when a socket is connected to (socket.EndAccept(ar)), its already
bound to a Port. since its bound, i cannot change its access to non
exclusive, but i need this port to still be open because i may need another
socket to connect on this port as well. how can i achieve this?
--
-iwdu15
Jan 2 '07 #1
9 2265
On 2007-01-02, iwdu15 <jmmgoalsteratyahoodotcomwrote:
Hi, im making an AIM like server using TCP sockets, however i found a big
issue. when a socket is connected to (socket.EndAccept(ar)), its already
bound to a Port. since its bound, i cannot change its access to non
exclusive, but i need this port to still be open because i may need another
socket to connect on this port as well. how can i achieve this?
You may need to explain this situation a little more clearly (maybe some short
code samples would be helpfull).

--
Tom Shelton
Jan 2 '07 #2
From what I remember of doing something similar a few years ago; You have a
'listening' socket and every time that socket detects an incoming connection
you open a new socket on a different port and make the connection on that
port. That way you can continue to listen on the original socket.

I don't have code samples to hand anymore i'm afraid.

HTH

"iwdu15" <jmmgoalsteratyahoodotcomwrote in message
news:FF**********************************@microsof t.com...
Hi, im making an AIM like server using TCP sockets, however i found a big
issue. when a socket is connected to (socket.EndAccept(ar)), its already
bound to a Port. since its bound, i cannot change its access to non
exclusive, but i need this port to still be open because i may need
another
socket to connect on this port as well. how can i achieve this?
--
-iwdu15

Jan 2 '07 #3
On 2007-01-02, Martin <ma****@myisp.comwrote:
From what I remember of doing something similar a few years ago; You have a
'listening' socket and every time that socket detects an incoming connection
you open a new socket on a different port and make the connection on that
port. That way you can continue to listen on the original socket.
You are correct, that is how it is supposed to work - except, you don't open a
new socket. A new socket is returned to you via the accept method. I think
the op is confused about this - and is actually trying to communicate with the
client using the server socket. But, I'm not quite sure - hence the request
for clarification and code demonstrating the issue.

Some people fine the TcpListener/TcpClient classes useful - but to be honest,
I prefer to use the Socket class directly. That's a personal preference,
probably developed out of problems/bugs I experienced during the early beta's
:)

--
Tom Shelton
Jan 2 '07 #4
right, thats my problem. a Socket is given to me by the function
EndAccept(..), this socket is already bound to a port, so i cannot change it
to non-exclusive. is there any way to change that?
--
-iwdu15
Jan 3 '07 #5
"iwdu15" <jmmgoalsteratyahoodotcomwrote
Hi, im making an AIM like server using TCP sockets, however i found a big
issue. when a socket is connected to (socket.EndAccept(ar)), its already
bound to a Port. since its bound, i cannot change its access to non
exclusive, but i need this port to still be open because i may need
another
socket to connect on this port as well. how can i achieve this?
Let's say you have a socket listening, on (for example) port 5222. You put
the socket into BeginAccept mode, and then out of the blue you get a
callback. In your callback method you call EndAccept, and get a reference to
a new socket (this is KEY!).

In the NEW socket, you call BeginReceive to start the whole receive process.
You now have a connected client.

On the original socket you call "BeginAccept()" again - this allows
additional users to connect. This algorithm is then repeated forever, and
you have a server that scales very well.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, MVP C#
http://www.coversant.net/blogs/cmullins
Jan 3 '07 #6
yea, i realize this much. however, what i was confused about was wouldnt the
server throw an error the next time a connection attempt was made? like if
you try to bind more than one socket to a port without saying it does not
have exclusive access, an error is thrown. so when you receive a connection
attempt, the socket handed to you by EndReceive(...) is automatically
non-exclusive?
--
-iwdu15
Jan 3 '07 #7
On 2007-01-03, iwdu15 <jmmgoalsteratyahoodotcomwrote:
yea, i realize this much. however, what i was confused about was wouldnt the
server throw an error the next time a connection attempt was made? like if
you try to bind more than one socket to a port without saying it does not
have exclusive access, an error is thrown. so when you receive a connection
attempt, the socket handed to you by EndReceive(...) is automatically
non-exclusive?
The socket handed to you by the EndReceive is a completly new and different
socket then the one that accepted the request. It is on a completly different
port, so you can have many client connect to the server sockets known port. The
conversation between the server and the client happens on the port allocated
to the new socket....

--
Tom Shelton
Jan 4 '07 #8
Hi,

"Tom Shelton" <to*********@comcastXXXXXXX.netwrote in message
news:17******************************@comcast.com. ..
On 2007-01-03, iwdu15 <jmmgoalsteratyahoodotcomwrote:
>yea, i realize this much. however, what i was confused about was wouldnt
the
server throw an error the next time a connection attempt was made? like
if
you try to bind more than one socket to a port without saying it does not
have exclusive access, an error is thrown. so when you receive a
connection
attempt, the socket handed to you by EndReceive(...) is automatically
non-exclusive?

The socket handed to you by the EndReceive is a completly new and
different
socket then the one that accepted the request.
That's right.
>It is on a completly different
port, so you can have many client connect to the server sockets known
port. The
conversation between the server and the client happens on the port
allocated
to the new socket....
That's wrong. The new socket uses the same server port. A TCP server can
have many clients connected to the same port. When (connected) clients sent
packets to the server, the TCP stack can distinguish the received packets
based on the source IP and source port which is part of the IP/TCP header
that is sent along.

HTH,
Greetings
>
--
Tom Shelton

Jan 4 '07 #9

Bart Mermuys wrote:
Hi,

"Tom Shelton" <to*********@comcastXXXXXXX.netwrote in message
news:17******************************@comcast.com. ..
On 2007-01-03, iwdu15 <jmmgoalsteratyahoodotcomwrote:
yea, i realize this much. however, what i was confused about was wouldnt
the
server throw an error the next time a connection attempt was made? like
if
you try to bind more than one socket to a port without saying it does not
have exclusive access, an error is thrown. so when you receive a
connection
attempt, the socket handed to you by EndReceive(...) is automatically
non-exclusive?
The socket handed to you by the EndReceive is a completly new and
different
socket then the one that accepted the request.

That's right.
It is on a completly different
port, so you can have many client connect to the server sockets known
port. The
conversation between the server and the client happens on the port
allocated
to the new socket....

That's wrong. The new socket uses the same server port. A TCP server can
have many clients connected to the same port. When (connected) clients sent
packets to the server, the TCP stack can distinguish the received packets
based on the source IP and source port which is part of the IP/TCP header
that is sent along.
Your are correct of course. My bad. It was too late at night for me
to be thinking clearly. The local end point of the new socket is the
same as the servers, it is differentiated by the remote endpoint - the
ip:port from which the connection originated.

--
Tom Shelton

Jan 4 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joachim | last post by:
This is the code example on the MSDN page for the Socket.BeginReceive function: allDone.Set(); Socket s = (Socket) ar.AsyncState; Socket s2 = s.EndAccept(ar); StateObject so2 = new...
7
by: Colin | last post by:
I'm writing a little console socket server but I'm having some difficulty. Can I ask your advice - where is the best place to get some help on that topic? It would be nice if some people who knew...
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
2
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless...
0
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
5
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for...
10
by: ThunderMusic | last post by:
Hi, I'm currently working with sockets. I accept connections using m_mySocket.Listen(BackLogCount); But when I want to stop listening, I shutdown all my clients and call m_mySocket.Close(), but it...
2
by: manasap | last post by:
Hi all! I've written a server and a client application using asynchronous sockets.The client sends data packets for every 7 seconds.The server receives the packets. This process proceeds...
1
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.