473,320 Members | 2,097 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,320 software developers and data experts.

IP and Port

Hi,
I am writing a program using the TcpListener class. How can I get a
random unused port and the ip of my local host machine.
Thanks in Advance
Nov 16 '05 #1
8 3170
to get a random unused port, try to use the Random Class to generate a number
up to 2500 or 3000
Tom.
"Xarky" wrote:
Hi,
I am writing a program using the TcpListener class. How can I get a
random unused port and the ip of my local host machine.
Thanks in Advance

Nov 16 '05 #2
to get a random unused port, try to use the Random Class to generate a number
up to 2500 or 3000
Tom.
"Xarky" wrote:
Hi,
I am writing a program using the TcpListener class. How can I get a
random unused port and the ip of my local host machine.
Thanks in Advance

Nov 16 '05 #3
Hi,

Just pass a 0 as the port number in the constructor.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Xarky" <be*********@yahoo.com> wrote in message
news:bc************************@posting.google.com ...
Hi,
I am writing a program using the TcpListener class. How can I get a
random unused port and the ip of my local host machine.
Thanks in Advance

Nov 16 '05 #4
Hi,

Just pass a 0 as the port number in the constructor.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Xarky" <be*********@yahoo.com> wrote in message
news:bc************************@posting.google.com ...
Hi,
I am writing a program using the TcpListener class. How can I get a
random unused port and the ip of my local host machine.
Thanks in Advance

Nov 16 '05 #5
Hi,
First of all thanks for all the help already given. Please can
someone tell what method should I use to get the ip of my machine.

Also, having an ip stored in a string, how can I convert it to the
object IPAddress.

Thanks in Advance
Nov 16 '05 #6
Hi,
Sorry for asking too many questions. I am doing the as follows.
Now how can I get the port number that was assigned.

TcpListener tcp = new TcpListener(0); // need to get random
port
Thanks for your patience

Hi,

Just pass a 0 as the port number in the constructor.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Xarky" <be*********@yahoo.com> wrote in message
news:bc************************@posting.google.com ...
Hi,
I am writing a program using the TcpListener class. How can I get a
random unused port and the ip of my local host machine.
Thanks in Advance

Nov 16 '05 #7
Hi,

((IPEndPoint)TcpListener.LocalEndPoint).Port

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Xarky" <be*********@yahoo.com> wrote in message
news:bc*************************@posting.google.co m...
Hi,
Sorry for asking too many questions. I am doing the as follows.
Now how can I get the port number that was assigned.

TcpListener tcp = new TcpListener(0); // need to get random
port
Thanks for your patience

Hi,

Just pass a 0 as the port number in the constructor.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Xarky" <be*********@yahoo.com> wrote in message
news:bc************************@posting.google.com ...
Hi,
I am writing a program using the TcpListener class. How can I get a
random unused port and the ip of my local host machine.
Thanks in Advance

Nov 16 '05 #8

Xarky wrote:

[...snip...]
Please can
someone tell what method should I use to get the ip of my machine.


I got it somewhat like

IPAddress[] addressArray = Dns.Resolve(Dns.GetHostName()).AddressList;
IPAddress myLocalAddress = addressArray[0];

which requires access to a DNS-Server, I think.
Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
0
by: per.bergstrom | last post by:
To whom it may concern, The serial port server 'cnhd38' has been terminated (on who's initiative, I don't know). It affects the users of the (at least) following nodes: cnhd36, cnhd44, cnhd45,...
2
by: willie | last post by:
Hi, I'm writing a program which requires the use of three serial ports and one parallel port. My application has a scanning devices on each port, which I can access fine with pyserial. ...
5
by: Jason | last post by:
After a server accepts a client connection on a certain port, a new socket is created on the server on a system managed dynamic port to handle the connection. Please confirm this. If so, how...
6
by: kai | last post by:
Hi, I was tring to run an example (HelloWorld.aspx) from MSPrss book, I get this message: "ASP.NET Development Server faild to start listening port 1034. Error message: An attempt was made...
7
by: Sharon | last post by:
Hi all, I've implemented a TCP server using the Socket async methods. When connecting to the server from 3 instances of hyper terminal, i've noticed that each of the newly created server sockets,...
4
by: H J van Rooyen | last post by:
Hi All, I am writing a polling controller for an RS-485 line that has several addressable devices connected. It is a small access control system. All is well- the code runs for anything from...
25
by: bmearns | last post by:
Is it possible to specify which port to use as the outbound port on a connection? I have the IP address and port number for the computer I'm trying to connect to (not listening for), but it's...
13
by: Rob | last post by:
Hi all, I am fairly new to python, but not programming and embedded. I am having an issue which I believe is related to the hardware, triggered by the software read I am doing in pySerial. I...
5
by: Maciej Sondej | last post by:
Hi, I have problem. I want to react on event which come from IO.Port(RS232). I have a class that works on console application class Program { static void Main(string args) {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.