Socket declaration just doesn't work

This is a discussion on Socket declaration just doesn't work within the C# Programming forums, part of the General Programming Boards category; Socket Listener = new Socket(0, SocketType.Stream, ProtocolType.Tcp); This is practially straight out of a tutorial example and I can't find ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    Socket declaration just doesn't work

    Socket Listener = new Socket(0, SocketType.Stream, ProtocolType.Tcp);

    This is practially straight out of a tutorial example and I can't find anything wrong with it, but Visual Studio keeps underlining it in red signalling errors (4 or 5 of them too). By having "Socket Listener;" in the class and then having "Listener = new Socket(...);" inside the method where it's used I get rid of the red lines, but then when I declare the second socket in the same way, they just come back.

    I'm not so sure about the parameters (expecially that first 0), but there are also errors showing up about the fact that I'm declaring something as type Socket (I did notice that while listing the name spaces I would be using, System.Net and System.Net.Sockets did not show up as options in the drop down menu like I thought they would've).

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    31
    use this
    Code:
             TcpListener listener;
             
               // Step 1: create TcpListener
    
     //listener = new TcpListener(System.Net.IPAddress.Parse("0"),4000);
                listener = new TcpListener(4000);
    			 
    
                // Step 2: TcpListener waits for connection request
                listener.Start();
    where 4000 is a port, if doesn't work change the port
    Last edited by Dragon227Slayer; 06-19-2004 at 10:08 AM.

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    The The TcpListener class is designed for synchronous data transfer, and my application requires asynchronous communication.

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    And for some reason the problem has now seemed to disappear. I don't remember specifically making any changes to the way I did it, but the source file was fairly small at the time, so I just created a new clean file and coded from the beginning.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Socket program
    By mhetfield in forum C Programming
    Replies: 5
    Last Post: 04-03-2007, 03:46 PM
  2. socket program help
    By mhetfield in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-02-2007, 06:02 AM
  3. Slight problem with socket reading!!!
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 02-15-2006, 08:55 AM
  4. Socket class OOD
    By lord mazdak in forum C++ Programming
    Replies: 6
    Last Post: 12-17-2005, 12:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21