I have designed a socket Server and developed asynchronous server . It is working fine with 60 Clients which are connecting to ths Server running at Machine (2 GB RAM and OS is Windows 2003 Server)having IP which is Mapped with static IP and Port in firewall .
The Programme is working fine with 60 clients and rate if incoing data on the server is 5 -6 string of 1024 byte size are being saved in DataBase.
When i try to connect 61th client to the same server then it stops functioning. does not recieve Data and do accept new clients. And existing clients start gettting disconnected.
Pls note i am using BeginConnect and EndConnect function of C#. and using GPRS Connection at the Client Side. and LEased Line of 2 MEG on server Side.
For rceieving the Data Once the Client is Connected i use WaitforData function and OnRecieveData function in Asynchronous manner to recieved the Data on Socket Server.
Kindly suggest me how i can increase the number more than 60 Clients on Socket Server
4 3310 http://www.csharphelp.com/archives3/archive486.html
I have designed a socket Server and developed asynchronous server . It is working fine with 60 Clients which are connecting to ths Server running at Machine (2 GB RAM and OS is Windows 2003 Server)having IP which is Mapped with static IP and Port in firewall .
The Programme is working fine with 60 clients and rate if incoing data on the server is 5 -6 string of 1024 byte size are being saved in DataBase.
When i try to connect 61th client to the same server then it stops functioning. does not recieve Data and do accept new clients. And existing clients start gettting disconnected.
Pls note i am using BeginConnect and EndConnect function of C#. and using GPRS Connection at the Client Side. and LEased Line of 2 MEG on server Side.
For rceieving the Data Once the Client is Connected i use WaitforData function and OnRecieveData function in Asynchronous manner to recieved the Data on Socket Server.
Kindly suggest me how i can increase the number more than 60 Clients on Socket Server
I found this researching your question not sure if it will help but this seems to set the sockets I found it at http://www.csharphelp.com/archives3/archive486.html -
public Server(int port, string title, string attr)
-
{
-
this.portNumber = port;
-
this.title = title;
-
this.maxSockets =10000;
-
connectedSocks = new ArrayList(this.maxSockets);
-
}
-
-
-
///
-
/// Description: Start the threads to listen to the port and process
-
/// messages.
-
///
-
a lot of other code was included maybe you can get an idea from there
hope it helps
[HTML]I have already done this and initialized an array of 20000 for the clients.
Below written is the Code fort his which i am using
-
private Socket[] m_workerSocket = new Socket[20000];
-
-
//Start Listen Here On Button click
-
void ButtonStartListenClick(object sender, System.EventArgs e)
-
{
-
-
OPenDataBaseConnectionIfClosed();
-
-
try
-
{
-
// Check the port value
-
if (textBoxPort.Text == "")
-
{
-
MessageBox.Show("Please enter a Port Number");
-
return;
-
}
-
string portStr = textBoxPort.Text;
-
int port = System.Convert.ToInt32(portStr);
-
// Create the listening socket...
-
/* m_mainSocket = new Socket(AddressFamily.InterNetwork,
-
SocketType.Stream,
-
ProtocolType.Tcp);
-
*/
-
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, port);
-
// Bind to local IP Address...
-
//MessageBox.Show("iplocal00" + ipLocal);
-
// m_mainSocket.Bind(ipLocal);
-
-
// Start listening...
-
m_mainSocket.Listen(100000);
-
//MessageBox.Show("iplocal 01" );
-
// Create the call back for any client connections...
-
m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
-
//MessageBox.Show("iplocal 02");
-
-
//UpdateControls(true);
-
//MessageBox.Show("iplocal 03");
-
// lblIPAddress.Text = m_mainSocket.RemoteEndPoint.ToString();
-
// MessageBox.Show("IP Number : " + m_mainSocket.RemoteEndPoint);
-
// lblIPAddress = m_mainSocket.RemoteEndPoint;
-
-
}
-
catch (SocketException se)
-
{
-
lblIPAddress.Text = "6 : Connection Closed";
-
-
WriteTOTextFile("1:" + se.NativeErrorCode + " : " + se.Message + System.DateTime.Now);
-
}
-
-
}
-
-
// This is the call back function, which will be invoked when a client is connected
-
public void OnClientConnect(IAsyncResult asyn)
-
{
-
try
-
{
-
// Here we complete/end the BeginAccept() asynchronous call
-
// by calling EndAccept() - which returns the reference to
-
// a new Socket object
-
//m_mainSocket.
-
-
m_workerSocket[m_clientCount] = m_mainSocket.EndAccept(asyn);
-
-
// Let the worker Socket do the further processing for the
-
// just connected client
-
-
-
-
WaitForData(m_workerSocket[m_clientCount]);
-
-
// Now increment the client count
-
++m_clientCount;
-
++SocketNo;
-
// Display this client connection as a status message on the GUI
-
//String str = String.Format("Client # {0} connected", m_clientCount);
-
String str = String.Format("Client # {0} connected", SocketNo);
-
textBoxMsg.Text = str;
-
SocketNo = m_clientCount;
-
// m_workerSocket[m_clientCount].Ttl = 500;
-
// lblIPAddress.Text;
-
// MessageBox.Show(" : " + m_clientCount + " : ");
-
String ipconnected = m_workerSocket[m_clientCount].RemoteEndPoint.ToString();
-
hstIPDev.Add(ipconnected, "0");
-
lblIPAddress.Text = ":: " + ipconnected;
-
lbl_dev_count.Text = hstIPDev.Count.ToString();
-
// Since the main Socket is now free, it can go back and wait for
-
// other clients who are attempting to connect
-
-
m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
-
-
-
}
-
-
catch (ObjectDisposedException e )
-
{
-
//lblIPAddress.Text = "4 : Connection Closed";
-
System.Diagnostics.Debugger.Log(0, "1", "\n OnClientConnection: Socket has been closed\n");
-
WriteTOTextFile("2 " + e.Message + " : OnClientConnection: Socket has been closed : " + System.DateTime.Now);
-
-
textBoxMsg.Text = String.Format("Client # {0} connected",m_clientCount);
-
-
-
-
}
-
catch (SocketException se)
-
{
-
-
//MessageBox.Show("22" + " ErrorCode " + se.ErrorCode + " : " +se.Message);
-
WriteTOTextFile("3: " + se.NativeErrorCode + " : " + se.Message + System.DateTime.Now);
-
StartListenClick();
-
//m_mainSocket.Close();
-
//StartListenClick();
-
-
}
-
catch (Exception se)
-
{
-
-
//MessageBox.Show("22" + " ErrorCode " + se.ErrorCode + " : " + se.Message);
-
WriteTOTextFile("33: " + " : " + se.Message + System.DateTime.Now);
-
StartListenClick();
-
-
}
-
-
-
-
}
-
-
-
Actually i listen the client requst on one IP wth Port to listen . When Asychronous call END then i create new Socket Object nad put that socket object in waitstate in the following function
-
// Start waiting for data from the client
-
public void WaitForData(System.Net.Sockets.Socket soc)
-
{
-
-
-
try
-
{
-
if ( pfnWorkerCallBack == null ){
-
// Specify the call back function which is to be
-
// invoked when there is any write activity by the
-
// connected client
-
pfnWorkerCallBack = new AsyncCallback (OnDataReceived);
-
}
-
SocketPacket theSocPkt = new SocketPacket ();
-
theSocPkt.m_currentSocket = soc;
-
-
// Start receiving any data written by the connected client
-
// asynchronously
-
soc .BeginReceive (theSocPkt.dataBuffer, 0,
-
theSocPkt.dataBuffer.Length,
-
SocketFlags.None,
-
pfnWorkerCallBack,
-
theSocPkt);
-
// MessageBox.Show("inside Wait 02");
-
-
if (soc.RemoteEndPoint != null)
-
{
-
lblIPAddress.Text= " Recent ip connected : " + soc.RemoteEndPoint.ToString();
-
CurrentIP = soc.RemoteEndPoint.ToString();
-
//lstBoxClientList.Items.Add (soc.RemoteEndPoint.ToString());
-
-
-
}
-
//MessageBox.Show("inside Wait 03");
-
}
-
catch(SocketException se)
-
{
-
//MessageBox.Show ( "2:" + se.ErrorCode + " : " + se.Message );
-
WriteTOTextFile("4: " + se.NativeErrorCode + " : " + se.Message + System.DateTime.Now);
-
int ipIndexinListBox;
-
ipIndexinListBox = FindAllOfMyString(CurrentIP);
-
if (ipIndexinListBox >= 0)
-
{
-
-
lstBoxClientList.Items.RemoveAt(ipIndexinListBox);
-
}
-
soc.Disconnect(true);
-
////.......
-
//m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
-
////.....
-
//textBoxMsg.Text = String.Format("Client # {0} connected", SocketNo);
-
-
}
-
-
}
-
And when Data arrives on the main Socket from the Client the On recieve asynchrous function to read the Data is being used in following function
-
-
public void OnDataReceived(IAsyncResult asyn)
-
{
-
-
-
try
-
{
-
SocketPacket socketData = (SocketPacket)asyn.AsyncState;
-
-
int iRx = 0;
-
// Complete the BeginReceive() asynchronous call by EndReceive() method
-
// which will return the number of characters written to the stream
-
// by the client
-
iRx = socketData.m_currentSocket.EndReceive(asyn);
-
-
char[] chars = new char[iRx + 1];
-
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
-
String ipData=socketData.m_currentSocket.RemoteEndPoint.ToString();
-
CurrentIP = ipData;
-
int charLen = d.GetChars(socketData.dataBuffer,
-
0, iRx, chars, 0);
-
-
System.String szData = new System.String(chars);
-
szData = szData.Trim();
-
-
-
long intvalOfChar;//, minA,mina,maxZ,maxz,min0,max9; // Determine the Ascii Value
-
char c;
-
-
-
c = Convert.ToChar(szData.Substring(0, 1));
-
intvalOfChar = (int)c;
-
// richTextBoxAllData.AppendText(szData);
-
-
-
// IF $ Appears more than one than the following if block stops
-
//the add Enter character in the string comming from Client()Device ///
-
if ((richTextBoxReceivedMsg.Text.LastIndexOf('$') == 0 && c == '$') || (richTextBoxReceivedMsg.Text.LastIndexOf('$') > 0 && c == '$'))
-
{
-
richTextBoxReceivedMsg.Text = "";
-
//richTextBoxSendMsg.AppendText("\r");
-
c = (char)('\r');
-
}
-
////////////////////////////////////////////////////////////////
-
-
if (c != (char)1 && c != (char)('*') )
-
{
-
-
try
-
{
-
if ((szData.LastIndexOf('$') == 0 || richTextBoxReceivedMsg.Text.Trim().LastIndexOf('$') == 0))
-
{
-
-
richTextBoxReceivedMsg.AppendText(szData);
-
//richTextBoxSendMsg.AppendText(szData);
-
-
str = richTextBoxReceivedMsg.Text;
-
String[] values3 = str.Split(',');
-
-
if (richTextBoxReceivedMsg.Text.LastIndexOf('&') > 0 && str.IndexOf(',') != -1 )
-
{
-
-
// Get Cutrrent Pos
-
if (richTextBoxReceivedMsg.Text.IndexOf("CurrentPos") != -1 && values3.Length == 3)
-
{
-
// richTextBoxSendMsg.AppendText("\r");
-
String[] CurrentPOSStr;
-
String IPofDevice, DeviceCode, DevName;
-
CurrentPOSStr = str.Split(',');
-
-
// DeviceCode = CurrentPOSStr[1];
-
// DevName = FindDeviceNamefortheDeviceCode(DeviceCode);
-
DevName = CurrentPOSStr[1];
-
DevName1 = DevName; // Parameter for concatng IP
-
-
//IPofDevice = FindIPoftheDevName(DevName);
-
IPofDevice = FindIPFromHashTable(DevName);
-
-
-
if (IPofDevice != "")
-
{
-
SendSingleMessage("$ActGetPos,1203,0000&", IPofDevice);
-
richTextBoxPollingList.AppendText(DevName + "," + IPofDevice + "," + System.DateTime.Now + "\n");
-
lblLastMessageSent.Text = DevName + "," + IPofDevice + " " + System.DateTime.Now;
-
}
-
else
-
{
-
richTextBoxPollingList.AppendText("Message not sent for polling because No IP found for "+DevName + "," + IPofDevice + "," + System.DateTime.Now + "\n");
-
}
-
str = ""; // Clearing the String
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
}
-
-
-
//Get Unit ID
-
-
-
if (richTextBoxReceivedMsg.Text.IndexOf("GetUnit") != -1 && values3.Length==3 )
-
{
-
String[] Str;
-
String IPofDevice, DeviceCode, DevName;
-
//Str = str.Split(',');
-
//DeviceCode = Str[1];
-
//DevName = FindDeviceNamefortheDeviceCode(DeviceCode);
-
//DevName1 = DevName; // Parameter for concatng IP
-
//IPofDevice = FindIPoftheDevName(DevName);
-
//richTextBoxPollingList.AppendText(DevName + "," + IPofDevice + "," + System.DateTime.Now + "\n");
-
//lblLastMessageSent.Text = DevName + "," + IPofDevice + " " + System.DateTime.Now;
-
-
richTextBoxCommandOK.AppendText(str+"\n");
-
str = ""; // Clearing the String
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
}
-
-
//GetGPRs Config
-
-
if (richTextBoxReceivedMsg.Text.IndexOf("GetGPRSConfig") != -1 && values3.Length==7)
-
{
-
String[] Str;
-
String IPofDevice, DeviceCode, DevName;
-
//Str = str.Split(',');
-
//DeviceCode = Str[1];
-
//DevName = FindDeviceNamefortheDeviceCode(DeviceCode);
-
//DevName1 = DevName; // Parameter for concatng IP
-
//IPofDevice = FindIPoftheDevName(DevName);
-
//richTextBoxPollingList.AppendText(DevName + "," + IPofDevice + "," + System.DateTime.Now + "\n");
-
//lblLastMessageSent.Text = DevName + "," + IPofDevice + " " + System.DateTime.Now;
-
-
richTextBoxCommandOK.AppendText(str + "\n");
-
str = ""; // Clearing the String
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
}
-
// Get TimeStamp
-
if (richTextBoxReceivedMsg.Text.IndexOf("GetTimeStamp") != -1 && values3.Length==3)
-
{
-
String[] Str;
-
String IPofDevice, DeviceCode, DevName;
-
//Str = str.Split(',');
-
//DeviceCode = Str[1];
-
//DevName = FindDeviceNamefortheDeviceCode(DeviceCode);
-
//DevName1 = DevName; // Parameter for concatng IP
-
//IPofDevice = FindIPoftheDevName(DevName);
-
//richTextBoxPollingList.AppendText(DevName + "," + IPofDevice + "," + System.DateTime.Now + "\n");
-
//lblLastMessageSent.Text = DevName + "," + IPofDevice + " " + System.DateTime.Now;
-
-
richTextBoxCommandOK.AppendText(str + "\n");
-
str = ""; // Clearing the String
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
}
-
-
-
if (richTextBoxReceivedMsg.Text.IndexOf("logGetPos") != -1 && str.IndexOf(',') != -1 && values3.Length<=18)
-
{
-
richTextBoxCommandOK.AppendText(str+"\n");
-
// richTextBoxSendMsg.AppendText(" from IP " + CurrentIP + "\r\n");
-
String[] LogGetPOSStringArray;
-
LogGetPOSStringArray = str.Split(',');
-
-
if (LogGetPOSStringArray.Length == 18)
-
{
-
SaveNewDataToDataBase(str);
-
UpdatePollingDetail(LogGetPOSStringArray[1]);
-
}
-
else
-
{
-
WriteTOTextFile("logGetPos String Less than 17 words: " + str + " "+ System.DateTime.Now);
-
}
-
-
-
str = ""; // Clearing the String
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
//SavetoDataBase.....
-
}
-
-
-
}
-
-
}
-
}
-
catch (Exception e)
-
{
-
int ipIndex;
-
//m_workerSocket[m_clientCount].Disconnect(true);
-
-
WriteTOTextFile("5: " + e.Message + System.DateTime.Now);
-
//--SocketNo;
-
// textBoxMsg.Text = "Client # " + SocketNo +" connected";
-
////////ipIndex = FindAllOfMyString(CurrentIP);
-
////////if (ipIndex >= 0)
-
////////{
-
//////// lstBoxClientList.Items.RemoveAt(ipIndex);
-
////////}
-
}
-
}
-
-
if (str.IndexOf('&') != -1 && str.IndexOf(',') != -1)
-
{
-
String[] values2 = str.Split(',');
-
-
-
/////////////// Display the IP in rich text box from which the command Ok received
-
if ((str.IndexOf("OK", 0) > 0 || str.IndexOf("Pwd", 0) > 0 || str.IndexOf("Cmd", 0)>0 || str.IndexOf("Param", 0)>0) && values2.Length >=3)
-
{
-
-
richTextBoxCommandOK.AppendText("Recieved : " + str + " from " + CurrentIP + "\n");
-
//richTextBoxSendMsg.AppendText("Recieved : " + str + " from " + CurrentIP + "\n");
-
-
str = "";
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
-
}
-
////////////
-
-
if( (str.IndexOf('$') != -1) && ((values2.Length == 15) || (values2.Length == 17) || (values2.Length == 18)) && (str.IndexOf(',') != -1))
-
{
-
String existingIPAndDevName;
-
int indexofExistingIPAndDevName;
-
lock (hstIPDev)
-
{
-
// hstIPDev.Remove(values2[1]);
-
// hstIPDev.Add(values2[1],ipData);
-
hstIPDev.Remove(ipData);
-
hstIPDev.Add(ipData,values2[1]);
-
}
-
// MessageBox.Show(str);
-
// existingIPAndDevName = CurrentIP + "," + values2[1];
-
existingIPAndDevName = "," + values2[1];
-
-
//////////////indexofExistingIPAndDevName = FindAllOfMyString(existingIPAndDevName);
-
-
-
//////////////if (indexofExistingIPAndDevName < 0)
-
//////////////{
-
////////////// lstBoxClientList.Items.Add(CurrentIP + "," + values2[1]); // Adding the IP with Device Code in the ListClient
-
////////////// // lstBoxClientList.Items.Add(CurrentIP + "," + values2[1]); // Adding the IP with Device Code in the ListClient
-
//////////////}
-
//////////////else
-
//////////////{
-
////////////// lstBoxClientList.Items.RemoveAt(indexofExistingIPAndDevName);//,CurrentIP + "," + values2[1]); // Adding the IP with Device Code in the ListClient
-
////////////// lstBoxClientList.Items.Add(CurrentIP + "," + values2[1]); // Adding the IP with Device Code in the ListClient
-
//////////////}
-
richTextBoxReceivedMsg.Clear();
-
-
-
if (((values2[1].Equals("0705280114")) || values2[3].Equals("0705280114") && str.IndexOf(',') != -1) && (values2.Length == 15 || values2.Length == 17)) // Device code 8
-
{
-
-
str = str.Trim();
-
-
SaveDataToDataBase(str);
-
-
szData = null;
-
-
richTextBoxReceivedMsg.Clear();
-
}
-
-
//else
-
-
if (((!values2[1].Equals("0705280114")) || !values2[3].Equals("0705280114") && str.IndexOf(',') != -1) && values2.Length == 18) // Devices Other Than Device code 8
-
{
-
-
if (str.IndexOf(',') != -1)
-
{
-
SaveNewDataToDataBase(str);
-
szData = null;
-
}
-
}
-
-
-
txtLastMessageSaved.Text = str;
-
str = "";
-
-
-
-
richTextBoxReceivedMsg.Clear();
-
-
values2 = null;
-
}
-
-
}
-
// Continue the waiting for data on the Socket
-
-
WaitForData(socketData.m_currentSocket);
-
//////lbl_dev_count.Text = lstBoxClientList.Items.Count.ToString();
-
lbl_dev_count.Text = hstIPDev.Count.ToString();
-
//UpdateListofIP(CurrentIP,DevName1);
-
}
-
catch (ObjectDisposedException )
-
{
-
SocketPacket socketData02 = (SocketPacket)asyn.AsyncState;
-
String ipData = socketData02.m_currentSocket.RemoteEndPoint.ToString();
-
hstIPDev.Remove(ipData);
-
-
System.Diagnostics.Debugger.Log(0,"1","\nOnDataReceived: Socket has been closed\n");
-
WriteTOTextFile("5: OnDataReceived: Socket has been closed "+ System.DateTime.Now);
-
-
int indexofIP;
-
////////indexofIP = FindAllOfMyString(CurrentIP);
-
////////if (indexofIP != -1)
-
////////{
-
//////// lstBoxClientList.Items.RemoveAt(indexofIP);
-
////////}
-
// m_workerSocket[m_clientCount].Disconnect(true);
-
// --SocketNo;
-
// textBoxMsg.Text = "Client # " + SocketNo + " connected";
-
//WaitForData(socketData02.m_currentSocket);
-
////////////lbl_dev_count.Text = lstBoxClientList.Items.Count.ToString();
-
lbl_dev_count.Text = hstIPDev.Count.ToString();
-
}
-
catch(SocketException se)
-
{
-
-
//Code To Close the Worker Socket
-
SocketPacket socketData01 = (SocketPacket)asyn.AsyncState;
-
String ipData01;
-
if (socketData01.m_currentSocket != null)
-
{
-
-
ipData01 = socketData01.m_currentSocket.RemoteEndPoint.ToString();
-
//RemoveIPFromHashTable(ip);
-
hstIPDev.Remove(ipData01);
-
-
WriteTOTextFile("8. Closing Worker Socket OrionIP:" + ipData01 + " Worker IP : " + socketData01.m_currentSocket.LocalEndPoint.ToString());
-
socketData01.m_currentSocket.Close();
-
socketData01.m_currentSocket = null;
-
-
-
-
}
-
-
if( se.ErrorCode ==10054)
-
{
-
//CurrentIP= m_workerSocket[m_clientCount].RemoteEndPoint.ToString();
-
// m_workerSocket[m_clientCount].Disconnect(true);
-
lblIPAddress.Text = lblIPAddress.Text + " Remotely Closed" +CurrentIP;
-
// --SocketNo;
-
//textBoxMsg.Text = "Client # " + SocketNo + " connected";
-
richTextBoxAllData.AppendText("Here disconnected :"+ CurrentIP);
-
WriteTOTextFile("6:" + " " + se.NativeErrorCode + " : " + se.Message + System.DateTime.Now);
-
StartListenClick();
-
////int indexofIP;
-
////indexofIP = FindAllOfMyString(CurrentIP);
-
////if( indexofIP != -1)
-
////{
-
//// lstBoxClientList.Items.RemoveAt(indexofIP);
-
////}
-
-
-
//int i;
-
//i=lstBoxClientList.FindString("," + CurrentIP);
-
//lstBoxClientList.Items.RemoveAt(i);
-
}
-
else
-
{
-
//MessageBox.Show ("4 : " + se.ErrorCode + ": " + se.Message );
-
WriteTOTextFile("7: a" + se.ErrorCode + " : " + se.Message + System.DateTime.Now);
-
}
-
-
// WaitForData(socketData01.m_currentSocket);
-
//lbl_dev_count.Text = lstBoxClientList.Items.Count.ToString();
-
lbl_dev_count.Text = hstIPDev.Count.ToString();
-
}
-
}
-
And in this read function when socket Client gets disconnected the byte length of data i recieve is zero and then i check for null ocket and then close the child socket which is not the main socket but one of the socket fin the array list.
-
-
Still waiting for solution
-
setiarakeshgps@hotmail.com
[/HTML][/PHP]
[HTML]I have already done this and initialized an array of 20000 for the clients.Below written is the Code fort his which i am using -
private Socket[] m_workerSocket = new Socket[20000];
-
-
//Start Listen Here On Button click
-
void ButtonStartListenClick(object sender, System.EventArgs e)
-
{
-
-
OPenDataBaseConnectionIfClosed();
-
-
try
-
{
-
// Check the port value
-
if (textBoxPort.Text == "")
-
{
-
MessageBox.Show("Please enter a Port Number");
-
return;
-
}
-
string portStr = textBoxPort.Text;
-
int port = System.Convert.ToInt32(portStr);
-
// Create the listening socket...
-
/* m_mainSocket = new Socket(AddressFamily.InterNetwork,
-
SocketType.Stream,
-
ProtocolType.Tcp);
-
*/
-
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, port);
-
// Bind to local IP Address...
-
//MessageBox.Show("iplocal00" + ipLocal);
-
// m_mainSocket.Bind(ipLocal);
-
-
// Start listening...
-
m_mainSocket.Listen(100000);
-
//MessageBox.Show("iplocal 01" );
-
// Create the call back for any client connections...
-
m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
-
//MessageBox.Show("iplocal 02");
-
-
//UpdateControls(true);
-
//MessageBox.Show("iplocal 03");
-
// lblIPAddress.Text = m_mainSocket.RemoteEndPoint.ToString();
-
// MessageBox.Show("IP Number : " + m_mainSocket.RemoteEndPoint);
-
// lblIPAddress = m_mainSocket.RemoteEndPoint;
-
-
}
-
catch (SocketException se)
-
{
-
lblIPAddress.Text = "6 : Connection Closed";
-
-
WriteTOTextFile("1:" + se.NativeErrorCode + " : " + se.Message + System.DateTime.Now);
-
}
-
-
}
-
-
// This is the call back function, which will be invoked when a client is connected
-
public void OnClientConnect(IAsyncResult asyn)
-
{
-
try
-
{
-
// Here we complete/end the BeginAccept() asynchronous call
-
// by calling EndAccept() - which returns the reference to
-
// a new Socket object
-
//m_mainSocket.
-
-
m_workerSocket[m_clientCount] = m_mainSocket.EndAccept(asyn);
-
-
// Let the worker Socket do the further processing for the
-
// just connected client
-
-
-
-
WaitForData(m_workerSocket[m_clientCount]);
-
-
// Now increment the client count
-
++m_clientCount;
-
++SocketNo;
-
// Display this client connection as a status message on the GUI
-
//String str = String.Format("Client # {0} connected", m_clientCount);
-
String str = String.Format("Client # {0} connected", SocketNo);
-
textBoxMsg.Text = str;
-
SocketNo = m_clientCount;
-
// m_workerSocket[m_clientCount].Ttl = 500;
-
// lblIPAddress.Text;
-
// MessageBox.Show(" : " + m_clientCount + " : ");
-
String ipconnected = m_workerSocket[m_clientCount].RemoteEndPoint.ToString();
-
hstIPDev.Add(ipconnected, "0");
-
lblIPAddress.Text = ":: " + ipconnected;
-
lbl_dev_count.Text = hstIPDev.Count.ToString();
-
// Since the main Socket is now free, it can go back and wait for
-
// other clients who are attempting to connect
-
-
m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
-
-
-
}
-
-
catch (ObjectDisposedException e )
-
{
-
//lblIPAddress.Text = "4 : Connection Closed";
-
System.Diagnostics.Debugger.Log(0, "1", "\n OnClientConnection: Socket has been closed\n");
-
WriteTOTextFile("2 " + e.Message + " : OnClientConnection: Socket has been closed : " + System.DateTime.Now);
-
-
textBoxMsg.Text = String.Format("Client # {0} connected",m_clientCount);
-
-
-
-
}
-
catch (SocketException se)
-
{
-
-
//MessageBox.Show("22" + " ErrorCode " + se.ErrorCode + " : " +se.Message);
-
WriteTOTextFile("3: " + se.NativeErrorCode + " : " + se.Message + System.DateTime.Now);
-
StartListenClick();
-
//m_mainSocket.Close();
-
//StartListenClick();
-
-
}
-
catch (Exception se)
-
{
-
-
//MessageBox.Show("22" + " ErrorCode " + se.ErrorCode + " : " + se.Message);
-
WriteTOTextFile("33: " + " : " + se.Message + System.DateTime.Now);
-
StartListenClick();
-
-
}
-
-
-
-
}
-
-
-
Actually i listen the client requst on one IP wth Port to listen . When Asychronous call END then i create new Socket Object nad put that socket object in waitstate in the following function
-
// Start waiting for data from the client
-
public void WaitForData(System.Net.Sockets.Socket soc)
-
{
-
-
-
try
-
{
-
if ( pfnWorkerCallBack == null ){
-
// Specify the call back function which is to be
-
// invoked when there is any write activity by the
-
// connected client
-
pfnWorkerCallBack = new AsyncCallback (OnDataReceived);
-
}
-
SocketPacket theSocPkt = new SocketPacket ();
-
theSocPkt.m_currentSocket = soc;
-
-
// Start receiving any data written by the connected client
-
// asynchronously
-
soc .BeginReceive (theSocPkt.dataBuffer, 0,
-
theSocPkt.dataBuffer.Length,
-
SocketFlags.None,
-
pfnWorkerCallBack,
-
theSocPkt);
-
// MessageBox.Show("inside Wait 02");
-
-
if (soc.RemoteEndPoint != null)
-
{
-
lblIPAddress.Text= " Recent ip connected : " + soc.RemoteEndPoint.ToString();
-
CurrentIP = soc.RemoteEndPoint.ToString();
-
//lstBoxClientList.Items.Add (soc.RemoteEndPoint.ToString());
-
-
-
}
-
//MessageBox.Show("inside Wait 03");
-
}
-
catch(SocketException se)
-
{
-
//MessageBox.Show ( "2:" + se.ErrorCode + " : " + se.Message );
-
WriteTOTextFile("4: " + se.NativeErrorCode + " : " + se.Message + System.DateTime.Now);
-
int ipIndexinListBox;
-
ipIndexinListBox = FindAllOfMyString(CurrentIP);
-
if (ipIndexinListBox >= 0)
-
{
-
-
lstBoxClientList.Items.RemoveAt(ipIndexinListBox);
-
}
-
soc.Disconnect(true);
-
////.......
-
//m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
-
////.....
-
//textBoxMsg.Text = String.Format("Client # {0} connected", SocketNo);
-
-
}
-
-
}
-
And when Data arrives on the main Socket from the Client the On recieve asynchrous function to read the Data is being used in following function
-
-
public void OnDataReceived(IAsyncResult asyn)
-
{
-
-
-
try
-
{
-
SocketPacket socketData = (SocketPacket)asyn.AsyncState;
-
-
int iRx = 0;
-
// Complete the BeginReceive() asynchronous call by EndReceive() method
-
// which will return the number of characters written to the stream
-
// by the client
-
iRx = socketData.m_currentSocket.EndReceive(asyn);
-
-
char[] chars = new char[iRx + 1];
-
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
-
String ipData=socketData.m_currentSocket.RemoteEndPoint.ToString();
-
CurrentIP = ipData;
-
int charLen = d.GetChars(socketData.dataBuffer,
-
0, iRx, chars, 0);
-
-
System.String szData = new System.String(chars);
-
szData = szData.Trim();
-
-
-
long intvalOfChar;//, minA,mina,maxZ,maxz,min0,max9; // Determine the Ascii Value
-
char c;
-
-
-
c = Convert.ToChar(szData.Substring(0, 1));
-
intvalOfChar = (int)c;
-
// richTextBoxAllData.AppendText(szData);
-
-
-
// IF $ Appears more than one than the following if block stops
-
//the add Enter character in the string comming from Client()Device ///
-
if ((richTextBoxReceivedMsg.Text.LastIndexOf('$') == 0 && c == '$') || (richTextBoxReceivedMsg.Text.LastIndexOf('$') > 0 && c == '$'))
-
{
-
richTextBoxReceivedMsg.Text = "";
-
//richTextBoxSendMsg.AppendText("\r");
-
c = (char)('\r');
-
}
-
////////////////////////////////////////////////////////////////
-
-
if (c != (char)1 && c != (char)('*') )
-
{
-
-
try
-
{
-
if ((szData.LastIndexOf('$') == 0 || richTextBoxReceivedMsg.Text.Trim().LastIndexOf('$') == 0))
-
{
-
-
richTextBoxReceivedMsg.AppendText(szData);
-
//richTextBoxSendMsg.AppendText(szData);
-
-
str = richTextBoxReceivedMsg.Text;
-
String[] values3 = str.Split(',');
-
-
if (richTextBoxReceivedMsg.Text.LastIndexOf('&') > 0 && str.IndexOf(',') != -1 )
-
{
-
-
// Get Cutrrent Pos
-
if (richTextBoxReceivedMsg.Text.IndexOf("CurrentPos") != -1 && values3.Length == 3)
-
{
-
// richTextBoxSendMsg.AppendText("\r");
-
String[] CurrentPOSStr;
-
String IPofDevice, DeviceCode, DevName;
-
CurrentPOSStr = str.Split(',');
-
-
// DeviceCode = CurrentPOSStr[1];
-
// DevName = FindDeviceNamefortheDeviceCode(DeviceCode);
-
DevName = CurrentPOSStr[1];
-
DevName1 = DevName; // Parameter for concatng IP
-
-
//IPofDevice = FindIPoftheDevName(DevName);
-
IPofDevice = FindIPFromHashTable(DevName);
-
-
-
if (IPofDevice != "")
-
{
-
SendSingleMessage("$ActGetPos,1203,0000&", IPofDevice);
-
richTextBoxPollingList.AppendText(DevName + "," + IPofDevice + "," + System.DateTime.Now + "\n");
-
lblLastMessageSent.Text = DevName + "," + IPofDevice + " " + System.DateTime.Now;
-
}
-
else
-
{
-
richTextBoxPollingList.AppendText("Message not sent for polling because No IP found for "+DevName + "," + IPofDevice + "," + System.DateTime.Now + "\n");
-
}
-
str = ""; // Clearing the String
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
}
-
-
-
//Get Unit ID
-
-
-
if (richTextBoxReceivedMsg.Text.IndexOf("GetUnit") != -1 && values3.Length==3 )
-
{
-
String[] Str;
-
String IPofDevice, DeviceCode, DevName;
-
//Str = str.Split(',');
-
//DeviceCode = Str[1];
-
//DevName = FindDeviceNamefortheDeviceCode(DeviceCode);
-
//DevName1 = DevName; // Parameter for concatng IP
-
//IPofDevice = FindIPoftheDevName(DevName);
-
//richTextBoxPollingList.AppendText(DevName + "," + IPofDevice + "," + System.DateTime.Now + "\n");
-
//lblLastMessageSent.Text = DevName + "," + IPofDevice + " " + System.DateTime.Now;
-
-
richTextBoxCommandOK.AppendText(str+"\n");
-
str = ""; // Clearing the String
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
}
-
-
//GetGPRs Config
-
-
if (richTextBoxReceivedMsg.Text.IndexOf("GetGPRSConfig") != -1 && values3.Length==7)
-
{
-
String[] Str;
-
String IPofDevice, DeviceCode, DevName;
-
//Str = str.Split(',');
-
//DeviceCode = Str[1];
-
//DevName = FindDeviceNamefortheDeviceCode(DeviceCode);
-
//DevName1 = DevName; // Parameter for concatng IP
-
//IPofDevice = FindIPoftheDevName(DevName);
-
//richTextBoxPollingList.AppendText(DevName + "," + IPofDevice + "," + System.DateTime.Now + "\n");
-
//lblLastMessageSent.Text = DevName + "," + IPofDevice + " " + System.DateTime.Now;
-
-
richTextBoxCommandOK.AppendText(str + "\n");
-
str = ""; // Clearing the String
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
}
-
// Get TimeStamp
-
if (richTextBoxReceivedMsg.Text.IndexOf("GetTimeStamp") != -1 && values3.Length==3)
-
{
-
String[] Str;
-
String IPofDevice, DeviceCode, DevName;
-
//Str = str.Split(',');
-
//DeviceCode = Str[1];
-
//DevName = FindDeviceNamefortheDeviceCode(DeviceCode);
-
//DevName1 = DevName; // Parameter for concatng IP
-
//IPofDevice = FindIPoftheDevName(DevName);
-
//richTextBoxPollingList.AppendText(DevName + "," + IPofDevice + "," + System.DateTime.Now + "\n");
-
//lblLastMessageSent.Text = DevName + "," + IPofDevice + " " + System.DateTime.Now;
-
-
richTextBoxCommandOK.AppendText(str + "\n");
-
str = ""; // Clearing the String
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
}
-
-
-
if (richTextBoxReceivedMsg.Text.IndexOf("logGetPos") != -1 && str.IndexOf(',') != -1 && values3.Length<=18)
-
{
-
richTextBoxCommandOK.AppendText(str+"\n");
-
// richTextBoxSendMsg.AppendText(" from IP " + CurrentIP + "\r\n");
-
String[] LogGetPOSStringArray;
-
LogGetPOSStringArray = str.Split(',');
-
-
if (LogGetPOSStringArray.Length == 18)
-
{
-
SaveNewDataToDataBase(str);
-
UpdatePollingDetail(LogGetPOSStringArray[1]);
-
}
-
else
-
{
-
WriteTOTextFile("logGetPos String Less than 17 words: " + str + " "+ System.DateTime.Now);
-
}
-
-
-
str = ""; // Clearing the String
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
//SavetoDataBase.....
-
}
-
-
-
}
-
-
}
-
}
-
catch (Exception e)
-
{
-
int ipIndex;
-
//m_workerSocket[m_clientCount].Disconnect(true);
-
-
WriteTOTextFile("5: " + e.Message + System.DateTime.Now);
-
//--SocketNo;
-
// textBoxMsg.Text = "Client # " + SocketNo +" connected";
-
////////ipIndex = FindAllOfMyString(CurrentIP);
-
////////if (ipIndex >= 0)
-
////////{
-
//////// lstBoxClientList.Items.RemoveAt(ipIndex);
-
////////}
-
}
-
}
-
-
if (str.IndexOf('&') != -1 && str.IndexOf(',') != -1)
-
{
-
String[] values2 = str.Split(',');
-
-
-
/////////////// Display the IP in rich text box from which the command Ok received
-
if ((str.IndexOf("OK", 0) > 0 || str.IndexOf("Pwd", 0) > 0 || str.IndexOf("Cmd", 0)>0 || str.IndexOf("Param", 0)>0) && values2.Length >=3)
-
{
-
-
richTextBoxCommandOK.AppendText("Recieved : " + str + " from " + CurrentIP + "\n");
-
//richTextBoxSendMsg.AppendText("Recieved : " + str + " from " + CurrentIP + "\n");
-
-
str = "";
-
szData = "";
-
richTextBoxReceivedMsg.Clear();
-
-
-
}
-
////////////
-
-
if( (str.IndexOf('$') != -1) && ((values2.Length == 15) || (values2.Length == 17) || (values2.Length == 18)) && (str.IndexOf(',') != -1))
-
{
-
String existingIPAndDevName;
-
int indexofExistingIPAndDevName;
-
lock (hstIPDev)
-
{
-
// hstIPDev.Remove(values2[1]);
-
// hstIPDev.Add(values2[1],ipData);
-
hstIPDev.Remove(ipData);
-
hstIPDev.Add(ipData,values2[1]);
-
}
-
// MessageBox.Show(str);
-
// existingIPAndDevName = CurrentIP + "," + values2[1];
-
existingIPAndDevName = "," + values2[1];
-
-
//////////////indexofExistingIPAndDevName = FindAllOfMyString(existingIPAndDevName);
-
-
-
//////////////if (indexofExistingIPAndDevName < 0)
-
//////////////{
-
////////////// lstBoxClientList.Items.Add(CurrentIP + "," + values2[1]); // Adding the IP with Device Code in the ListClient
-
////////////// // lstBoxClientList.Items.Add(CurrentIP + "," + values2[1]); // Adding the IP with Device Code in the ListClient
-
//////////////}
-
//////////////else
-
//////////////{
-
////////////// lstBoxClientList.Items.RemoveAt(indexofExistingIPAndDevName);//,CurrentIP + "," + values2[1]); // Adding the IP with Device Code in the ListClient
-
////////////// lstBoxClientList.Items.Add(CurrentIP + "," + values2[1]); // Adding the IP with Device Code in the ListClient
-
//////////////}
-
richTextBoxReceivedMsg.Clear();
-
-
-
if (((values2[1].Equals("0705280114")) || values2[3].Equals("0705280114") && str.IndexOf(',') != -1) && (values2.Length == 15 || values2.Length == 17)) // Device code 8
-
{
-
-
str = str.Trim();
-
-
SaveDataToDataBase(str);
-
-
szData = null;
-
-
richTextBoxReceivedMsg.Clear();
-
}
-
-
//else
-
-
if (((!values2[1].Equals("0705280114")) || !values2[3].Equals("0705280114") && str.IndexOf(',') != -1) && values2.Length == 18) // Devices Other Than Device code 8
-
{
-
-
if (str.IndexOf(',') != -1)
-
{
-
SaveNewDataToDataBase(str);
-
szData = null;
-
}
-
}
-
-
-
txtLastMessageSaved.Text = str;
-
str = "";
-
-
-
-
richTextBoxReceivedMsg.Clear();
-
-
values2 = null;
-
}
-
-
}
-
// Continue the waiting for data on the Socket
-
-
WaitForData(socketData.m_currentSocket);
-
//////lbl_dev_count.Text = lstBoxClientList.Items.Count.ToString();
-
lbl_dev_count.Text = hstIPDev.Count.ToString();
-
//UpdateListofIP(CurrentIP,DevName1);
-
}
-
catch (ObjectDisposedException )
-
{
-
SocketPacket socketData02 = (SocketPacket)asyn.AsyncState;
-
String ipData = socketData02.m_currentSocket.RemoteEndPoint.ToString();
-
hstIPDev.Remove(ipData);
-
-
System.Diagnostics.Debugger.Log(0,"1","\nOnDataReceived: Socket has been closed\n");
-
WriteTOTextFile("5: OnDataReceived: Socket has been closed "+ System.DateTime.Now);
-
-
int indexofIP;
-
////////indexofIP = FindAllOfMyString(CurrentIP);
-
////////if (indexofIP != -1)
-
////////{
-
//////// lstBoxClientList.Items.RemoveAt(indexofIP);
-
////////}
-
// m_workerSocket[m_clientCount].Disconnect(true);
-
// --SocketNo;
-
// textBoxMsg.Text = "Client # " + SocketNo + " connected";
-
//WaitForData(socketData02.m_currentSocket);
-
////////////lbl_dev_count.Text = lstBoxClientList.Items.Count.ToString();
-
lbl_dev_count.Text = hstIPDev.Count.ToString();
-
}
-
catch(SocketException se)
-
{
-
-
//Code To Close the Worker Socket
-
SocketPacket socketData01 = (SocketPacket)asyn.AsyncState;
-
String ipData01;
-
if (socketData01.m_currentSocket != null)
-
{
-
-
ipData01 = socketData01.m_currentSocket.RemoteEndPoint.ToString();
-
//RemoveIPFromHashTable(ip);
-
hstIPDev.Remove(ipData01);
-
-
WriteTOTextFile("8. Closing Worker Socket OrionIP:" + ipData01 + " Worker IP : " + socketData01.m_currentSocket.LocalEndPoint.ToString());
-
socketData01.m_currentSocket.Close();
-
socketData01.m_currentSocket = null;
-
-
-
-
}
-
-
if( se.ErrorCode ==10054)
-
{
-
//CurrentIP= m_workerSocket[m_clientCount].RemoteEndPoint.ToString();
-
// m_workerSocket[m_clientCount].Disconnect(true);
-
lblIPAddress.Text = lblIPAddress.Text + " Remotely Closed" +CurrentIP;
-
// --SocketNo;
-
//textBoxMsg.Text = "Client # " + SocketNo + " connected";
-
richTextBoxAllData.AppendText("Here disconnected :"+ CurrentIP);
-
WriteTOTextFile("6:" + " " + se.NativeErrorCode + " : " + se.Message + System.DateTime.Now);
-
StartListenClick();
-
////int indexofIP;
-
////indexofIP = FindAllOfMyString(CurrentIP);
-
////if( indexofIP != -1)
-
////{
-
//// lstBoxClientList.Items.RemoveAt(indexofIP);
-
////}
-
-
-
//int i;
-
//i=lstBoxClientList.FindString("," + CurrentIP);
-
//lstBoxClientList.Items.RemoveAt(i);
-
}
-
else
-
{
-
//MessageBox.Show ("4 : " + se.ErrorCode + ": " + se.Message );
-
WriteTOTextFile("7: a" + se.ErrorCode + " : " + se.Message + System.DateTime.Now);
-
}
-
-
// WaitForData(socketData01.m_currentSocket);
-
//lbl_dev_count.Text = lstBoxClientList.Items.Count.ToString();
-
lbl_dev_count.Text = hstIPDev.Count.ToString();
-
}
-
}
[HTML]And in this read function when socket Client gets disconnected the byte length of data i recieve is zero and then i check for null ocket and then close the child socket which is not the main socket but one of the socket fin the array list.
Still waiting for solution [/HTML] setiarakeshgps@hotmail.com[/HTML]
http://www.csharphelp.com/archives3/archive486.html
I found this researching your question not sure if it will help but this seems to set the sockets I found it at http://www.csharphelp.com/archives3/archive486.html -
public Server(int port, string title, string attr)
-
{
-
this.portNumber = port;
-
this.title = title;
-
this.maxSockets =10000;
-
connectedSocks = new ArrayList(this.maxSockets);
-
}
-
-
-
///
-
/// Description: Start the threads to listen to the port and process
-
/// messages.
-
///
-
a lot of other code was included maybe you can get an idea from there
hope it helps
[HTML]Rakesh Says Thanks for Reply But alreday i have set 20000 for socket clients in array to handle the processing of data receving from the 60 Clients Below is the Code which i am using[/HTML] - //Start Listen Here On Button click
-
void ButtonStartListenClick(object sender, System.EventArgs e)
-
{
-
-
OPenDataBaseConnectionIfClosed();
-
-
try
-
{
-
// Check the port value
-
if (textBoxPort.Text == "")
-
{
-
MessageBox.Show("Please enter a Port Number");
-
return;
-
}
-
string portStr = textBoxPort.Text;
-
int port = System.Convert.ToInt32(portStr);
-
// Create the listening socket...
-
/* m_mainSocket = new Socket(AddressFamily.InterNetwork,
-
SocketType.Stream,
-
ProtocolType.Tcp);
-
*/
-
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, port);
-
// Bind to local IP Address...
-
//MessageBox.Show("iplocal00" + ipLocal);
-
// m_mainSocket.Bind(ipLocal);
-
-
// Start listening...
-
m_mainSocket.Listen(100000);
-
//MessageBox.Show("iplocal 01" );
-
// Create the call back for any client connections...
-
m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
-
//MessageBox.Show("iplocal 02");
-
-
//UpdateControls(true);
-
//MessageBox.Show("iplocal 03");
-
// lblIPAddress.Text = m_mainSocket.RemoteEndPoint.ToString();
-
// MessageBox.Show("IP Number : " + m_mainSocket.RemoteEndPoint);
-
// lblIPAddress = m_mainSocket.RemoteEndPoint;
-
-
}
-
catch (SocketException se)
-
{
-
lblIPAddress.Text = "6 : Connection Closed";
-
-
WriteTOTextFile("1:" + se.NativeErrorCode + " : " + se.Message + System.DateTime.Now);
-
}
-
-
}
-
-
// This is the call back function, which will be invoked when a client is connected
-
public void OnClientConnect(IAsyncResult asyn)
-
{
-
try
-
{
-
// Here we complete/end the BeginAccept() asynchronous call
-
// by calling EndAccept() - which returns the reference to
-
// a new Socket object
-
//m_mainSocket.
-
-
m_workerSocket[m_clientCount] = m_mainSocket.EndAccept(asyn);
-
-
// Let the worker Socket do the further processing for the
-
// just connected client
-
-
-
-
WaitForData(m_workerSocket[m_clientCount]);
-
-
// Now increment the client count
-
++m_clientCount;
-
++SocketNo;
-
// Display this client connection as a status message on the GUI
-
//String str = String.Format("Client # {0} connected", m_clientCount);
-
String str = String.Format("Client # {0} connected", SocketNo);
-
textBoxMsg.Text = str;
-
SocketNo = m_clientCount;
-
// m_workerSocket[m_clientCount].Ttl = 500;
-
// lblIPAddress.Text;
-
// MessageBox.Show(" : " + m_clientCount + " : ");
-
String ipconnected = m_workerSocket[m_clientCount].RemoteEndPoint.ToString();
-
hstIPDev.Add(ipconnected, "0");
-
lblIPAddress.Text = ":: " + ipconnected;
-
lbl_dev_count.Text = hstIPDev.Count.ToString();
-
// Since the main Socket is now free, it can go back and wait for
-
// other clients who are attempting to connect
-
-
m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
-
-
-
}
-
-
catch (ObjectDisposedException e )
-
{
-
//lblIPAddress.Text = "4 : Connection Closed";
-
System.Diagnostics.Debugger.Log(0, "1", "\n OnClientConnection: Socket has been closed\n");
-
WriteTOTextFile("2 " + e.Message + " : OnClientConnection: Socket has been closed : " + System.DateTime.Now);
-
-
textBoxMsg.Text = String.Format("Client # {0} connected",m_clientCount);
-
-
-
-
}
-
catch (SocketException se)
-
{
-
-
//MessageBox.Show("22" + " ErrorCode " + se.ErrorCode + " : " +se.Message);
-
WriteTOTextFile("3: " + se.NativeErrorCode + " : " + se.Message + System.DateTime.Now);
-
StartListenClick();
-
//m_mainSocket.Close();
-
//StartListenClick();
-
-
}
-
catch (Exception se)
-
{
-
-
//MessageBox.Show("22" + " ErrorCode " + se.ErrorCode + " : " + se.Message);
-
WriteTOTextFile("33: " + " : " + se.Message + System.DateTime.Now);
-
StartListenClick();
-
-
}
-
-
-
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rajesh |
last post by:
Hi,
We have a socket server app in Java and the client application in C++.
When we try to connect 60 clients simultaneously from C++ using
threads, only 55-56 connections are successfull, rest...
|
by: simon place |
last post by:
Spent some very frustrating hours recoding to find a way of closing a server
socket, i'd not thought it would be any problem,
however, after complete failure and as a last resort, i looked at the...
|
by: Tomasz Naumowicz |
last post by:
Hello Everybody,
I have the following problem with sockets.
Socket.Available reports data in the buffer (e.g. 1849 bytes) but
Socket.Read throws an exception because the connection is already...
|
by: jasonsgeiger |
last post by:
From: "Factor" <jasonsgeiger@gmail.com>
Newsgroups: microsoft.public.in.csharp
Subject: Multiple Clients, One port
Date: Wed, 19 Apr 2006 09:36:02 -0700
I'm been working with sockets for a...
|
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...
|
by: Engineerik |
last post by:
I am trying to create a socket server which will listen for connections from
multiple clients and call subroutines in a Fortran DLL and pass the results
back to the client. The asynchronous socket...
|
by: iwdu15 |
last post by:
hi, ive done work with sockets and such before, so its nothing new. thought
id try the Socket.SendFile() method instead of the manual way. however, there
is no Socket.ReceiveFile() method. How do...
|
by: samyphp |
last post by:
i am trying to broadcast continuous data from server using udp connection...
while accessing from single client its working fine...
but while accessing from multiple clients its not working and...
|
by: Airslash |
last post by:
Hello,
The problem is that my server is not receiving data.
The code below are the various classes I designed around sockets. It will be big...
I have run the code with the debugger, and I see...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |