Click here to Skip to main content
Sign Up to vote bad
good
See more: C#
system.net.sockets.socketexception(0x80004005)
no connection could be made because the target machine actively refused it 192.168.1.7:1024
i need to know what is the problem and how can solve
i try to ping that 192.168.1.7 (this access point take ip through tcp/ ip module )and that replay no problem
 

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net.Sockets;
using System.Threading;
using System.Runtime.Remoting.Channels;
 
namespace simple_tcpclient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
            Connect("192.168.1.7", "1");
          
        
        }
          public static void Connect(String server, String message) 
{
  try 
  {
    // Create a TcpClient. 
    // Note, for this client to work you need to have a TcpServer  
    // connected to the same address as specified by the server, port 
    // combination.
    int port = 1024;
    TcpClient client = new TcpClient(server, port);
 
    // Translate the passed message into ASCII and store it as a Byte array.
    Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);         
 
    // Get a client stream for reading and writing. 
   //  Stream stream = client.GetStream();

    NetworkStream stream = client.GetStream();
 
    // Send the message to the connected TcpServer. 
    stream.Write(data, 0, data.Length);
 
    System.Windows.Forms.MessageBox.Show("Sent: {0}" + message); ;         
 
    // Receive the TcpServer.response. 

    // Buffer to store the response bytes.
    data = new Byte[256];
 
    // String to store the response ASCII representation.
    String responseData = String.Empty;
 
    // Read the first batch of the TcpServer response bytes.
    Int32 bytes = stream.Read(data, 0, data.Length);
    responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
 
    System.Windows.Forms.MessageBox.Show("recieved: {0}"+ responseData); 
      
    // Close everything.
   // stream.Close();         
   // client.Close();         
  } 
  catch (ArgumentNullException e) 
  {
      System.Windows.Forms.MessageBox.Show("ArgumentNullException: {0}"+ e);
  } 
  catch (SocketException e) 
  {
      System.Windows.Forms.MessageBox.Show("SocketException: {0}"+ e);
  }
 
  System.Windows.Forms.MessageBox.Show("\n Press Enter to continue...");
  Console.Read();
 
               
}
 

 

 

 

 

 

 

 

        }
    }
 
Posted 6 Mar '13 - 20:40
ameleed281


1 solution

Your code connects to port 1024 of the host (192.168.1.7)
 
  int port = 1024;
  TcpClient client = new TcpClient(server, port);
 

According to exception - no service listens on this port at this host.
 
You can check if this port is open using telnet program
 
telnet 192.168.1.7 1024
 
To resolve - ensure, that on host some application listens to this port.
  Permalink  
Comments
ameleed - 7 Mar '13 - 4:18
thanks Vyacheslav Voronenko you mean insert that (telnet 192.168.1.7 1024)to my code . i already insert it to the code but it isn't identified how can i identify it ? i am searching in this is exception and i find that may because of the firewall of my host (192.168.1.7) block the call. so do you think the problem is in hardware or in my application
Vyacheslav Voronenko - 7 Mar '13 - 6:37
What is the result of telnet 192.168.1.7 1024 command? If Connecting To 192.168.1.7...Could not open connection to the host, on port 1024: Connect failed Than problem is not in your application.
ameleed - 9 Mar '13 - 7:17
yes i use this is http://www.ultradevelopers.net/Blog/12 to make telnet and service is not running what is the problem ?
Vyacheslav Voronenko - 10 Mar '13 - 3:54
You do not need any C# here - it just allows you to simply check if smth listens to remote port or not. From the command prompt.
ameleed - 10 Mar '13 - 8:26
yes i made that from command prompt and the result of telnet 192.168.1.7 1024 is could not open connection to the host on port connected failed what can i do in this problem may be firewall in my pc or firewall in the wireless access point or may be need to open port 1024 can you help me to find the solution
Vyacheslav Voronenko - 10 Mar '13 - 10:25
You have to solve this problem at your box 192.168.1.7 - run something that you were expecting to contact at this port. (What is it?)
ameleed - 10 Mar '13 - 12:35
the box 192.168.1.7 is this is device http://www.hexin-technology.com/RS-232_To_Ethernet_TCP_IP_Serial_Device_Server-Product-252.html
Vyacheslav Voronenko - 10 Mar '13 - 13:06
Looking on docs - are you sure device is correctly configured (in terms of address) and is located in the same network range as your computer? Is standalone test with elTest tool passed?
ameleed - 13 Mar '13 - 3:26
thanks i will test the e1test
ameleed - 15 Mar '13 - 6:55
wow yes Vyacheslav Voronenko as you said now i can connect and my application is run and problem and no error thanks for you i am very pleased to help me
Vyacheslav Voronenko - 15 Mar '13 - 6:56
No problem at all :) Cheers!
ameleed - 15 Mar '13 - 7:21
yes :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 449
1 Mahesh Bailwal 373
2 Maciej Los 255
3 Rohan Leuva 175
4 CPallini 175
0 Sergey Alexandrovich Kryukov 9,402
1 OriginalGriff 7,204
2 CPallini 3,933
3 Rohan Leuva 3,211
4 Maciej Los 2,743


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 7 Mar 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid