|
Hi friends,
I wrote a TcpListener in my machine in port 20000 and clients connect to this server and everything's fine in LAN, but I have error in Internet connections, here's my Listener code:
int port = 20000;
string recieved = null;
string send = null;
TcpListener listener = new TcpListener(IPAddress.Any, port);
listener.Start();
TcpClient tcp = listener.AcceptTcpClient();
NetworkStream netstream = tcp.GetStream();
StreamReader sr = new StreamReader(netstream);
StreamWriter sw = new StreamWriter(netstream);
recieved = sr.ReadLine();
Console.WriteLine("\nMessage Recieved : " + recieved);
send = Console.ReadLine();
sw.WriteLine(send);
sw.Flush();
Console.WriteLine("\nMessage Sent : " + send);
netstream.Close();
tcp.Close();
and Client code:
string server = "192.168.1.4";
int port = 20000;
string sendmessage = null;
string recievemessage = null;
while (true)
{
TcpClient tcp = new TcpClient(server, port);
NetworkStream netstream = tcp.GetStream();
StreamReader sr = new StreamReader(netstream);
StreamWriter sw = new StreamWriter(netstream);
sendmessage = Console.ReadLine();
sw.WriteLine(sendmessage);
sw.Flush();
Console.WriteLine("\nMessage Sent : " + sendmessage);
recievemessage = sr.ReadLine();
Console.WriteLine("\nMessage Recieve : " + recievemessage);
netstream.Close();
tcp.Close();
}
In Internet usage, I have this error:
No connection could be made because the target machine actively refused it.
I googled and understood that this happens when Server is not listening on this port but my Server was running.
Any idea? Thanks
While (true) { Human.isLearnable = true; }
|
|
|
|
|
You may have problems connecting to your server machine through a router (from outside of your LAN) unless you have port forwarding setup. So, try setting up port forwarding to forward all requestes made on port 20000 to your server machine.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Thank for reply,
I think line "TcpListener listener = new TcpListener(IPAddress.Any, 20000);" accepts all clients connected to port 20000, am I right? Or maybe I couldn't understand you! Thanks again.
While (true) { Human.isLearnable = true; }
|
|
|
|
|
Yeah, but if your server is behind a router, then the router will receive the request and have no idea what to do with it after that. So you use port forwarding, that way the router knows where to send the requests to
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
... or a firewall maybe.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank for your reply,
I checked firewall settings, my Server is Unblocked.
Does the IP of a machine in a LAN different from its IP in internet? I think, because we can set LAN IP but Internet IP should be unique, right? If so, how can I get my machine's Internet IP?
While (true) { Human.isLearnable = true; }
|
|
|
|
|
Pedram Behroozi wrote: Does the IP of a machine in a LAN different from its IP in internet?
Often it is, yes.
See SK Genius' reply...
If you're behind a router or some other gateway, your WAN IP address
may be different than the address(es) of your server machine's network adapter(s).
In that case, you'll need to configure port forwarding so connection requests
to the global address (on your selected listening port) get forwarded to your
server's local address.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you very much, SK Genius and Mark Salsbery.
I understood that my PC can't be a Server cause my Server IP is not Dedicate, it's Share, so that IP or the IP I gave from http://www.whatismyip.com/[^] can't be recognized by Clients and I have Error.
Thanks you again.
While (true) { Human.isLearnable = true; }
|
|
|
|
|
Pedram Behroozi wrote: my PC can't be a Server
Are you sure?
You should be able to configure the network to allow this.
I run several servers from this very machine, accessible from the internet,
and this machine's address is very different from the public address.
It's an IT issue. If you're at a company, maybe there's an IT person who
can set it up for you.
If it's your own network, study the documentation for your router/gateway -
look for "port forwarding".
If there's absolutely no way to configure access to your server from outside your LAN,
well, then I guess your PC can't be a server
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
WOW, THAT'S WORK!!!!!!
jasd gskdf as fdau dlasdfsfdjh gkdfjhg@!!!!!
THANK YOU VERY VERY VERY (to infinity and beyond) MUCH!!!
That's work, I AM HAPPPPIEST MAN IN THE WHOLE WORLD!!!!
I wish I could rate you 100000000000000000000000!
I just search for "Port forwarding" and amazingly I found http://portforward.com/[^] which guided me through Port Forwarding configuration of my Linksys router.
AND THAT'S WORK!!!
How can I thank you? Typing capital letters?
Actually I can't.
BEST REGARDS
While (true) { Human.isLearnable = true; }
|
|
|
|
|
LOL Nicely done! You're an IT Guy now!
YOU did it, but you're VERY VERY VERY (to infinity and beyond) welcome.
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I have 2 forms. One is the main form and another is just a normal form. In the main form, I have two buttons. One is to open modeless form and another is to open modal form (using ShowDialog()). When I clicked the first button, it will show modeless form. However, if I clicked the second button and the modal form is open, the first modeless form can't be access anymore (until the modal form is closed).
Any idea how to allow this modeless form to be accessible?
Thanks for any help
|
|
|
|
|
Hey
That's why they made Modals!!!
but if you used your second form as a modalDialog for preventing access to the mainForm. the simplest way to get rid of it (if you don't care your controls going to be Grey) is to use Show instead of show dialog and pass the mainform instance to form (previously was shown as modal) and disable the mainForm then after hiding the dialog enable it again.
or http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2192114&SiteID=1[^]
Hope its going to help!
|
|
|
|
|
|
if i got data in a Stream class, how can i save it to a directory?
please help,
thanks
|
|
|
|
|
Write it to a FileStream[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Err..
Stream myStream = ...
byte[] data = new byte[myStream.Length];
myStream.Write(data, 0, (int)myStream.Length);
FileStream fs = new FileStream(@"C:\", FileMode.Create);
fs.Write(data, 0, data.Length);
fs.Close();
Would probably work. And you should probably buy yourself a beginners book.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
theoretically u r right but in the "Stream" class there is no "Length" property.
|
|
|
|
|
Well what kind of stream do you actually have? Because that probably does have a length property.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
thank u guys, i got the point!
|
|
|
|
|
I have created a set up project for my application and it works great. Now I want to run some SQL Queries during installation to create a database on the target machine. How can I do this?
|
|
|
|
|
|
I am currently working on developing an application that needs to have the client automatically receive changes to the back end database. The back end db is a SQL2005, with the DAL on a second server to query the SQL and an AS-400. The clients are windows forms. I need for the treeviews and datagrids on the windows forms to receive the updates when other users have made changes to the SQL database. The AS-400 is infromational only so I do not need to capture the changes. I ahve been looking at using timers to create a polling routine, but do not feel that they may be the best method. I ahve also looked at the SQL 2005 Notification Service, which would allow me to push the notices to the DAL Server but not to the clients. I am looking for any suggestions as to best practice as I feel this is a common scenerio but have nto been able to find much documentation on the best wayt o handle. The development language is Visual Sturdio 2008 c# with Framework 3.5.
Thanks for any suggestions
Walter
|
|
|
|
|
|
I will look into this to see if it fits my need. thanks for the suggeston
|
|
|
|