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

IP address

I built two programs, one is a server and the other one is the client, I want
those two programs to work on the same machine and to exchange information
through the internet.
IPAddress ipAddress = IPAddress.Parse(my IP);
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
I use this same code in the both programs except for the port number which
is diferent.
But there seems to be no connection.
Maybe I use the wrong Ip number, coz I don't know how to get my ip, in my
interent connections status I see two ips: Client and Server (I use ADSL)
What can be the problem?

Nov 16 '05 #1
10 4603
Hi Michael,
I built two programs, one is a server and the other one is the client, I want
those two programs to work on the same machine and to exchange information
through the internet.
IPAddress ipAddress = IPAddress.Parse(my IP);
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
I use this same code in the both programs except for the port number which
is diferent.
But there seems to be no connection.
Maybe I use the wrong Ip number, coz I don't know how to get my ip, in my
interent connections status I see two ips: Client and Server (I use ADSL)


Use "127.0.0.1" as an IP addresss for both programs. That's the
so called loopback (local) address.

bye
Rob
Nov 16 '05 #2
Michael,

Is it possible that you are behind a firewall, and that the IP address
that you are obtaining is an internal IP, not an external one?

Also, how are you getting the IP address?

I also have to ask why you are choosing to go out to the internet to
make a request to yourself on the same machine. It seems horribly
inefficient, and certainly, you could abstract some of the request/response
logic in favor of a more efficient transport (so that you can gain the
benefits of a speedier transport on the same machine, but still use the
internet if the client and server were on separate machines).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...
I built two programs, one is a server and the other one is the client, I
want
those two programs to work on the same machine and to exchange information
through the internet.
IPAddress ipAddress = IPAddress.Parse(my IP);
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
I use this same code in the both programs except for the port number which
is diferent.
But there seems to be no connection.
Maybe I use the wrong Ip number, coz I don't know how to get my ip, in my
interent connections status I see two ips: Client and Server (I use ADSL)
What can be the problem?


Nov 16 '05 #3
Well now when I tried to use 127.0.0.1 it says :
No connection could be made becase the target machine actively refused it
at System.net.sockets.socket.endconnect<IAsyncResult asyncResult>
at AsynchronousClient.ConnectCallBack<IAsyncResult ar>.....
I also disabled my firewall.
I use those two programs on the same machine just becuase I have no other
computer with another internet connection nearby, eventually my goal is to
put those programs on separated computers.
And what do you mean by internal ip and external ip?
thanks
Nov 16 '05 #4
hi Robert I used the 127.0.0.1 ip number but when I run the program it says:
SocketException: .....No connection could be made because the target machine
actively refused it
at System.Net.Sockets.Socket.Connect(EndPoint remooteEP)
What can be the problem?
(I disabled my Firewall)

"Robert Jordan" wrote:
Hi Michael,
I built two programs, one is a server and the other one is the client, I want
those two programs to work on the same machine and to exchange information
through the internet.
IPAddress ipAddress = IPAddress.Parse(my IP);
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
I use this same code in the both programs except for the port number which
is diferent.
But there seems to be no connection.
Maybe I use the wrong Ip number, coz I don't know how to get my ip, in my
interent connections status I see two ips: Client and Server (I use ADSL)


Use "127.0.0.1" as an IP addresss for both programs. That's the
so called loopback (local) address.

bye
Rob

Nov 16 '05 #5
I would start off by do a quick loopback test.

1) Click on Start->Run
2) Type in "cmd" and hit enter
3) Type "ping 127.0.0.1"

If the response is something like "Request timed out", then a) your machine
is blocking ICMP packets or b) there is a problem with the 127.0.0.1
address. I doubt either is the case if your firewall is disabled. Either
way, if you post those results here, I'm sure we can help you further.

ShaneB

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
hi Robert I used the 127.0.0.1 ip number but when I run the program it
says:
SocketException: .....No connection could be made because the target
machine
actively refused it
at System.Net.Sockets.Socket.Connect(EndPoint remooteEP)
What can be the problem?
(I disabled my Firewall)

