Closed Thread
Results 1 to 3 of 3

Thread: TCP Socket Connection Problem

  1. #1
    Daemon is offline Newbie
    Join Date
    Mar 2010
    Posts
    3
    Rep Power
    0

    Question TCP Socket Connection Problem

    Hey Dudes,
    my first post so pls be kind .
    Started few days ago with C# and .NET using Visual Studio C# Express 2008.
    In school we are coding in Java and started socket-programming but i wanted to do something new and fresh so decided to take a look at C#.
    And having a try on a simple chat using TCP sockets.
    Now about my Problem:
    I don't know why my program doesn't connect to itself at another PC in my House's LAN, could be about my PCs (Firewall etc.) but i want to elimate the possibility of a programming mistake.
    However It DOES connect and i can chat when i start 2 instances on the same PC and parameters are "127.0.0.1" and e.g. "5221".
    Feel free to ask and thanks in advance.
    Here's the relevant Code:
    Code:
    static Socket Socket;

    internal static String connect(string sIPstring sPort)
            {
                try
                {
                    
    IPAddress IP IPAddress.Parse(sIP);
                    
    Int32 Port Convert.ToInt32(sPort);
                    
    IPEndPoint Endpoint = new IPEndPoint(IPPort);
                    
    Socket = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
                    
    Socket.Connect(Endpoint);
                }
                catch (
    Exception e)
                {
                    throw 
    e;
                }
                return 
    "Status: Connected!";
            }

    internal static String listen(string sIPstring sPort)
            {
                try
                {
                    
    IPAddress IP IPAddress.Parse(sIP);
                    
    Int32 Port Convert.ToInt32(sPort);
                    
    IPEndPoint Endpoint = new IPEndPoint(IPPort);
                    
    Socket ListeningSocket = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
                    
    ListeningSocket.Bind(Endpoint);
                    
    ListeningSocket.Listen(1);
                    
    Socket ListeningSocket.Accept();
                    
    ListeningSocket.Close();
                }
                catch (
    Exception e)
                {
                    throw 
    e;
                }
                return 
    "Status: Connected!";
            } 
    Last edited by Daemon; 03-13-2010 at 05:02 PM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    abdul.gafur's Avatar
    abdul.gafur is offline Learning Programmer
    Join Date
    Mar 2010
    Location
    Salo, Riau, Indonesia
    Posts
    42
    Rep Power
    0

    Re: TCP Socket Connection Problem

    I've never tried to create server client application, using C# and .net. Only using C, console application.

    Hope the following links help
    Page 2 - Socket Programming in C# - Part I
    Socket Programming in C#

  4. #3
    Daemon is offline Newbie
    Join Date
    Mar 2010
    Posts
    3
    Rep Power
    0

    Re: TCP Socket Connection Problem

    Thx for reply, but i'm really stuck on this.
    i read several tutorials and the msdn-library and i really think it should work and it does work on the same machine. I just need someone who's in this socket programming with c#.
    Last edited by Daemon; 03-14-2010 at 08:34 AM.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. MS Access connection problem with VB.NET
    By bradploz in forum Visual Basic Programming
    Replies: 0
    Last Post: 07-29-2011, 03:50 AM
  2. Replies: 2
    Last Post: 03-19-2011, 04:13 AM
  3. Replies: 1
    Last Post: 02-10-2011, 02:09 AM
  4. problem : application with socket
    By katerina85 in forum C and C++
    Replies: 1
    Last Post: 11-16-2009, 08:16 AM
  5. mysql server - connection problem
    By cinek in forum Visual Basic Programming
    Replies: 5
    Last Post: 01-30-2009, 08:23 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts