Click here to Skip to main content
15,889,876 members
Home / Discussions / C#
   

C#

 
AnswerRe: Telerik WinForm Library? Pin
Piratenwichtl200019-Aug-09 1:31
Piratenwichtl200019-Aug-09 1:31 
GeneralRe: Telerik WinForm Library? Pin
Jörgen Sigvardsson19-Aug-09 1:34
Jörgen Sigvardsson19-Aug-09 1:34 
GeneralRe: Telerik WinForm Library? Pin
Piratenwichtl200019-Aug-09 1:56
Piratenwichtl200019-Aug-09 1:56 
GeneralRe: Telerik WinForm Library? Pin
Jörgen Sigvardsson19-Aug-09 2:01
Jörgen Sigvardsson19-Aug-09 2:01 
GeneralRe: Telerik WinForm Library? Pin
ManniAT21-Aug-09 7:46
ManniAT21-Aug-09 7:46 
QuestionReporting Services - How to define the WHERE clause dynamically ? Pin
davebarkshire19-Aug-09 0:43
davebarkshire19-Aug-09 0:43 
AnswerRe: Reporting Services - How to define the WHERE clause dynamically ? Pin
Eddy Vluggen19-Aug-09 2:44
professionalEddy Vluggen19-Aug-09 2:44 
QuestionA problem occurs while connecting(using Socket Class) Pin
CoderForEver19-Aug-09 0:34
CoderForEver19-Aug-09 0:34 
Hey buddies this is my first time working on the Socket Class(Because I wanted to do a project on VOIP)...... and I got a sample code from MSDN which shows how to use the Socket Class ........ I wanted to connect to another PC in a network(only 2 computers which is Peer to Peer i.e there is no Server) ....... but there is one Problem so far Here is the code ......

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


namespace Sample
{
    public class GetSocket
    {
        private static Socket ConnectSocket(string server, int port)
        {
            Socket s = null;
            IPHostEntry hostEntry = null;

            // Get host related information.
            hostEntry = Dns.GetHostEntry(server);

            // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
            // an exception that occurs when the host IP Address is not compatible with the address family
            // (typical in the IPv6 case).
            foreach (IPAddress address in hostEntry.AddressList)
            {
                IPEndPoint ipe = new IPEndPoint(address, port);
                Socket tempSocket =
                    new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                tempSocket.Connect(ipe);//Here is the problem


The problem is @ the above last line in z CODE BLOCK i.e<br />
    (<code> tempSocket.Connect(ipe);//</code>) .... i.e the runtime error says<br />
<br />
A socket operation was attempted to an unreachable network 213.55.66.247:80<br />
<br />
 So how could I solve this problem.Help me<br />
</code><br />
<br />
the remaining code is as follows next to the above line<br />
<br />
<pre>if (tempSocket.Connected)
                {
                    s = tempSocket;
                    break;
                }
                else
                {
                    continue;
                }
            }
            return s;
        }

        // This method requests the home page content for the specified server.
        private static string SocketSendReceive(string server, int port)
        {
            string request = "GET / HTTP/1.1\r\nHost: " + server +
                "\r\nConnection: Close\r\n\r\n";
            Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
            Byte[] bytesReceived = new Byte[256];

            // Create a socket connection with the specified server and port.
            Socket s = ConnectSocket(server, port);

            if (s == null)
                return ("Connection failed");

            // Send request to the server.
            s.Send(bytesSent, bytesSent.Length, 0);

            // Receive the server home page content.
            int bytes = 0;
            string page = "Default HTML page on " + server + ":\r\n";

            // The following will block until te page is transmitted.
            do
            {
                bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
                page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
            }
            while (bytes > 0);

            return page;
        }

        public static void Main(string[] args)
        {
            string host;
            int port = 80;

            if (args.Length == 0)
                // If no server name is passed as argument to this program, 
                // use the current host name as the default.
                host = Dns.GetHostName();
            else
                host = args[0];

            string result = SocketSendReceive(host, port);
            Console.WriteLine(result);
            Console.Read();
        }
    }



}

</pre><br />
<br />
Thank you

AnswerRe: A problem occurs while connecting(using Socket Class) Pin
stancrm19-Aug-09 0:55
stancrm19-Aug-09 0:55 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
CoderForEver19-Aug-09 1:06
CoderForEver19-Aug-09 1:06 
AnswerRe: A problem occurs while connecting(using Socket Class) Pin
stancrm19-Aug-09 1:01
stancrm19-Aug-09 1:01 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
CoderForEver19-Aug-09 1:08
CoderForEver19-Aug-09 1:08 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
stancrm19-Aug-09 1:14
stancrm19-Aug-09 1:14 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
CoderForEver19-Aug-09 1:19
CoderForEver19-Aug-09 1:19 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
stancrm19-Aug-09 1:27
stancrm19-Aug-09 1:27 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
CoderForEver19-Aug-09 1:34
CoderForEver19-Aug-09 1:34 
AnswerRe: A problem occurs while connecting(using Socket Class) Pin
stancrm19-Aug-09 1:13
stancrm19-Aug-09 1:13 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
CoderForEver19-Aug-09 1:17
CoderForEver19-Aug-09 1:17 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
stancrm19-Aug-09 1:28
stancrm19-Aug-09 1:28 
AnswerRe: A problem occurs while connecting(using Socket Class) Pin
stancrm19-Aug-09 1:34
stancrm19-Aug-09 1:34 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
CoderForEver19-Aug-09 1:37
CoderForEver19-Aug-09 1:37 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
CoderForEver19-Aug-09 1:40
CoderForEver19-Aug-09 1:40 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
stancrm19-Aug-09 1:44
stancrm19-Aug-09 1:44 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
CoderForEver19-Aug-09 1:50
CoderForEver19-Aug-09 1:50 
GeneralRe: A problem occurs while connecting(using Socket Class) Pin
stancrm19-Aug-09 2:00
stancrm19-Aug-09 2:00 

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.