"Robert Jordan" wrote:
Hi Michael,
> I built two programs, one is a server and the other one is the client,
> I want
> those two programs to work on the same machine and to exchange
> information
> through the internet.
> IPAddress ipAddress = IPAddress.Parse(my IP);
> IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
> I use this same code in the both programs except for the port number
> which
> is diferent.
> But there seems to be no connection.
> Maybe I use the wrong Ip number, coz I don't know how to get my ip, in
> my
> interent connections status I see two ips: Client and Server (I use
> ADSL)


Use "127.0.0.1" as an IP addresss for both programs. That's the
so called loopback (local) address.

bye
Rob

Nov 16 '05 #6
I typed ping 127.0.0.1
and I got a responce:
reply from 127.0.0.1: bytes=32 time<ms ttl=128
"ShaneB" wrote:
I would start off by do a quick loopback test.

1) Click on Start->Run
2) Type in "cmd" and hit enter
3) Type "ping 127.0.0.1"

If the response is something like "Request timed out", then a) your machine
is blocking ICMP packets or b) there is a problem with the 127.0.0.1
address. I doubt either is the case if your firewall is disabled. Either
way, if you post those results here, I'm sure we can help you further.

ShaneB

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
hi Robert I used the 127.0.0.1 ip number but when I run the program it
says:
SocketException: .....No connection could be made because the target
machine
actively refused it
at System.Net.Sockets.Socket.Connect(EndPoint remooteEP)
What can be the problem?
(I disabled my Firewall)

"Robert Jordan" wrote:
Hi Michael,

> I built two programs, one is a server and the other one is the client,
> I want
> those two programs to work on the same machine and to exchange
> information
> through the internet.
> IPAddress ipAddress = IPAddress.Parse(my IP);
> IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
> I use this same code in the both programs except for the port number
> which
> is diferent.
> But there seems to be no connection.
> Maybe I use the wrong Ip number, coz I don't know how to get my ip, in
> my
> interent connections status I see two ips: Client and Server (I use
> ADSL)

Use "127.0.0.1" as an IP addresss for both programs. That's the
so called loopback (local) address.

bye
Rob


Nov 16 '05 #7
Ok...then it is almost certainly a problem in the code.

Can you post your client Connect code and your server Listen code? That
will help.

ShaneB

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
I typed ping 127.0.0.1
and I got a responce:
reply from 127.0.0.1: bytes=32 time<ms ttl=128
"ShaneB" wrote:
I would start off by do a quick loopback test.

1) Click on Start->Run
2) Type in "cmd" and hit enter
3) Type "ping 127.0.0.1"

If the response is something like "Request timed out", then a) your
machine
is blocking ICMP packets or b) there is a problem with the 127.0.0.1
address. I doubt either is the case if your firewall is disabled.
Either
way, if you post those results here, I'm sure we can help you further.

ShaneB

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
> hi Robert I used the 127.0.0.1 ip number but when I run the program it
> says:
> SocketException: .....No connection could be made because the target
> machine
> actively refused it
> at System.Net.Sockets.Socket.Connect(EndPoint remooteEP)
> What can be the problem?
> (I disabled my Firewall)
>
> "Robert Jordan" wrote:
>
>> Hi Michael,
>>
>> > I built two programs, one is a server and the other one is the
>> > client,
>> > I want
>> > those two programs to work on the same machine and to exchange
>> > information
>> > through the internet.
>> > IPAddress ipAddress = IPAddress.Parse(my IP);
>> > IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
>> > I use this same code in the both programs except for the port number
>> > which
>> > is diferent.
>> > But there seems to be no connection.
>> > Maybe I use the wrong Ip number, coz I don't know how to get my ip,
>> > in
>> > my
>> > interent connections status I see two ips: Client and Server (I use
>> > ADSL)
>>
>> Use "127.0.0.1" as an IP addresss for both programs. That's the
>> so called loopback (local) address.
>>
>> bye
>> Rob
>>


Nov 16 '05 #8
The sender:

