Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
A

Ajithevn

@Ajithevn
About
Posts
36
Topics
17
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • problem with client/server application
    A Ajithevn

    there are 2 systems with ips 192.168.1.87(clientA,serverA) and 192.168.1.35(clientB,serverB) . on both the systems client and server runs. now clientA sends a message to serverB on button click. as soon as serverB recieves a message it should send that message to ClientB how is that possible clientA--->serverB(onmessagerecieved)--->cientB

    server:-
    int recv;
    byte[] data = new byte[1024];
    IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 10294);
    Socket newsock = new Socket(AddressFamily.InterNetwork,
    SocketType.Dgram, ProtocolType.Udp);
    newsock.Bind(ipep);
    newsock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Any, IPAddress.Parse("127.0.0.1")));

    while (true)
    {
    IPEndPoint sender2 = new IPEndPoint(IPAddress.Any, 0);
    IPEndPoint sender1 = new IPEndPoint(IPAddress.Parse("192.168.1.35") , 0);
    EndPoint tmpRemote = (EndPoint)(sender2);
    EndPoint tmpRemote1 = (EndPoint)(sender1);
    data = new byte[1024];
    recv = newsock.ReceiveFrom(data, ref tmpRemote);
    Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
    string welcome = "7010";
    data = Encoding.ASCII.GetBytes(welcome);
    newsock.SendTo(data, data.Length, SocketFlags.None, tmpRemote1 );
    }

    client:-
    IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("192.168.1.35"), 10294);
    byte[] data = new byte[1024];
    Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

    private void Form1_Load(object sender, EventArgs e)
    {
    client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 10);
    }
    private void button1_Click(object sender, EventArgs e)
    {
    string welcome = "What's your IP?";
    data = Encoding.ASCII.GetBytes(welcome);
    client.SendTo(data, data.Length, SocketFlags.None, ipep);
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
    IPEndPoint server = new IPEndPoint(IPAddress.Any, 0);
    EndPoint tmpRemote = (EndPoint)server;
    data = new byte[1024];
    int recv = client.ReceiveFrom(data, ref tmpRemote);
    this.richTextBox1.Text = Encoding.ASCII.GetString(data, 0, recv);
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
    client.Close();
    }

    C# help sysadmin tutorial

  • problem with client/server application
    A Ajithevn

    how to send the message sent from one client to another client, plz help me.

    C# help sysadmin tutorial

  • multiple socket connection
    A Ajithevn

    Hi all, Can somebody help me on how to create multiple connection to different server using ip/port at the same time and receive data. I have a program in C# but it's only working for 1 connection. Please help me or redirect me for a tutorial on multiple socket programming in C#. I'm new to this thing.

    C# tutorial csharp sysadmin help

  • how to create multiple connections in a client application
    A Ajithevn

    i have tried running threads in this format. but this also works only if button is clicked and only for 4 times but i wish 1 client to connect to the server when button is clicked and other client will connect and close for each minute. the code is:-

    private void button1_Click(object sender, EventArgs e)
    {
    for (int i = 0; i < 4; i++)
    {
    Thread thread = new Thread(new ParameterizedThreadStart(round));
    thread.Start();
    thread.Join();
    Thread.Sleep(100);
    }
    }
    private void round(object val)
    {
    System.Net.IPAddress myIP;
    System.Net.IPEndPoint myServer;
    Socket socket;
    string ip = (string)val;

            try
            {
                myIP = System.Net.IPAddress.Parse(ip);
                myServer = new System.Net.IPEndPoint(myIP, Int32.Parse("20000"));
                socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream ,ProtocolType.Tcp);
                socket.Connect(myServer);
                NetworkStream netStream=new NetworkStream(socket);
                Byte\[\] byteMessage=new Byte\[640\];
                string sendMessage="hello server";
                byteMessage=System.Text.Encoding.Default.GetBytes( sendMessage.ToCharArray());
                netStream.Write(byteMessage,0,byteMessage.Length);
                netStream.Flush();
                netStream.Close();
                socket.Close();
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
    
    C# help tutorial

  • how to create multiple connections in a client application
    A Ajithevn

    can u be more specific im not getting any idea about it. you mean to say when client send or recieve a msg run a new thread and reconnect to the server

    C# help tutorial

  • how to create multiple connections in a client application
    A Ajithevn

    Bjorn Spruit wrote:

    Is it a database connection you wish to establish ?

    No its not a database connection. it is a socket connection between the client and the server of the remote machine

    C# help tutorial

  • how to create multiple connections in a client application
    A Ajithevn

    i have a client application i which i need to connect to the remote machine on click of a button and localhost on every minute.is it possible. plz help me.

    C# help tutorial

  • how to send and recieve data from different ip using socket server
    A Ajithevn

    Thanks for the help

    C# sysadmin help tutorial

  • how to send and recieve data from different ip using socket server
    A Ajithevn

    Richard MacCutchan wrote:

    I don't understand this - how can Client-A receive a message from Client-A?

    im sorry i did not explain it properly its not that "Client-A receive a message from Client-A" Client-A sends a msg to a different machine which contains a server and Client-B(168.132.2.5). so when the server recieve the msg how to send that msg to Client-B

    Richard MacCutchan wrote:

    If the client needs to communicate with more than one server then it needs a socket connection for each one.

    here client is not communicating with more than one server it is multiple clients communicating with one server. where clients are on different machines. one machine contains both client as well a server(Client-B,Server). one machine contains only client(Client-A). Client-A--->Server--->Client-B

    modified on Tuesday, October 20, 2009 7:15 AM

    C# sysadmin help tutorial

  • how to send and recieve data from different ip using socket server
    A Ajithevn

    If there are 2 machine Client-A(168.132.2.3) and Client-B(168.132.2.5) with these ip. Client-A connects to server with IP address specified in the socket as "Client-B(168.132.2.5)" and recieve a message from Client-A as soon as the message is recieved i need to send that message to Client-B. how is that possible?

    C# sysadmin help tutorial

  • how to send and recieve data from different ip using socket server
    A Ajithevn

    Hi all sorry for reposting.Im using socket programming to send data from one system to another.im running client and server on both systems.my problem is when i send a message from client of one system it reaches the server of other system, how to send that recieved data to localhost client. below is the code:-

    client:-

    private void sendButton_Click(object sender, EventArgs e)
    {
    TcpClient socketForServer;
    try
    {
    socketForServer = new TcpClient(_ip of sending machine , 10);

            }
            catch
            {
                MessageBox.Show("Failed to connect to server at {0}:999", \_machineName); 
                return;
            }
            NetworkStream networkStream = socketForServer.GetStream();            
            System.IO.StreamWriter streamWriter =
            new System.IO.StreamWriter(networkStream);
            System.IO.StreamReader streamReader =
            new System.IO.StreamReader(networkStream);
            try
            {
                streamWriter.WriteLine(this.messageTextBox.Text);                    
                streamWriter.Flush();
                this.messageTextBox.Clear();
                this.messageTextBox.ReadOnly = true; 
                this.messageTextBox.Text = streamReader.ReadLine(); 
             
            }
            catch
            {
                MessageBox.Show("Exception reading from Server");  
            }
            // tidy up
            networkStream.Close();            
    
        }
    

    Server:-

    TcpListener tcpListener = new TcpListener(10);
    tcpListener.Start();

            while (true)
            {
                Socket socketForClient = tcpListener.AcceptSocket();                
                NetworkStream networkStream = new NetworkStream(socketForClient);                
                System.IO.StreamReader streamReader =
                new System.IO.StreamReader(networkStream);               
                string theString = streamReader.ReadLine();
                MessageBox.Show(theString);  //message recieved how to send this back to local host           
                streamReader.Close();
                networkStream.Close();
                socketForClient.Close();
            }
    

    IF Clinet-B connects to server and sends message, before disconnecting how can Client-A connect to servere.

    C# sysadmin help tutorial

  • how to use runonce registry service?
    A Ajithevn

    1)HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce how to invoke this? or call this? or execute this key? 2)can we uninstall a setup created for a c# windows application on shutdown of system using RunOnce.

    C# csharp windows-admin help tutorial question

  • [Message Deleted]
    A Ajithevn

    [Message Deleted]

    C#

  • how to use runonce registry service?
    A Ajithevn

    Hi all i have no idea about run services.i googled a lot but i could not find much of help. plz help me about:- 1)how to use runonce registry service? 2)can i use it from my c# application? 3)i got to know that i need to create a batch file, can that batch file be destroied after it is being executed? http://www.catch22.net/tuts/selfdel[^] i have checked this link from this only i got few ideas 4)can the batch file contain task to be performed on shutdown of the system if so can yo help me with a sample? 5)where to place the batch file and when to execute it from my application?

    C# csharp windows-admin help tutorial question

  • Uninstall on shutdown
    A Ajithevn

    sorry for reposting is there any other means by which i can do it plz help me

    C# csharp question workspace

  • Uninstall on shutdown
    A Ajithevn

    Hi on system shutdown can i uninstall a installed setup of c# applicaton?

    C# csharp question workspace

  • form closing reason problem
    A Ajithevn

    sorry to say u this method has no effect on the shutdown procedure of windows

    C# help windows-admin

  • form closing reason problem
    A Ajithevn

    i tried to stop the form closing event also i that case it is giving me some error. which states the formate of the file is not correct i dont find any link between this error and my application. plz help me

    C# help windows-admin

  • form closing reason problem
    A Ajithevn

    im not uninstalling the same application that im running im uninstalling any setup1 if previosly installed by me by mistake.

    C# help windows-admin

  • form closing reason problem
    A Ajithevn

    Hi all on form closing event i check if it is windows shutdown and if yes i uninstall the program it is not working for me. i tried writting to a log file on form closing event if it is windows shutdown it worked. from another application on ckick of a button also the uninstall program worked. plz help me

    private void ChatApplication_FormClosing(object sender, FormClosingEventArgs e)
    {
    if (e.CloseReason == CloseReason.WindowsShutDown)
    {

                Uninstall();
                
            }            
    
        }
    

    private static void Uninstall()
    {
    Process oProcess = new Process();
    oProcess.StartInfo.FileName = "cmd.exe";
    oProcess.StartInfo.CreateNoWindow = true;
    oProcess.StartInfo.UseShellExecute = false;
    RegistryKey oRegKey = null;
    string sUninstallString = "";

            string\[\] asSubKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\").GetSubKeyNames();
            foreach (string sSubKey in asSubKeys)
            {
                oRegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + sSubKey);
                if (oRegKey.GetValue("Displayname") != null && oRegKey.GetValue("Displayname").ToString() == "Setup1")
                {
                    sUninstallString = oRegKey.GetValue("Uninstallstring").ToString();
                    break;
                }
            }
    
            if (sUninstallString.LastIndexOf("exe") != (sUninstallString.Length - 3))
            {
                sUninstallString = sUninstallString.Remove(0, 14);
                oProcess.StartInfo.Arguments = "/k msiexec.exe /x" + sUninstallString;
            }
            else
            {
                sUninstallString = sUninstallString.Replace("C:\\\\", "");
                string sExe = sUninstallString.Substring(sUninstallString.LastIndexOf('\\\\') + 1);
                sUninstallString = sUninstallString.Remove(sUninstallString.LastIndexOf('\\\\'));
                oProcess.StartInfo.Arguments = ("/k cd\\\\ & cd " + sUninstallString + " & " + sExe);
            }
            oProcess.StartInfo.RedirectStandardError = true;
            oProcess.Start();
            oProcess.WaitForExit();
            oProcess.Close();
            oProcess.Dispose();
        }
    
    C# help windows-admin
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups