not-local server with sockets

This is a discussion on not-local server with sockets within the C# Programming forums, part of the General Programming Boards category; Hi guys, I wrote an echo server with sockets. Here is the server socket creating code: Code: IPEndPoint iep = ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    6

    not-local server with sockets

    Hi guys,

    I wrote an echo server with sockets.

    Here is the server socket creating code:
    Code:
                IPEndPoint iep = new IPEndPoint(IPAddress.IPv6Any, 1234);
    
                Socket server = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
    
                server.Bind(iep);
    The client program has to provide the ip of the server, so when the server and the client are running from my computer I use the Link-local IPv6 Address as shown in ipconfig (aaxx::xxxx:xxax:axax:xaxa%xx)

    I must use Ipv6 because I run win7.

    What ip should the client provide in case that the server runs from my computer and the client runs from another computer?

    Thanks.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    You have to submit the IP-address, that your server can be reached by. If all your computers are in your LAN, open a cmd-window on your server, type "ipconfig" und use that address to connect. If you want to connect over WAN (internet), look up your IP in your router config or find a site that tells you what IP you have.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    6
    Actually, I'm a little confused with the Ipv6 add Ipv4.
    The server now works only with IPv6 addresses and I don't know where I can find my Ipv6 address, whatismyip.com provides only Ipv4.
    What should I do to make my server work with Ipv4 addresses? What type of IPAddress should I pass to the IPEndPoint?

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    2,137
    Quote Originally Posted by 0xIDE View Post
    I must use Ipv6 because I run win7.
    not sure where you got this idea, but it's absolutely incorrect. windows 7 is not an IPv6-only system. there isn't any mainstream operating system out there yet that is. you can still use IPv4 with every version of windows after 95, and (AFAIK) every version of linux ever made.

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    6
    ok, I've changed the server a bit. Now it's code is:
    Code:
                IPEndPoint iep = new IPEndPoint(IPAddress.Any, 1234);
    
                Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    When I type 10.0.0.2 in the client's windows I get all works fine.
    When I type my WAN IP as shown in wahismyip.com I get this:

    Code:
    Unhandled Exception: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it *IP*:1234
    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
       at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
          at EchoClient.Program.Main(String[] args) in \EchoClient\Program.cs:line 20
    what is the problem now?

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    2,137
    Quote Originally Posted by 0xIDE View Post
    Code:
    Unhandled Exception: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it *IP*:1234
    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
       at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
          at EchoClient.Program.Main(String[] args) in \EchoClient\Program.cs:line 20
    what is the problem now?
    this is most likely a firewall blocking the incoming connection.

  7. #7
    Registered User
    Join Date
    Jul 2011
    Posts
    6
    I disabled the firewall but it didn't help much.
    I think I should forward ports...
    I've done this:
    http://img28.imageshack.us/img28/2124/34508095.gif
    But stil the same exception...

  8. #8
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    in win7 you need to allow incoming connections - other wise they are blocked

    in your win7 computer - find a firewall settings there should be allow list somewhere.

    you have 2 options available - or list your port as able to accept incoming connections from the corresponding network.

    or list your application as one which is allowed to accept incoming connections.

    Note that win7 blocks incoming connections (without the above procedure) even if the windows firewall is shown as not running (really annoying behavior)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  9. #9
    Registered User
    Join Date
    Jul 2011
    Posts
    6
    How do exactly i do that?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using UNIX-Sockets for local interprocess communication
    By eeboot in forum Linux Programming
    Replies: 3
    Last Post: 11-06-2010, 08:31 AM
  2. TCP/IP lib for C++ [Sockets, Client/Server]
    By C_ntua in forum Networking/Device Communication
    Replies: 5
    Last Post: 06-15-2010, 11:42 PM
  3. can i force connecting to local web server via internet network ?
    By umen242 in forum Networking/Device Communication
    Replies: 5
    Last Post: 04-29-2008, 09:21 AM
  4. Advice Request for a local web server
    By Mario F. in forum Tech Board
    Replies: 9
    Last Post: 02-24-2008, 03:13 PM
  5. Intercepting Data Bound for Local Application from Remote Server
    By maththeorylvr in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-29-2005, 12:57 AM

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