Thread: tcp/ip not connecting to my computer

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    tcp/ip not connecting to my computer

    When I try to connect to my computer using tcp/ip it says my computer activly rejected the connetion. Why does that hapen?

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    16
    Check your firewalls - McAfee, Norton, Windows Firewall too.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Hmm ok I did, I even turned them all off for a tiby bit to check, still didn't work. I can play games online and do everythin else with tcp/ip but not my own program.

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I can't connect to any perosns comupter, only web sites and other stuff like that. WHy can't I?

  5. #5
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Nobody can help you if you don't post code.
    To code is divine

  6. #6
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    sorry I thought I did...

    first I int some variables

    Code:
            IPAddress IP;
            TcpClient tcp;
            NetworkStream net;
            StreamReader read;
            StreamWriter write;
            bool connected = false;
    then I connect

    Code:
                IP = IPAddress.Parse(textBox_ip.Text);
    
                tcp = new TcpClient();
                tcp.Connect(IP, int.Parse(textBox_Port.Text));
                if (tcp.Connected)
                {
                    textBox_Conver.AppendText("Connected\r\n");
                    connected = true;
                }
                net =  tcp.GetStream();
                read = new StreamReader(net);
                write = new StreamWriter(net);
    if the connection works, which I get the error while connecting I can ping with this code

    Code:
                if (connected == true)
                {
                    textBox_Conver.AppendText("Pinging...\r\n");
                    Ping ping = new Ping();
                    PingReply reply = ping.Send(IP);
                    long time = reply.RoundTripTime;
                    textBox_Conver.AppendText("Ping: " + time.ToString() + "\r\n");
                    textBox_Conver.AppendText("Ready \r\n");
                }
    That should be enough, and it does work for websites, but not for ragular computers.

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    36
    Are you trying to talk to computers on your home network which are connected with a router? It probably has an option whether to let them talk to each other or just to talk to the primary (internet) connection. And your testing probably went to local for the stuff that failed and the internet for http stuff. If you are using a hub its hard wired, but they probably can talk to each other, if not you can't fix it.

  8. #8
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    hrmm so I am on dial up, but still I can not talk to my own computer on my own computer? I can do this with other programs and Game Maker.

  9. #9
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I assume the problem is because nothing is listening for your connection. When you start up a game that employs some networking, it will be listening for connections, and connect to a server that is also listening for connections. Do you have any program running on the target computer that is awaiting your connection?

  10. #10
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    hrmmm that brings a whole new concept. Ok I see what I need to do, my program is sorta blunt. And I guess web sites are always listening for connections I am guessing. Ok I see what I am doing wrong.

  11. #11
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Ping's got nothing to do with programs listening for connections. There is no point creating a Tcp connection if you're just using ping. "Ping" is not a software service and doesn't listen on a particular port (as the TCP connection does). It uses ICMP packets and replies are handled at the OS level.

    You've created the streams to read and write from the socket, but you're not actually writing any data.

    Heres a test - try connecting to www.google.com on port 80 (HTTP standard port). Use the stream writer to write "GET / HTTP/1.0\r\n\r\n" (a standard "show me the page baby!" HTTP request). Then use the reader to get the response.

    As Sean pointed out, the problem is probably that the computers aren't listening on the ports you try and connect to - use TcpServer (or TcpHost?) to create a server to accept incoming connections in one program, and TcpClient in another to connect to it.

  12. #12
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    hmm so using the stream I really can send data just like a packet? And I read up on ping last night and figured out it has notin to do with connections.

    And I will try that test after I get my Counter Strike Source tower's physics correct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. connecting to a computer inside a LAN
    By hardi in forum Networking/Device Communication
    Replies: 6
    Last Post: 10-25-2006, 04:43 PM
  2. Connecting to my computer from elsewhere
    By maxorator in forum Windows Programming
    Replies: 19
    Last Post: 05-04-2006, 10:08 PM
  3. Replies: 34
    Last Post: 02-26-2006, 01:16 PM
  4. Tabbed Windows with MDI?
    By willc0de4food in forum Windows Programming
    Replies: 25
    Last Post: 05-19-2005, 10:58 PM
  5. connecting to another computer
    By yinhowe in forum C Programming
    Replies: 4
    Last Post: 11-19-2002, 03:14 AM