473,804 Members | 3,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BeginAccept doesn't work

Does anyone know why the BeginAccept doesn't work? If, in the code
below, I do the normal Accept function I can get the client socket but
it seems that the callback isn't really called.
Here's the code:
-----------------------------
private Socket socket;
private Socket clientSocket;

public TcpServer(strin g serverIP,int serverPort)
{
clientSocket=nu ll;
socket=new
Socket(AddressF amily.InterNetw ork,SocketType. Stream,Protocol Type.Tcp);
IPEndPoint ep=new IPEndPoint(IPAd dress.Parse(ser verIP),serverPo rt);
socket.Bind(ep) ;
socket.Listen(1 0);
socket.BeginAcc ept(new AsyncCallback(A cceptConnection ),socket);
}

private void AcceptConnectio n(IAsyncResult ar)
{
Socket socket=(Socket) ar.AsyncState;
clientSocket=so cket.EndAccept( ar);
//throw new Exception("TCP Accepted on
#"+clientSocket .RemoteEndPoint .ToString());
throw new Exception("Yuhu u");
}

Jan 27 '06
11 3709
Funny, this is what I told you what happened to your object and what you
could do to solve this issue in the other thread of yours, but in that same
thread you said:
<
None of the solutions actually worked but creating a thread and
determining if the client is connected (through a function) worked now.

, mind to share what you did exactly?

Willy.

"Nuno Magalhaes" <nu************ @hotmail.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
| It works now. It was the GC that was marking the server object to be
| collected. It didn't detect that the callback was present.
|
| Writing a bit more of my RTSP server solved this problem, in a simple
| thread on RTSPServer.cs.
|
| Jon wrote:
| > Nuno Magalhaes <nu************ @hotmail.com> wrote:
| > > It's a really short program cause it's the beginning...
| > >
| > > The form: http://pwp.netcabo.pt/0141404701/RTSPServer.cs
| > > The server: http://pwp.netcabo.pt/0141404701/TcpServer.cs
| > >
| > > If you could help me I would be really appreciated... doing an Accept
| > > on TcpServer.cs does accept the client (like Internet Explorer
| > > "http://localhost:555/") so it's not from any firewall or antivirus.
| >
| > Well, I'm not sure why there's a difference between Accept and
| > BeginAccept, but if you change the socket address to IPAddress.Any, it
| > works fine. I suspect the problem is that it's not listening on the
| > loopback address if you just specify the actual network interface
| > address.
| >
| > --
| > Jon Skeet - <sk***@pobox.co m>
| > http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
| > If replying to the group, please do not mail me too
|
Jan 28 '06 #11
Yes, you were right. Using the object elsewhere in the code makes the
object unavailable for GC and the BeginAccept then works inside the
TcpServer object.

Willy Denoyette [MVP] wrote:
Funny, this is what I told you what happened to your object and what you
could do to solve this issue in the other thread of yours, but in that same
thread you said:
<
None of the solutions actually worked but creating a thread and
determining if the client is connected (through a function) worked now.

, mind to share what you did exactly?

Willy.

"Nuno Magalhaes" <nu************ @hotmail.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
| It works now. It was the GC that was marking the server object to be
| collected. It didn't detect that the callback was present.
|
| Writing a bit more of my RTSP server solved this problem, in a simple
| thread on RTSPServer.cs.
|
| Jon wrote:
| > Nuno Magalhaes <nu************ @hotmail.com> wrote:
| > > It's a really short program cause it's the beginning...
| > >
| > > The form: http://pwp.netcabo.pt/0141404701/RTSPServer.cs
| > > The server: http://pwp.netcabo.pt/0141404701/TcpServer.cs
| > >
| > > If you could help me I would be really appreciated... doing an Accept
| > > on TcpServer.cs does accept the client (like Internet Explorer
| > > "http://localhost:555/") so it's not from any firewall or antivirus.
| >
| > Well, I'm not sure why there's a difference between Accept and
| > BeginAccept, but if you change the socket address to IPAddress.Any, it
| > works fine. I suspect the problem is that it's not listening on the
| > loopback address if you just specify the actual network interface
| > address.
| >
| > --
| > Jon Skeet - <sk***@pobox.co m>
| > http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
| > If replying to the group, please do not mail me too
|


Jan 28 '06 #12

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

Similar topics

149
25221
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
0
341
by: Joachim | last post by:
When closing down my server I get the following exception An unhandled exception of type 'System.InvalidOperationException' occurred in system.dll Additional information: AcceptCallback I beleive that it is the asynchronous BeginAccept call which causes the
1
7071
by: scott | last post by:
Hi all hope some one can help me with this prob because it is really annoying me and I can't seem to solve it. Just like to say thx to any one that can offer any help. Ok the prob. I have a server which accepts new connections using the Socket.BeginAccept() function. This is done in its own thread using the following code.
1
6296
by: Chris Morse | last post by:
WARNING: Verbosity: skip to the very bottom paragraph for succinct version of my question.) Hi- I can't seem to find an answer to this. I am playing around with a variation of the ".NET Framework Developer's Guide" (in the MSDN docs) "Using an Asynchronous Server Socket" sample. As usual with docs like this, the example isn't very good. I had to
4
1845
by: Nuno Magalhaes | last post by:
One thing I've noticed is that if I try that code on a simple form load event it works ok like this: ....form load event... Socket socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); IPEndPoint ep=new IPEndPoint(IPAddress.Parse(serverIP),serverPort); socket.Bind(ep); socket.Listen(10); socket.BeginAccept(new AsyncCallback(AcceptConnection),socket);
5
12808
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 more incoming connections and does the BeginAccpet() again. It does an infinite loop this way. My question is: What is the best way to stop this? I thought about putting a boolean in there, but then what if it's still waiting for an incoming...
10
4470
by: Clayton | last post by:
Hi all, I'm trying to develop a server that listens to incoming calls using the asycnhronous methods BeginAccept / EndAccept. I start the server (till this point it is ok) and few seconds later I stop it (with no clients connected). Once I press the stop button an ObjectDisposedException is fired. What is the reason for this? Is it because the thread is still running even after I closed the server socket? Here is the code:
39
5878
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
0
9704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9569
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7608
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.