473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

What is the difference between getPort() and getLocalPort() of the Socket class?

Some may say that
Expand|Select|Wrap|Line Numbers
  1. getLocalPort()
returns the "Local Port" and
Expand|Select|Wrap|Line Numbers
  1. getPort()
returns the "remote Port" but what i find interesting yet ironically confusing is that how can be there two ports associated with the same Socket?
Mar 26 '13 #1
4 9931
Rabbit
12,516 Expert Mod 8TB
Because you connect to a port on the remote computer from a port on your computer. You connect to their port 80 from your port 8009 for example. Pretty much every web server uses port 80. If you have multiple websites loaded, they can't very well all use your port 80 as well. In fact, none of them use your port 80. It's reserved for if you want to run a web server yourself.
Mar 26 '13 #2
But isn't a Socket like an end point between two communicating entities.for instance,

server--------------------|socket|-----------------client

So the question arises that how can we have two end-points in a connection.( I seriously can't grab this one!!!)
Mar 27 '13 #3
r035198x
13,262 8TB
Ports exist on computers not inside some socket object. A computer (whether client or server) always needs to be able to open a port in order for it to communicate with another computer.
The client computer and the server computer do not both have to open the same port number to be able to communicate. The client can use port X to communicate out but be connecting to port Y of the computer it is communicating with (if that computer is using port Y to communicate out).
Mar 27 '13 #4
Rabbit
12,516 Expert Mod 8TB
Your chart is wrong. It's more like this
Expand|Select|Wrap|Line Numbers
  1. ---------------------------socket-----------------------------
  2. | local socket address    protocol     remote socket address |
  3. | 10.1.87.251:8008          TCP        10.2.85.12:80         |
  4. --------------------------------------------------------------
  5.  
  6. local socket----------------remote socket
  7.  
Yes, a socket is an end-point for data transmission. But each computer creates their own socket.
Mar 27 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dan Rice | last post by:
Hello, Im trying to get the following working but it doesn't seem to receive anything. I have got the UdpClient class to receive data but unreliably and was told to use the Socket class...
7
by: groleo | last post by:
Hi. I've searched a lot on google, but no one seems to develop a socket class for c++? I've found a lot of classes that works only on Windows. The thing is that I need a BSD socket library. I...
3
by: HABJAN ®iga | last post by:
Is there a way to be notifyed (callback, event,...) when the connection of socket was closed... The WinSock activex in vb6 had event ondisconnect... I get exception when i try to send some data,...
3
by: notregister | last post by:
Hi, how do i use socket class to send data to a device which i have that IP address and Port number e.g 169.254.192.155 RemotePort: 9100 or any IP address that i want? Pls advise Thanks
1
by: brettsbignose | last post by:
Please inform me if microsoft has a better group to post this genre of question on, but since I am working in vb.net, this was my best choice. I am writing a program that can send UDP packets. ...
1
by: ssherm01 | last post by:
I'm using MS VS C++ .NET. I've written a multicast test utility that can send IGMP packets for a user specified group address. As well, it can send and receive UDP packets for a specified...
3
by: sniper1000 | last post by:
what are basic difference in C socket and network programming between linux and windows? and what is the difference between liberarries? Tanks
5
by: Bruce | last post by:
Hello I am building a C# app that creates anywhere from 10 to 100 connections to a specified server and sends 1000s of TCP requests and processes the responses. (it is a stress tool) I planned...
2
by: Piotrekk | last post by:
Hi I have a question related to Socket class. What are the advantages / disadvantages of using Socket class comparing to TcpClient and HttpWebRequest Regards Piotr Kołodziej
2
by: kodart | last post by:
Introduction Performance is the main concern to most server application developers. That’s why many of them anticipate using .NET platform to develop high performance server application regardless...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.