Click here to Skip to main content
15,917,005 members
Home / Discussions / C#
   

C#

 
QuestionSourceGrid 2 Pin
goldjoer1-Dec-05 23:15
goldjoer1-Dec-05 23:15 
Questiondesign report at runtime? Pin
dinh van hai1-Dec-05 22:52
dinh van hai1-Dec-05 22:52 
QuestionPrinting Theory?!??! Pin
tatchung1-Dec-05 22:22
tatchung1-Dec-05 22:22 
AnswerRe: Printing Theory?!??! Pin
mcljava2-Dec-05 10:56
mcljava2-Dec-05 10:56 
GeneralRe: Printing Theory?!??! Pin
tatchung4-Dec-05 14:55
tatchung4-Dec-05 14:55 
QuestionHow to get the Windows color theme? Pin
Pikebu1-Dec-05 21:46
Pikebu1-Dec-05 21:46 
AnswerRe: How to get the Windows color theme? Pin
Insincere Dave2-Dec-05 6:20
Insincere Dave2-Dec-05 6:20 
Questionsocket - client Pin
Ankit Aneja1-Dec-05 20:29
Ankit Aneja1-Dec-05 20:29 
i am doing here some some socket-client work in C# windows service
it is working fine for multiple clientss
now i want to limit these multiple clients to 25 for example
i want that when service starts objects for all these 25 clients
are created and when client connects it should be accepted and will not allow more than 25 clients to connect
and when client diconnects that object can be allocated to another client who requests
i am not able to make up logic how i will first create 25 objects and store them in array
and how i will be checking wether object is free or not to be allocated to another client


code:

protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
listen obj;
Thread threadlisten=null;
obj=new listen();
threadlisten =new Thread(new ThreadStart(obj.startlisten));
threadlisten.Start();
}



in listen class listen.cs

public class listen
{
TcpListener server=null;
Thread tcpthread=null;
client cl=null;
public listen()
{
//
// TODO: Add constructor logic here
//
}
public void startlisten()
{
Int32 port = 3310;
IPAddress localAddr = IPAddress.Parse("192.168.0.5");

// TcpListener server = new TcpListener(port);
server = new TcpListener(localAddr, port);

// Start listening for client requests.
server.Start();

// Enter the listening loop.
while(true)
{


// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
cl= new client(server.AcceptTcpClient());
tcpthread=new Thread(new ThreadStart(cl.getClient));
tcpthread.Start();

}
}
public void stoplisten()
{
server.Stop();
}
}


in client class client.cs

public class client
{
TcpClient tcpClient;

// Buffer for reading data
Byte[] bytes = new Byte[256];
String data = null;
public client(TcpClient Client)
{
//
// TODO: Add constructor logic here
tcpClient =Client;
}
public void getClient()
{
try
{
data = null;

// Get a stream object for reading and writing
NetworkStream stream = tcpClient.GetStream();

int i;

// Loop to receive all the data sent by the client.
while((i = stream.Read(bytes, 0, bytes.Length))!=0)
{
// Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);

// Process the data sent by the client.
string replyMsg = data;
clamdCommand x=new clamdCommand();
replyMsg=x.Command(replyMsg);

byte[] msg = System.Text.Encoding.ASCII.GetBytes(replyMsg);

// Send back a response.
stream.Write(msg, 0, msg.Length);
//Console.WriteLine(String.Format("Sent: {0}", data));
}
}
catch(Exception se)
{
}

// Shutdown and end connection
tcpClient.Close();
}
}


Ankit Aneja
"Nothing is impossible. The word itself says - I M possible"

AnswerRe: socket - client Pin
mcljava2-Dec-05 7:45
mcljava2-Dec-05 7:45 
Questionis it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
sridevi20051-Dec-05 19:26
sridevi20051-Dec-05 19:26 
AnswerRe: is it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
S. Senthil Kumar1-Dec-05 20:15
S. Senthil Kumar1-Dec-05 20:15 
GeneralRe: is it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
sridevi20052-Dec-05 17:50
sridevi20052-Dec-05 17:50 
AnswerRe: is it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
leppie1-Dec-05 20:18
leppie1-Dec-05 20:18 
GeneralRe: is it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
sridevi20051-Dec-05 23:10
sridevi20051-Dec-05 23:10 
GeneralRe: is it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
Rob Philpott1-Dec-05 23:26
Rob Philpott1-Dec-05 23:26 
GeneralRe: is it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
sridevi20052-Dec-05 17:33
sridevi20052-Dec-05 17:33 
GeneralRe: is it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
leppie1-Dec-05 23:29
leppie1-Dec-05 23:29 
GeneralRe: is it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
Alvaro Mendez2-Dec-05 3:31
Alvaro Mendez2-Dec-05 3:31 
GeneralRe: is it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
Dan Neely2-Dec-05 3:58
Dan Neely2-Dec-05 3:58 
GeneralRe: is it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
Rob Philpott1-Dec-05 23:24
Rob Philpott1-Dec-05 23:24 
GeneralRe: is it possible for string type constants to be declared in interfaces in C#.net,urgent plz Pin
sridevi20052-Dec-05 17:49
sridevi20052-Dec-05 17:49 
QuestionAny good algorithm for Indexing Pin
adi024461-Dec-05 18:12
adi024461-Dec-05 18:12 
AnswerRe: Any good algorithm for Indexing Pin
Judah Gabriel Himango1-Dec-05 18:26
sponsorJudah Gabriel Himango1-Dec-05 18:26 
GeneralRe: Any good algorithm for Indexing Pin
adi024463-Dec-05 16:44
adi024463-Dec-05 16:44 
QuestionProcess Execution Detection Pin
Shanila1231-Dec-05 17:26
Shanila1231-Dec-05 17:26 

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.