Click here to Skip to main content
16,011,839 members
Home / Discussions / C#
   

C#

 
AnswerRe: Datagridview cell painting Pin
Jake Myers29-Apr-09 22:34
Jake Myers29-Apr-09 22:34 
GeneralRe: Datagridview cell painting Pin
Dan Neely30-Apr-09 8:41
Dan Neely30-Apr-09 8:41 
GeneralRe: Datagridview cell painting Pin
Jake Myers1-May-09 4:20
Jake Myers1-May-09 4:20 
GeneralRe: Datagridview cell painting Pin
Dan Neely1-May-09 4:37
Dan Neely1-May-09 4:37 
GeneralRe: Datagridview cell painting [modified] Pin
Jake Myers1-May-09 5:06
Jake Myers1-May-09 5:06 
QuestionUnlocking account in AD Pin
Jacob Dixon18-Mar-09 7:53
Jacob Dixon18-Mar-09 7:53 
QuestionHelp understanding C# sockets Pin
John Joger18-Mar-09 7:47
John Joger18-Mar-09 7:47 
AnswerRe: Help understanding C# sockets Pin
John Joger21-Mar-09 16:23
John Joger21-Mar-09 16:23 
This is my code so far. I'm having problems to integrate a hashtable into the server but can get one working in its own.

Any help appreciated.

using System;
using System.Collections;
using System.Net.Sockets;
using System.Linq;
using System.Text;
using System.IO;

namespace Server
{
    class Program
    {
        static void Main(string[] args)
        {
            runServer();
        }

        static public void runServer()
        {
            TcpListener listener;
            Socket connection;
            NetworkStream socketStream;
            int port = 43;
            
            try
            {
                listener = new TcpListener(port);
                listener.Start();
                Console.WriteLine(" Whereis Server Started....");
                while (true)
                {
                    connection = listener.AcceptSocket();
                    socketStream = new NetworkStream(connection);
                    doRequest(socketStream);
                    socketStream.Close();
                    connection.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.ToString());
                //log.log(e.ToString());
            }
        }

        //Stores person and location string
        //Hashtable table = new Hashtable();

        static void doRequest(NetworkStream socketStream)
        {
            StreamWriter sw = new StreamWriter(socketStream);
            StreamReader sr = new StreamReader(socketStream);

            String cmd = sr.ReadLine(); //here cmd is either going to be <person> or <person> <space> <location>
            
            Hashtable table = new Hashtable();
            table.Add("bob", "in bed");
            table.Add("sam", "test_location2");
            table.Add("mark", "test_location3");

        if (cmd.Contains(' ')) //If cmd contains a <space> it must be a request to update a persons location
        {
                String person = cmd;
                
                //Finds the position of the <space> character in the string and 
                //then uses that position to cut the string into a new substring.
                int SpaceChr = person.IndexOf(" ");
                person = person.Substring(0,SpaceChr);
                Console.WriteLine("person test <" + person + ">");

                String location = cmd;
                SpaceChr++;
                location = location.Substring(SpaceChr);
                Console.WriteLine("location test <" + location + ">");
            
                table.Add(person, location);
                table[person] = location;

                sw.WriteLine(person + " location changed to " + location);
                Console.WriteLine("\n" + person + " location changed to " + location);
                sw.Flush();
        }
        else //If cmd doesn't contain a <space> then it must be a lookup request
        { 
            String person = cmd; 
            Console.WriteLine("Request for " + person + "\n\nReplied " + table[person]);
            sw.WriteLine(person + " is " + table[person]);
            sw.Flush();
        }
              
        }
    }
}




<pre>using System;
using System.Collections;
using System.Net.Sockets;
using System.Linq;
using System.Text;
using System.IO;

namespace HashTableTest
{
    class Program
    {
        static void Main(string[] args)
        {
            //Hashtable table = new Hashtable();
            //table.Add("bob", "test_location");
            //table.Add("sam", "test_location2");
            //table.Add("mark", "test_location3");
            //Console.WriteLine("Has the hashtable worked:" + table["bob"]);
            //Console.ReadLine();

            string name = "bob";
            string location = "at home";
            
            Hashtable table = new Hashtable();
            table.Add(name, location);
            table.Add("sam", "test_location2");
            table.Add("mark", "test_location3");

            //table.Add(person, location);
            //table[person] = location;

            Console.WriteLine("Has the hashtable worked:" + table[name]);
            Console.ReadLine();
        }
    }
}


using System;
using System.Net.Sockets;
using System.IO;
public class Whois
{
    static void Main(string[] args)
    {
        
        string name = "localhost";

        int port = 43;
        
        TcpClient client = new TcpClient();

        Console.WriteLine("Whereis Server Requested...\n");
        
        try
        {
            client.Connect(name, port);
        }
        catch (Exception noServer)
        {
            Console.WriteLine("Server refused connection. Is the server up and listening on port " + port + "? \n");
            Console.WriteLine("Exception: \n\n" + noServer.ToString());   
        }
        StreamWriter sw = new StreamWriter(client.GetStream()); 
        StreamReader sr = new StreamReader(client.GetStream());

        Console.WriteLine("Client:");
        string person = args[0];

        if (args.Length > 1)
        {
            string location = args[1];
            sw.WriteLine(person + " " + location);
            
            Console.WriteLine("Attempting to Change location of <" + person + "> to <" + location + ">\n");
        }
        else
        {
            Console.WriteLine("Looking up <" + person + ">");
            sw.WriteLine(person);
        }
        
        sw.Flush(); //sends sw
        
        Console.WriteLine("Server:\n" + sr.ReadToEnd());
        Console.ReadLine(); //holds window open
    }
}

QuestionXML root element changes after manipulating XML file. Need help. Pin
shira_me18-Mar-09 7:39
shira_me18-Mar-09 7:39 
AnswerRe: XML root element changes after manipulating XML file. Need help. Pin
bgato2k618-Mar-09 11:02
bgato2k618-Mar-09 11:02 
QuestionHow old is F# ? Pin
Mohammad Dayyan18-Mar-09 7:29
Mohammad Dayyan18-Mar-09 7:29 
AnswerRe: How old is F# ? Pin
Yusuf18-Mar-09 7:35
Yusuf18-Mar-09 7:35 
GeneralRe: How old is F# ? Pin
Mohammad Dayyan18-Mar-09 8:19
Mohammad Dayyan18-Mar-09 8:19 
GeneralRe: How old is F# ? Pin
Judah Gabriel Himango18-Mar-09 8:55
sponsorJudah Gabriel Himango18-Mar-09 8:55 
AnswerRe: How old is F# ? Pin
musefan18-Mar-09 7:35
musefan18-Mar-09 7:35 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 7:50
Ravadre18-Mar-09 7:50 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 7:57
0x3c018-Mar-09 7:57 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 8:07
Ravadre18-Mar-09 8:07 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 8:19
0x3c018-Mar-09 8:19 
GeneralRe: How old is F# ? Pin
Mohammad Dayyan18-Mar-09 8:26
Mohammad Dayyan18-Mar-09 8:26 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 8:38
0x3c018-Mar-09 8:38 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 8:46
Ravadre18-Mar-09 8:46 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 8:55
0x3c018-Mar-09 8:55 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 9:25
Ravadre18-Mar-09 9:25 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 9:34
0x3c018-Mar-09 9:34 

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.