Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
Questionnewbie seeks guidance on how use IDE Pin
wheels4me6-May-06 13:16
wheels4me6-May-06 13:16 
AnswerRe: newbie seeks guidance on how use IDE Pin
led mike6-May-06 13:51
led mike6-May-06 13:51 
AnswerRe: newbie seeks guidance on how use IDE Pin
Josh Smith7-May-06 4:51
Josh Smith7-May-06 4:51 
Questionhow to use progressbar ? Pin
hdv2126-May-06 12:22
hdv2126-May-06 12:22 
AnswerRe: how to use progressbar ? Pin
ekynox6-May-06 14:28
ekynox6-May-06 14:28 
QuestionBeginReceive problem (Sockets question) Pin
tmp06-May-06 10:56
tmp06-May-06 10:56 
AnswerRe: BeginReceive problem (Sockets question) Pin
led mike6-May-06 13:45
led mike6-May-06 13:45 
AnswerRe: BeginReceive problem (Sockets question) Pin
Shy Agam6-May-06 22:44
Shy Agam6-May-06 22:44 
Hello tmp0...

When using Socket's async functions it's important to call the EndX methods inside your callback functions...

In BeginAccept()'s case, you have to call EndAccept(), which will return a new CONNECTED socket.
Only then could you take the listener object you've created, and call BeginAccept() again.

With that said, your myOnConnect() callback should look something like that:
public void myOnConnect(IAsyncResult ar)
{
    OnConnect(myId);
    try
    {
        //Get the connected socket.
        Socket sock = listener.EndAccept(ar);
        //Release the old listener object
        listener.Close(); //Or whatever works for you.

        if (sock.Connected)
        {
            AsyncCallback recieveData = new AsyncCallback(myOnReceive);
            sock.BeginReceive(m_byBuff, 0, m_byBuff.Length, SocketFlags.None, recieveData, sock);
        }
    }
    catch(Exception e)
    {
        MessageBox.Show("Err: "+e.ToString());
    }
    //Reinstantiate listener (Assuming you've released it)
    listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

    listener.BeginAccept(new AsyncCallback(myOnConnect), listener);
}

Hope this helps...
Tell me the results Smile | :)

Shy

-- modified at 4:52 Sunday 7th May, 2006
GeneralRe: BeginReceive problem (Sockets question) Pin
tmp07-May-06 2:53
tmp07-May-06 2:53 
QuestionTime stamp in applications Pin
_tasleem6-May-06 10:49
_tasleem6-May-06 10:49 
AnswerRe: Time stamp in applications Pin
led mike6-May-06 13:33
led mike6-May-06 13:33 
QuestionListBox Event Pin
Sean896-May-06 10:48
Sean896-May-06 10:48 
AnswerRe: ListBox Event Pin
led mike6-May-06 13:30
led mike6-May-06 13:30 
GeneralRe: ListBox Event Pin
Sean896-May-06 17:26
Sean896-May-06 17:26 
QuestionDragDrop() Event Handler assistance needed... Pin
new_phoenix6-May-06 10:33
new_phoenix6-May-06 10:33 
AnswerRe: DragDrop() Event Handler assistance needed... Pin
rudy.net7-May-06 4:11
rudy.net7-May-06 4:11 
Question.m4a Tag Reader Pin
4324235423534253425135143532456-May-06 9:36
4324235423534253425135143532456-May-06 9:36 
Questionwhere can i find ngen.exe? Pin
Susuko6-May-06 8:18
Susuko6-May-06 8:18 
AnswerRe: where can i find ngen.exe? Pin
Ravi Bhavnani6-May-06 9:05
professionalRavi Bhavnani6-May-06 9:05 
GeneralRe: where can i find ngen.exe? Pin
Susuko6-May-06 9:44
Susuko6-May-06 9:44 
GeneralRe: where can i find ngen.exe? Pin
Ravi Bhavnani6-May-06 9:52
professionalRavi Bhavnani6-May-06 9:52 
QuestionConvert a file to stream Pin
QzRz6-May-06 6:42
QzRz6-May-06 6:42 
AnswerRe: Convert a file to stream Pin
DigitalKing6-May-06 6:48
DigitalKing6-May-06 6:48 
GeneralRe: Convert a file to stream Pin
QzRz6-May-06 6:54
QzRz6-May-06 6:54 
AnswerRe: Convert a file to stream Pin
S. Senthil Kumar6-May-06 7:28
S. Senthil Kumar6-May-06 7:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.