Click here to Skip to main content
15,890,506 members
Home / Discussions / C#
   

C#

 
AnswerRe: Finalizer problem Pin
mav.northwind7-Dec-05 1:14
mav.northwind7-Dec-05 1:14 
AnswerRe: Finalizer problem Pin
S. Senthil Kumar7-Dec-05 1:28
S. Senthil Kumar7-Dec-05 1:28 
QuestionPublish COM class from inside a WindowsForms application? Pin
mav.northwind6-Dec-05 23:13
mav.northwind6-Dec-05 23:13 
QuestionCommunicating with Macromedia Flash in .Net Pin
Hadi Riazi6-Dec-05 21:32
Hadi Riazi6-Dec-05 21:32 
Questionsave aimage from the form in .jpeg format Pin
dhol6-Dec-05 20:21
dhol6-Dec-05 20:21 
QuestionConvert int to int[ ]? Pin
MudkiSekhon6-Dec-05 20:12
MudkiSekhon6-Dec-05 20:12 
AnswerRe: Convert int to int[ ]? Pin
S. Senthil Kumar6-Dec-05 20:29
S. Senthil Kumar6-Dec-05 20:29 
Questionsocket-client Pin
Ankit Aneja6-Dec-05 19:41
Ankit Aneja6-Dec-05 19:41 
Hi i am pasting my code belo which is giving error

System.NullReferenceException' occurred in
Additional information: Object reference not set to an instance of an object.

it breaks on line
if(cl[i].status==true) in listen class

code for listen class
public class listen
{
TcpListener server=null;
Thread tcpthread=null;
client[] cl=new client[5];

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.
// for(int i=0;i<5;i++)
// {
// cl[i].status=true;
// }
Boolean flag;
while(true)
{ flag=false;
// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
for(int i=0;i<5;i++)
{
if(cl[i].status==true)
{
cl[i]= new client(server.AcceptTcpClient());
tcpthread=new Thread(new ThreadStart(cl[i].getClient));
tcpthread.Start();
flag=true;
break;
}
}
if(flag!=true)
{
//display error message
}


}

}
}




code for client class

public class client
{
TcpClient tcpClient;
public Boolean status;
// Buffer for reading data
Byte[] bytes = new Byte[256];
String data = null;


public client()
{ //
// TODO: Add constructor logic here
//
//status=true;
}
public client(TcpClient Client)
{
tcpClient =Client;
//
// TODO: Add constructor logic here
//
status=false;
}
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)
{
MessageBox.Show(se.ToString());
}
// Shutdown and end connection
tcpClient.Close();
status=true;
}
}

Ankit Aneja
"Nothing is impossible. The word itself says - I M possible"
AnswerRe: socket-client Pin
Vikram A Punathambekar6-Dec-05 21:59
Vikram A Punathambekar6-Dec-05 21:59 
GeneralRe: socket-client Pin
Ankit Aneja6-Dec-05 22:31
Ankit Aneja6-Dec-05 22:31 
QuestionSynchronization Require inStatic Function Call! Pin
majidbhutta6-Dec-05 17:54
majidbhutta6-Dec-05 17:54 
AnswerRe: Synchronization Require inStatic Function Call! Pin
S. Senthil Kumar7-Dec-05 1:33
S. Senthil Kumar7-Dec-05 1:33 
GeneralRe: Synchronization Require inStatic Function Call! Pin
majidbhutta7-Dec-05 3:33
majidbhutta7-Dec-05 3:33 
GeneralRe: Synchronization Require inStatic Function Call! Pin
S. Senthil Kumar7-Dec-05 4:12
S. Senthil Kumar7-Dec-05 4:12 
GeneralRe: Synchronization Require inStatic Function Call! Pin
majidbhutta7-Dec-05 4:26
majidbhutta7-Dec-05 4:26 
GeneralRe: Synchronization Require inStatic Function Call! Pin
S. Senthil Kumar7-Dec-05 4:35
S. Senthil Kumar7-Dec-05 4:35 
GeneralRe: Synchronization Require inStatic Function Call! Pin
majidbhutta7-Dec-05 5:07
majidbhutta7-Dec-05 5:07 
QuestionI don't want to display Relation name on DataGrid Pin
dhtuan6-Dec-05 16:21
dhtuan6-Dec-05 16:21 
QuestionTreeView CheckBoxes, but not their children Pin
meatago6-Dec-05 14:28
meatago6-Dec-05 14:28 
QuestionSkeleton Key Cryptography Pin
MrEyes6-Dec-05 13:10
MrEyes6-Dec-05 13:10 
AnswerRe: Skeleton Key Cryptography Pin
Paul Conrad6-Dec-05 13:57
professionalPaul Conrad6-Dec-05 13:57 
QuestionHard Drive Firmware Serial Number Pin
theladsmith6-Dec-05 11:03
theladsmith6-Dec-05 11:03 
QuestionLocalizable application Pin
machocr6-Dec-05 10:36
machocr6-Dec-05 10:36 
AnswerRe: Localizable application Pin
lmoelleb6-Dec-05 20:45
lmoelleb6-Dec-05 20:45 
GeneralRe: Localizable application Pin
machocr7-Dec-05 3:10
machocr7-Dec-05 3:10 

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.