0

Hi. I have this connection code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace ConnApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234);
            try
            {
                sck.Connect(ip);
                Console.WriteLine("Connected!");
            }
            catch 
            {
                Console.WriteLine("Error!");
            }
            Console.Read();
        }
    }
}

It's telling me "Error!" and I cannot connect to local. But connection works on port 80. Please help me.

Edited by ©lick: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Momerath
0

We need a lot more information than "it's telling me Error". What error, exactly, is it giving. What line, exactly, is the error occuring. You should catch specific exceptions, not the generic "catch" you are using. You don't even bother to get the exception object so you can see more information about the problem!

Edited by Momerath: n/a

0

My error response, what I typed it in code - try catch.

Edited by ©lick: n/a

0

I know, but that tells us nothing except there is an exception. Change your catch statement (and following code) to:

catch (Exception ex) {
    Console.WriteLine(ex.Message);
    if (ex.InnerException != null) {
        Console.WriteLine(ex.InnerException.Message);
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.