I used a component for socket connection in C#
I connect 10 tcp object to server by threading. and I get the recived data in an Event (Data_OnRecived)
here is my code:
// Connect Function
private void Connect(object State)
{
Tcp tcp = (Tcp)State;
TcpSession tcpSession = new TcpSession();
tcpSession.RemoteEndPoint = new Dart.Sockets.IPEndPoint(IP, Convert.ToInt32(Port));
tcpSession.ConnectTimeout = 1;
try
{
tcp.Connect(tcpSession);
}
catch(System.Net.Sockets.SocketException ex) {
tcp.Marshal(ex);
}
}
// Initial TCP component
private void TcpInitialize()
{
for (int i = 0; i < MaxConnection; i++)
{
SocketControl[i].TCPConnection = new Tcp();
SocketControl[i].TCPConnection.Data += new System.EventHandler<Dart.Sockets.DataEventArgs>(this.tcp_Data);
SocketControl[i].TCPConnection.Start(Connect, SocketControl[i].TCPConnection);
SocketControl[i].TCPConnection.Tag = i;
}
}
and TCP_Data Event handler that fire when data recived:
void tcp_Data(object sender, Dart.Sockets.DataEventArgs e)
{
TCP tcp = (TCP) Sender;
int GlobalVariable = tcp.Tag;
}
my problem is here that tcp_Data will run in threading mode, not in Queque and one by one. can I change it that this event dont start in threading mode?? I mean every data that recived, fire the tcp_Data after another one.
Thanks for any helping