|
I tried to used VPN to make a path from Client to Server, and set Server's IP address: 192.168.1.250, Client's IP: 192.168.1.251, but when I run application, they can't connect, ("Connection time out"). Can you show me the way to connect Client Server on the Internet (WAN not LAN).
Contact me: spxuanthu2004@yahoo.com
Thanks.
|
|
|
|
|
I haven't found any way to obtein IP of the client connected to EasyServer.
Is there any easy way for it ?
Thanks
Jose L
|
|
|
|
|
Try the "GetClientIP" method...
Never put more than one leg at atime on the wall.
|
|
|
|
|
I tried it at the first time, but this method seems to be "private".
Looking at your source code "GetClientIP" is really declared as private, so the only way I know for using it is to declare this method "public". it not true ?
Thanks!
|
|
|
|
|
The system that you have developed is excellent and your code is quite well documented. Thank you!
Have you updated EasySocket to work with VS2005? The whole threading system has changed. Suspend and resume are depreciated. If you have a new version please upload it to the Code Project so that others like me may learn from your code.
Thank you again for the very instructive Easy Socket tutorial.
Best regards,
Terryd
|
|
|
|
|
Sorry Terryd, but I havn't wrote such.
I'm glad to hear that my code was helpful...
P.S
Learning about sockets is always a good thing
but when you need fast easy and more reliable mechanism
my advice is to start using "Remoting" now thats a tool !!!
( simply calls a function on remote machine with arguments and returned value... )
Never put more than one leg at atime on the wall.
|
|
|
|
|
Thanks for your really "easy" sockets.
Unfortunatly in you did a big mistake in your demos. You have access in your delegates to the controlls of your forms. But the code within the delegate function runs in the context of the socket.thread. So you will get in trouble. As you can see in the MSDN in the capter "Make Thread-Safe Calls to Windows Forms Controls" you have to use the invoke function. See my changes below:
delegate void SetTboxStatusCallback(string text);
delegate void AppendTBOXCallback(string text);
private void C1_DataArrived(object Data)
{
AppendTBOX("\n" + Data);
}
private void C1_Connected()
{
SetTboxStatusText("Connected to server");
}
private void C1_Disconnected()
{
SetTboxStatusText("Not Connected to server");
}
private void SetTboxStatusText(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.TboxStatus.InvokeRequired)
{
SetTboxStatusCallback d = new SetTboxStatusCallback(SetTboxStatusText);
this.Invoke(d, new object[] { text });
}
else
{
this.TboxStatus.Text = text;
}
}
private void AppendTBOX(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.TboxStatus.InvokeRequired)
{
AppendTBOXCallback d = new AppendTBOXCallback(AppendTBOX);
this.Invoke(d, new object[] { text });
}
else
{
this.TBOXin.AppendText(text);
}
}
}
I did not changes the code of server demo yet, but I am sure it must changes as well.
By the way: I tried to start the demos with "localhost" / "127.0.0.1". Both doesn't work. If I uesed the correct IP-Adress the demo works fine.
Do anybody have an idea?
Axel Kleinekathöfer
|
|
|
|
|
Thanks Akleinek, it's seams greate.
I haven't tried it yet though, can you tell me what will happend to the
form's thread once the AppendTBOXCallback will end (the PC will be restored ) ?
Will the EasySocket's thread will be suspended while the AppendTBOXCallback is invoked/ active ?
Never put more than one leg at atime on the wall.
|
|
|
|
|
Alex to get localhost to work...
First do this in Form1:
///
/// Summary description for Form1.
///
public partial class Form1 : Form
{
private Button button1;
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>VVVVVVVVVVVVVVVVVVVVVVVV<<<<<<<<<
EasyServer S1 = new EasyServer(1501, "localhost", true);
ClientInfo Cinf = new ClientInfo("localhost", true);
private Button button2;
private TextBox textBox1;
private Button button3;
private Button button4;
private Button button5;
private Button button6;
private TextBox TBOXout;
private TextBox TBOXin;
private System.Windows.Forms.Button button8;
///
/// Required designer variable.
///
private Container components = null;
public EasyServer(int PortNumber, string ServerName, bool UseSmartManagement)
{
if(PortNumber <= 0) throw
new EasySocketException("Server's port number must be greater than 0");
IPAddress ServerAddress;
Name = ServerName;
SmartManagementOn = UseSmartManagement;
ServerPort = PortNumber;
try
{
Second in ServerInfo.cs:
//>>>>>>>>>>>>> Change this <<<<<<<<<<<<<<<<<<<<<<<vvvvvvvvvvvvvvvvvv<<<<<<<<<<<
serveraddress="Dns.GetHostByName(Dns.GetHostName()).AddressList[0];
//">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> To this <<<<<<<<<<<<<<<<<<<
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>VVVVVVVVVVV<<<<<<<<<<<<<<<<<
ServerAddress = Dns.GetHostByName(ServerName).AddressList[0];
Listener = new TcpListener(ServerAddress , ServerPort);
}
catch(Exception error)
{
throw new EasySocketException( "Error on attempt to resolve " +
"server's IP address.", error );
}
|
|
|
|
|
Hi, I really liked this component.
Unfortunatly, I had to make some corrections to EasyClient code.
First, use clientSocket instead ClientSocket in some places.
Second, in ConnectingToServer, after OnConnectionTimeOut I added clientSocket.Close() and clientSocket = null. With this, if connection timed out because server's not available, you can try again by calling ConnectToServerAsync.
<br />
if( !clientSocket.Connected )
{ if(OnConnectionTimeOut!=null )OnConnectionTimeOut();<br />
clientSocket.Close();<br />
clientSocket = null;<br />
return;<br />
}<br />
I should probably have added the last two lines before calling OnConnectionTimeOut, but, well, it's already done and it worked.
Best regards
Christian Bourgeois
-- modified at 16:21 Wednesday 22nd February, 2006
|
|
|
|
|
Thanks Christian,
It's good to know that someone actualy review my code,
I've fixed all the glitches you mentioned and about to uploading it up.
I'll be glad if you or anybody else will inform me of more glitches in the code.
P.S
About the clientSocket thing, you must be punctual man or very observe to notice
such glitche. Any way I forgive myself in this case( when using RAD and of code completion utils great deal of the time, suck thing occur).
Thanks again
Never put more than one leg at atime on the wall.
|
|
|
|
|
Hi, I've found your code very good. I was building a more generic socket class, but I couldn't put OnDataArrived event to work, and yours seems to be fine. Thanks for the excelent code.
Now, to my question: have you documentated UseSmartManagement? Because I could not find it in your help. I want to use it, but don't know how to customize it. Thanks for your help in advance.
PS: Sorry about my english, I'm brazilian.
Regards,
Bruno Saboia de Albuquerque
|
|
|
|
|
Hi Bruno,
Actually I did documented UseSmartManagement in the constructor
(but I guess it's not detailed enough) when looking in the programmers documentation,
you can see a private function named SmartManagement.
Anyhow, this function isn't so smart , all it does is scanning the clients list constantly and looking at the last
time a connection was made (to\from) this client, if the time span is bigger than X
the cilent is kicked out.
My original idea was to add some more functionality like resetting the priority of each
thread (in case of more\less clients, more\less data transport, you know...) just didn't
had any power left.
Thanks for you comments (I really appreciate it), hope you'll make the event running.
By the way, your english is fine (how am I to judge I myself am Israeli)
(But way is my rating so poor ?)
Never put more than one leg at atime on the wall.
|
|
|
|
|
Hi! I'm still trying to get your demo to work right. Problem is when I shutdown the client and / or server they both still remain in memory. This occurs no matter what combination of connect / disconnect, listen / shutdown, send / don't send I try....
|
|
|
|
|
Unfortunately you were 100 % correct, I was aware of this problem but it seems that I've forgot all about ( I was so eager to upload it that I've forgot ).
Anyhow thank you for bringing this up, I made some modifications and it shouldn't cause
any more problems.
I've uploaded all the updated stuff again (Doc, code and demo).
Hope no more prob' will come up( I've spent like 2.5 houres just testing it ).
Another issue that u can solve by your self is the case that client was closed and forgot to disconnect.
If SmartManagement is on like in the demo( look for it in doc' if u like), after 30-60 sec of no data movment the server will "clean" the client. But what if it's off ?
In the client form go to Dispose() of the form and make sure that the first thing
it will do will be disconnecting the client from the server.
By the way if you wanna know what was the prob' in the previous version,
it was the threads( I'm using serveral threads to get data/ scan for client...)
before the fix I was trying to close the thread externaly (from another thread)
the compiler screamed that they aren't user threads (nonsense I'v created them see for your self).
Now I'm telling a thread to use the Abort() function on it self once a flag is on.
Never put more than one leg at a time on the wall.
|
|
|
|
|
Hi! I downloaded EasySocket and tried to get the server and client to work on my local machine but I had no luck whatsoever connecting to the server. Any ideas???
|
|
|
|
|
Hi lberman,
The TestServer and TestClient are simple example of using EasySocket namespace,
I can't tell you where is your prob' but here some IMPORTANT points:
//The same idea if you'r using your one solution:
1. Open the TestingServer solution, on line 14 in "form1.cs" file, see the construntor
of the server -> EasyServer S1 = new EasyServer(4000, "ShugonServ", true);
The port number here must be the same port number that you will set on the client
later. (try 4000, 2222 or any port that isn't in use).
go to line 208 : S1.SendData(TBOXout.Text, new ClientInfo("Master", true));
Change "Master" to the name or IP of the machine where the client is.
2. Open the TestingClient solution on line 13 in "form1.cs file":
EasyClient C1 = new EasyClient(new ServerInfo("Master",4000 ,true) );
see the constructor must get the port number that you put in the server,
and the IP of the machine(if it's on local network u CAN use the name of the machine,
if you simply dont know it give it the IP(on Command prompt write ipconfig to see
your IP). In your case this has to be the same string you wrote in the server
solution line 208 cos' it's the same machine.
3. Now be sure that the port you use is not blocked by a firewall. Run bouth solutions,
on the Client form click Is ready button (if the message box tells you that your
ready it's means you gave a legal IP or Machine name. On the server form
click "Listen", return to client form and click connect, if connection was made,
the status textbox should change to "Connected". That should work just fine,
if the prob' wasn't solved notice the excetion messages or and message at all
and tell me what dose it say, good luck.
Never put more than one leg at a time on the wall.
|
|
|
|
|
|