using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Text;
namespace SynSender
{
class Sender
{
[STAThread]
static void Main(string[] args)
{try{
Socket sender= new
Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);

IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 1160);

byte [] buffer= Encoding.ASCII.GetBytes("Hello<EOF>");
try
{
Console.WriteLine("Connecting");
sender.Connect(localEndPoint);
Console.WriteLine("Connected and sending");
sender.Send(buffer);
Console.WriteLine("Sent");
sender.Shutdown(SocketShutdown.Both);
}

catch (ArgumentNullException ane)
{
Console.WriteLine("ArgumentNullException : {0}",ane.ToString());
Console.Read();
}
catch (SocketException se)
{
Console.WriteLine("SocketException : {0}",se.ToString());
Console.Read();
}
catch (Exception e)
{
Console.WriteLine("Unexpected exception : {0}", e.ToString());
Console.Read();
}

}
catch (Exception e)
{
Console.WriteLine( e.ToString());
Console.Read();
}

}
}
}
The reciever:

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

namespace Reciever
{
class Recieve
{

[STAThread]
static void Main(string[] args)
{try{
Socket reciever= new
Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 1100);
Console.WriteLine("Connecting");
reciever.Bind(localEndPoint);
reciever.Listen(100);
Console.WriteLine("Waiting");
Socket handler= reciever.Accept();
Console.WriteLine("Handler accepted");
byte [] bytes=new byte[1024];
handler.Receive(bytes);
Console.WriteLine("Recieved"+bytes.ToString());

handler.Shutdown(SocketShutdown.Both);
handler.Close();
Console.WriteLine("\nPress ENTER to continue...");
Console.Read();

}

catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.Read();
}

}
}
}

But the reciever seems to work fine, it reachs the line when it shows
"waiting" on the screen, the sender is the one that causes the trouble
Thanks for your help

Nov 16 '05 #9
Your ports don't match. Fix that and it will work fine :)

ShaneB

Sender
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 1160);
Receiver IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 1100);

Nov 16 '05 #10
It works:)
Thank you very much!!!!
"ShaneB" wrote:
Your ports don't match. Fix that and it will work fine :)

ShaneB

Sender
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 1160);


Receiver
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 1100);


Nov 16 '05 #11

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...
8
by: YAN | last post by:
Hi, I want to get the mac address from a machine, which i have the IP address of that machine, how can i do that? I know how to get the mac address of the local machine from the following code: ...
7
by: Privacy Advocate | last post by:
//crossposted to: comp.lang.javascript, alt.comp.lang.javascript in an effort to get factual answers from JavaScript experts// Simply put; Is it possible to obtain the real (actual) IP address of...
33
by: baumann.Pan | last post by:
hi all, i want to get the address of buf, which defined as char buf = "abcde"; so can call strsep(address of buf, pointer to token);
4
by: andreas.w.h.k. :-\) | last post by:
How do I change the address location in the wsdl <wsdl:port name="SearchSoap12" binding="tns:SearchSoap12"> <soap12:address location="http://searchservices/engine/search.asmx" /> </wsdl:port> ...
1
by: Phoenix_ver10 | last post by:
I have a mailing list with multiple names going to the same addresses. I need one address with all the names for that address on it. I checked out the example on microsoft's site, but A: It doesn't...
1
by: Jamie J. Begin | last post by:
I'm very new to the world of Python and am trying to wrap my head around it's OOP model. Much of my OOP experience comes from VB.Net, which is very different. Let's say I wanted to create an...
6
by: Nicolas Noakes | last post by:
Hello, I would like to convert to following process to code. Any advice is welcome. I have a hardware device which requires the this procedure to set it's IP address. First create an static...
36
by: Julienne Walker | last post by:
Ignoring implementation details and strictly following the C99 standard in terms of semantics, is there anything fundamentally flawed with describing the use of a (non-inline) function as an...
1
by: saravanatmm | last post by:
I need javascript code for validate the email address. Email address field cannot allowed the capital letters, special characters except '@' symbol. But can allowed the small letters, numeric...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.