Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi my name is vishal for past 2 days i have been breaking my head on how to make winsock control to allow maximum of 20 clients to be connected at once in c# windows forms.
I have a form named:Form1 in which i have 1 winsock control named:Winsock1 along with some buttons and textboxes.

I did a research and found out below code worked the same functionality of winsock control Just what what i needed but unfortunately it was in vb6 code.

Given below is vb6 code with winsock control named:Winsock1 with which i was able to achieve the same functionality in vb6 with Ms access. :
VB
Private Sub Form_Load()
    Dim x As Integer
    For x = 1 To 20    'This will allow a maximum of 20 clients to be connected at once
        Load sckClient(x)
        sckClient(x).Close
    Next
    StartListen
End Sub
Private Function StartListen()
    sckServer.Close
    sckServer.LocalPort = 25000
    sckServer.Listen
End Function

where sckClient is name of one of my Winsock controls in vb6 and sckServer is name of my another Winsock control in vb6.

Given below is my c# code interpretation of above vb6 code:
C#
namespace DRRS_Socket_Application
{
    public partial class Form1 : Form
    {
        Socket sck;
        EndPoint epLocal;
        const string DELIM = "***";
        const string EOP = "???";
        int counter;
        public Form1()
        {
            InitializeComponent();
            sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            }
private void StartListen()
        {
            sckServer.Close();
            sckServer.LocalPort = 25000;
            sckServer.Listen();
        }
 private void Form1_Load(object sender, EventArgs e)
        {

        }

I have 2 Winsock controls named:sckServer and sckClient in my Form1. I am able to correctly code StartListen() in c# windows forms. But i am not able/correctly code (c#) of sckClient(Winsock control) in allowing 20 clients to be connected at once in c# windows forms.

I am supposed to use only Winsock control in c# windows forms because of my Boss orders and cannot use TCP Classes or other things.

Can anyone help me on how to make my winsock(sckClient) in allowing 20 clients to be connected at once in c# windows forms.Can anyone help me please? Any help/guidance in solving of this problem would be greatly appreciated!
Posted

1 solution


You need to use an asynchronous socket. See Using an Asynchronous Client Socket[^].



Hope that helps.

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900