473,465 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need help with socket problem - any ideas ?

why does this codesnippet block until the acceptcallback
has completed. According to the microsoft documentation
the beginaccept callback method executes in a separate
thread, and is called immediatly after BeginAccept
returns. I am trying to authenticate the client in this
callback. What am i doing wrong ?

sing System;
using System.Net;
using System.Text;
using System.Net.Sockets;
namespace SocketProblem
{
public class MainX
{
private static void StartListening()
{
IPEndPoint localEndPoint = new
IPEndPoint(IPAddress.Loopback, 5555);
Socket listener = new Socket
(AddressFamily.InterNetwork,SocketType.Stream,
ProtocolType.Tcp);
listener.Bind(localEndPoint);
listener.Listen(1000);
listener.BeginAccept(new
AsyncCallback(AcceptCallback),listener);
}

// blocks until this method completes!
private static void AcceptCallback
(IAsyncResult ar){
Socket listener = (Socket)
ar.AsyncState;
Socket handler = listener.EndAccept
(ar);
listener.BeginAccept(new
AsyncCallback(AcceptCallback),listener);
handler.Send(Encoding.UTF8.GetBytes
("Welcome\r\n"));

//etc etc
byte[] buffer = new byte[512];
handler.Receive(buffer);
//etc etc
}

[STAThread]
static void Main(string[] args)
{
StartListening();
Console.WriteLine("Press <enter>
to stop");
Console.ReadLine();
}

}
}

Nov 16 '05 #1
0 983

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

Similar topics

3
by: Gordon Scott | last post by:
Hi All, I've got a problem I'm seeing when trying to use the struct module to send data to a different machine. Actually I'm making a condensed file that gets transferred to and read on a BREW...
9
by: Phil Jenson | last post by:
I am try to evaluate the most efficient method of handling thousands of simultaneous TCP connects each of which remain connected to the server for hours and pass a small amount of data usually once...
5
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a...
2
by: darthghandi | last post by:
I am trying to pass a socket object when an event is signaled. I have successfully bound to a network interface and listened on a port for incoming connection. I have also been able to accept...
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
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.