views:

519

answers:

1

Hello,

I tried to send a packet on the socket I use to listen for connections - i failed of course.

I remember the days I coded in pascal that there was another socket I should send connections too,it was received after "Accept".

Well,if this is correct then this is my problem:

I'm using WSAAsyncSelect() in my TCP server(C#)

protected override void WndProc(ref Message m)
    {
        switch (m.Msg)
        {

            case Values.MESSAGE_ASYNC:
                switch (m.LParam.ToInt32())
                {
                    case Values.FD_ACCEPT:
                        WS2.Accept();
                        break;

                    case Values.FD_READ:
                        WS2.Receive();
                        break;
                    case Values.FD_CLOSE:
                        WS2.Close();
                        break;
                }
                break;

            default:
                base.WndProc(ref m);
                break;
        }
    }

I have to send a packet to the client when it gets connected.

How do i get the socket where I have to send packets on to that client?

I didn't call Accept(),because I don't know how it should be done in C#,been searching for examples,but none of them used the old WSAAsyncSelect().

Please provide an example showing how it should be done.

Thanks in advance!

+2  A: 

Have a look at TcpListener. Restrict the language to C# to get rid of the non-C# examples.

Arnshea
yep, changed the link to TcpListener - change the language filter to C# only.
Arnshea
Very bad example,but I've got how it works.Socket clientsock = sock.Accept();
John