Thread: socket programming cannot connect

  1. #16
    Registered User
    Join Date
    Oct 2013
    Posts
    15
    now my server program is
    Code:
    namespace
     server_window
    
    {
    
        
    publicpartialclassForm1 : Form
    
        {
                 Socket
     m_mainSocket = newSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    
             
    IPEndPoint iplocal = newIPEndPoint(IPAddress.Parse("192.168.1.2"), 1234);
    
            
    Socket client;
    
            
    IPEndPoint newclient;
    
            
    public Form1()
    
            {
    
                InitializeComponent();
    
                BW_Connection.RunWorkerAsync();
    
            }
    
          
    
            
    privatevoid BW_Connection_DoWork(object sender, DoWorkEventArgs e)
    
            {
                               m_mainSocket.Bind(iplocal);
    
                m_mainSocket.Listen(4);
    
               client = m_mainSocket.Accept();
    
                newclient = (
    IPEndPoint)client.RemoteEndPoint;
    
                
    this.Invoke(newMethodInvoker(delegate { TB_text.Text = "Client connected..."; }));
    
            }
               
    privatevoid Form1_FormClosing(object sender, FormClosingEventArgs e)
    
            {
    
                
    //socketForClient.Close();
    
                client.Close();
    
            }
    
    
        }
    
    }
    
    

  2. #17
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    Trying to get two potentially broken programs to run together isn't such a good way to go about this. Why not focus on your client program, see if you can get it to work with "nc -l -p 1234" (or some other similar server program), then worry about your server after your client program works as expected?

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > now my server program is
    ....
    An unreadable mess.

    When you paste code, use the "paste as text" option.

    The board makes a good job of formatting, so long as it isn't already riddled with markup from some other source.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #19
    Registered User
    Join Date
    Oct 2013
    Posts
    15
    Quote Originally Posted by Salem View Post
    > now my server program is
    ....
    An unreadable mess.

    When you paste code, use the "paste as text" option.

    The board makes a good job of formatting, so long as it isn't already riddled with markup from some other source.
    why u had unreadable mess? I really pasted as text when I pasted it. So in my side, everything is fine.

  5. #20
    Registered User
    Join Date
    Oct 2013
    Posts
    15
    Quote Originally Posted by Barney McGrew View Post
    Trying to get two potentially broken programs to run together isn't such a good way to go about this. Why not focus on your client program, see if you can get it to work with "nc -l -p 1234" (or some other similar server program), then worry about your server after your client program works as expected?
    I wrote c server program in Linux and tried my client program. my server is ok but my client still gives me connection refused. Even though I changed new port number, still the same.

  6. #21
    Registered User
    Join Date
    Oct 2013
    Posts
    15
    Quote Originally Posted by why_so_serious View Post
    I wrote c server program in Linux and tried my client program. my server is ok but my client still gives me connection refused. Even though I changed new port number, still the same.
    Now I got an error that "Address family not supported by protocol" when I run client program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Socket wont connect
    By Matty_Alan in forum Networking/Device Communication
    Replies: 2
    Last Post: 04-10-2010, 01:22 AM
  2. Using a single socket for accept() as well as connect()?
    By nkhambal in forum Networking/Device Communication
    Replies: 3
    Last Post: 10-20-2005, 05:43 AM
  3. My socket attempt refuses to connect
    By kzar in forum C Programming
    Replies: 3
    Last Post: 06-01-2005, 04:15 AM
  4. socket connect returning odd
    By WaterNut in forum C++ Programming
    Replies: 5
    Last Post: 05-10-2005, 08:49 PM
  5. need connect SQL through a DLL programming in c++
    By cmcortinas in forum C++ Programming
    Replies: 2
    Last Post: 01-29-2003, 11:57 AM

Tags for this Thread