Click here to Skip to main content
15,918,243 members
Home / Discussions / C#
   

C#

 
QuestionLDAP DirectoryEntry and Exceptions. Pin
Mike Doner3-Sep-10 8:20
Mike Doner3-Sep-10 8:20 
AnswerRe: LDAP DirectoryEntry and Exceptions. Pin
Henry Minute3-Sep-10 10:04
Henry Minute3-Sep-10 10:04 
QuestionRead Table of Content from PDF using PDFBOX library Pin
Nilesh Araligidad3-Sep-10 3:55
Nilesh Araligidad3-Sep-10 3:55 
AnswerRe: Read Table of Content from PDF using PDFBOX library Pin
Dave Kreskowiak3-Sep-10 4:53
mveDave Kreskowiak3-Sep-10 4:53 
QuestionMouseMove-Event without moving the mouse on Windows 7? Pin
Bernhard Hiller3-Sep-10 3:37
Bernhard Hiller3-Sep-10 3:37 
AnswerRe: MouseMove-Event without moving the mouse on Windows 7? Pin
jtobikidd15-Sep-10 4:46
jtobikidd15-Sep-10 4:46 
AnswerRe: MouseMove-Event without moving the mouse on Windows 7? Pin
Pawel Gielmuda16-Feb-11 22:44
Pawel Gielmuda16-Feb-11 22:44 
QuestionThreaded client server connection problems Pin
teknolog1233-Sep-10 3:07
teknolog1233-Sep-10 3:07 
hi, I'm using the below code for my client/server application.The question is, it creates a new connection each time it triggered by the timer and the number of sockets in the arraylist(alSockets) increases. What is the ideal way?

if you don't mind, I have another question;
if a client is sending two requests, server has to reply those two requests. If server replies only one instead of two, an exception is thrown. Sometimes I may need to send three requests, how can I prepare the server so that no exception is thrown

//Server
 public void listenerThread()
        {
            IPHost = Dns.GetHostEntry(Dns.GetHostName());
            TcpListener tcpListener = new TcpListener(IPHost.AddressList[0], 8080);
            tcpListener.Start();
            while (true)
            {
                Socket listenerSocket = tcpListener.AcceptSocket();

                if (listenerSocket.Connected)
                {
                    lock (this)
                    {
                        alSockets.Add(listenerSocket);
                    }
                    Thread thdHandler = new Thread(new ThreadStart(handlerThread));
                    thdHandler.Start();
                }
            }
        }

        public void handlerThread()
        {
            Socket handlerSocket = (Socket)alSockets[alSockets.Count - 1];
            NetworkStream networkStream = new NetworkStream(handlerSocket);
            ntrStream = new NetworkStream(handlerSocket);
            strRead = new StreamReader(ntrStream);
            strWrite = new StreamWriter(ntrStream);

            string textFromClient = strRead.ReadLine(); 
            if (handlerSocket.Connected)
            {
                //the code
            }
        }


//Client

private void timer1_Tick(object sender, EventArgs e) //triggered every minute
        {
            connectToServer();
        }

private void connectToServer()
        {
            IPHostEntry ipHost = Dns.GetHostEntry(server);
            try
            {
                client = new TcpClient(ipHost.AddressList[0].ToString(), 8080);
                ntrStream = client.GetStream();
                streamWrite = new StreamWriter(ntrStream);

                streamYaz.WriteLine("textToServer");
                streamYaz.Flush();

                ntrStream.Close();
                streamWrite.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("No Connection"); 
            }
        }

AnswerRe: Threaded client server connection problems Pin
Ian Shlasko3-Sep-10 3:28
Ian Shlasko3-Sep-10 3:28 
GeneralRe: Threaded client server connection problems Pin
teknolog1234-Sep-10 5:07
teknolog1234-Sep-10 5:07 
GeneralRe: Threaded client server connection problems Pin
Ian Shlasko4-Sep-10 5:30
Ian Shlasko4-Sep-10 5:30 
QuestionCheck if File is in Use Pin
MumbleB3-Sep-10 1:42
MumbleB3-Sep-10 1:42 
AnswerRe: Check if File is in Use Pin
OriginalGriff3-Sep-10 1:59
mveOriginalGriff3-Sep-10 1:59 
AnswerRe: Check if File is in Use Pin
Dave Kreskowiak3-Sep-10 2:17
mveDave Kreskowiak3-Sep-10 2:17 
AnswerRe: Check if File is in Use Pin
Łukasz Nowakowski3-Sep-10 3:13
Łukasz Nowakowski3-Sep-10 3:13 
QuestionHow to access public varialbes in C# class Pin
Joe Rozario3-Sep-10 1:31
Joe Rozario3-Sep-10 1:31 
AnswerRe: How to access public varialbes in C# class Pin
#realJSOP3-Sep-10 1:34
professional#realJSOP3-Sep-10 1:34 
GeneralRe: How to access public varialbes in C# class Pin
Joe Rozario3-Sep-10 1:39
Joe Rozario3-Sep-10 1:39 
AnswerRe: How to access public varialbes in C# class Pin
AspDotNetDev3-Sep-10 11:50
protectorAspDotNetDev3-Sep-10 11:50 
GeneralRe: How to access public varialbes in C# class Pin
Ravi Bhavnani5-Sep-10 19:02
professionalRavi Bhavnani5-Sep-10 19:02 
AnswerRe: How to access public varialbes in C# class Pin
Pete O'Hanlon3-Sep-10 1:42
mvePete O'Hanlon3-Sep-10 1:42 
GeneralRe: How to access public varialbes in C# class Pin
Joe Rozario3-Sep-10 18:38
Joe Rozario3-Sep-10 18:38 
GeneralRe: How to access public varialbes in C# class Pin
Pete O'Hanlon3-Sep-10 21:43
mvePete O'Hanlon3-Sep-10 21:43 
QuestionAvoiding exceptions in socket programming Pin
Rob Philpott3-Sep-10 0:49
Rob Philpott3-Sep-10 0:49 
AnswerRe: Avoiding exceptions in socket programming Pin
Not Active3-Sep-10 1:06
mentorNot Active3-Sep-10 1:06 

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.