9 Replies - 4958 Views - Last Post: 20 October 2008 - 03:54 PM Rate Topic: -----

#1 pe_mitev  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 28-December 07

Socket connection through router

Posted 17 October 2008 - 02:21 PM

Hello to everybody! As I have mentioned in other topics of mine, I am developing a simple server-client chat, based on async sockets. This is the code with which I make the connection from the client to the server.

 Public Sub InitializeConnection()
		Dim Addr As IPAddress = Nothing

		Try

			DONT_ACCEPT_REQUESTS = True

			CancelTimer.Start()

			'Assign Addr to the user input (txtIP)
			Addr = Dns.GetHostEntry(ServerIP).AddressList(0)

			If Not Addr Is Nothing Then
				'Create an endpoint
				Dim EP As New IPEndPoint(Addr, CInt(ServerPort))
				'Set up client: instantiate, beginconnect
				ClientSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, _
										  ProtocolType.Tcp)
				ClientSocket.BeginConnect(EP, AddressOf ConnectCallBack, Nothing)
				ClientSocket.SendTimeout = 60
				ClientSocket.ReceiveTimeout = 60
			End If


		Catch Exp As Exception

			Exit Sub
		End Try

	End Sub



ServerIP, ServerPort are nothing but variables which are given value, but how I do this tends to be unnecessary information. The problem I face with this is that I am not able to configure properly routers to transfer to a specified computer for the server application. I check with the Utorrent port checker if the port is opened, after a start the program and it starts listening and it gives OK and also makes the program connect and disconnect again(because of the socket from the Utorrent port checker). With other words, when somebody has a static IP and they do not have a wall(software firewall or a router), there is no problem acting as a server. The problem comes when I want to be server and as you see the socket from the Utorrent port checkers arrives and reports that the port is opened but the client side just cannot get connected to the server side. Is there something in my code that can fail when it came across a router or another kind of a barrier?

Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: Socket connection through router

#2 dbasnett  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 603
  • Joined: 01-October 08

Re: Socket connection through router

Posted 17 October 2008 - 03:26 PM

Maybe this

NAT Traversal
Was This Post Helpful? 0
  • +
  • -

#3 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: Socket connection through router

Posted 18 October 2008 - 10:48 AM

If you server is listening on say port 4000 then you need to forward port 4000 on the server side router to the server.
Was This Post Helpful? 0
  • +
  • -

#4 pe_mitev  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 28-December 07

Re: Socket connection through router

Posted 19 October 2008 - 12:10 AM

Yes, I know that I have to forward the port I want to use and as I said, I have done this. I used the Utorrent port checker and it sends a short-time socket and actually my application goes further and monitors the chat form, but it shows "Disconnected" immediately, as I said that the Utorrent port checker sends a socket and immediately stops it. When I give my IP to friends, the situation is totally different. My server application starts listening, but nobody eventually connects. I use port 5346 for my application if it does mather. I just asked if you see something in my code, that just blocks this thing. Once again, the port is opened, as Utorrent port checker gives OK when I start my server application and "Not opened" when I stop it.
Was This Post Helpful? 0
  • +
  • -

#5 dbasnett  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 603
  • Joined: 01-October 08

Re: Socket connection through router

Posted 19 October 2008 - 04:58 AM

"When I give my IP to friends, the situation is totally different. My server application starts listening, but nobody eventually connects."

are they connecting to you over the internet?
Was This Post Helpful? 0
  • +
  • -

#6 pe_mitev  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 28-December 07

Re: Socket connection through router

Posted 20 October 2008 - 01:39 AM

The interesting fact is that they do not manage to connect. On the other hand, when I use this http://www.utorrent....t.php?port=6881 it sends a test socket and says OK and my program switches to Chat window as somebody had connected, but as this is a test socket from the Utorrent port checker, my program becomes "Disconnected".

To summarize, I am surprised how it is possible this port checker to succeed in connecting to my application, but my friends not?
Was This Post Helpful? 0
  • +
  • -

#7 pe_mitev  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 28-December 07

Re: Socket connection through router

Posted 20 October 2008 - 01:39 AM

The interesting fact is that they do not manage to connect. On the other hand, when I use this http://www.utorrent....t.php?port=6881 it sends a test socket and says OK and my program switches to Chat window as somebody had connected, but as this is a test socket from the Utorrent port checker, my program becomes "Disconnected".

To summarize, I am surprised how it is possible this port checker to succeed in connecting to my application, but my friends not?
Was This Post Helpful? 0
  • +
  • -

#8 dbasnett  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 603
  • Joined: 01-October 08

Re: Socket connection through router

Posted 20 October 2008 - 03:48 AM

last time, are your friends and utorrent being used across the internet?

friends - yes/no
utorrent - yes/no
Was This Post Helpful? 0
  • +
  • -

#9 pe_mitev  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 28-December 07

Re: Socket connection through router

Posted 20 October 2008 - 01:31 PM

Yes, of course they must connect via the internet.

My friends - could not manage to connect
utorrent port checker - connects.


That is why I am asking if my code has some problems about the NAT.
Was This Post Helpful? 0
  • +
  • -

#10 dbasnett  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 603
  • Joined: 01-October 08

Re: Socket connection through router

Posted 20 October 2008 - 03:54 PM

utorrent over the internet or locally?

did you read the link i posted? i think you have a Port Translation problem trying to go across the internet. try port 80 and see if that works?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1