www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Server is not active?

reply "wagtail" <kashiwagi513 gamil.com> writes:
I tried making simple chat program with std.socket.
On starting programs,client program stops.
SocketOSException was caught ,so I checked errorCode().
Win7,which I use,tells me error code 10061.
I surely think to start server program,
and I allow fire wall to connect...

Is there any possible causes else?
Sep 26 2013
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
Can you show us any more code?
Sep 26 2013
parent reply "wagtail" <kashiwagi513 gamil.com> writes:
On Friday, 27 September 2013 at 01:04:47 UTC, Adam D. Ruppe wrote:
 Can you show us any more code?
A part of code shown below. /++++++++++++++++++++++++++ Server main() ++++++++++++++++++++++++++++++++/ ushort port = 9876; auto inet = new InternetAddress("0.0.0.0",port); Socket server = new TcpSocket(inet.addressFamily()); bool flag = true; server.bind(inet); server.listen(255); titleMes();//show titleMessage while(flag){ Socket client; printf("WaitingConnection..."); try{ client = server.accept(); client.blocking(true); }catch(SocketAcceptException){ printf("acceptEx..."); } myTasks.add(new Task(client,&(mesLog.add))); //Task : Thread class containing Socket. flag = false; printf("need more connection? y,n"); char[] yn; yn = cast(char[])readln(); if(yn[0]=='y')flag = true; else { foreach(Task t;myTasks.getArray)t.start(); foreach(Task t;myTasks.getArray)t.getTarget_p().send("OK"); } } int old=0; while(1){ for(int i=0;i<10000;i++){for(int j=0;j<10000;j++){}} system("cls"); foreach(char[] c;mesLog.getArray)writeln(c); } } /+++++++++++++++++++++++++++++ client main() ++++++++++++++++++++++++++++++++/ Socket target; //Listener is Thread continuing to do listen(). Listener listener; auto INET_OWN = new InternetAddress(InternetAddress.PORT_ANY); char[] address; ushort port = 9876; InternetAddress INET_DES; titleMes(); writeln("Please input destination ipAddress.(IPv4)(ex:218.112.218.204)"); address = readln().dup; write("target : "); writeln(address); INET_DES = new InternetAddress(address,port); target = new TcpSocket(/*INET_OWN.addressFamily()*/); //connection try{ target.connect(INET_DES); }catch(SocketOSException e){ printf("Errorcode%d\n",e.errorCode); if(e.errorCode==10061)writeln("Server is not available\n"); } ......
Sep 26 2013
next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
hmm, I don't know what the problem is, the socket stuff there 
looks correct... will have to wait for someone else to have ideas.
Sep 26 2013
parent "wagtail" <kashiwagi513 gamil.com> writes:
On Friday, 27 September 2013 at 01:37:38 UTC, Adam D. Ruppe wrote:
 hmm, I don't know what the problem is, the socket stuff there 
 looks correct... will have to wait for someone else to have 
 ideas.
Thank you for your reply. I'll think it over again.
Sep 26 2013
prev sibling next sibling parent reply ollie <ollie home.net> writes:
On Fri, 27 Sep 2013 03:22:32 +0200, wagtail wrote:

 A part of code shown below.
 
 /++++++++++++++++++++++++++ Server main()
 ++++++++++++++++++++++++++++++++/
          ushort port = 9876;
 
 	auto inet = new InternetAddress("0.0.0.0",port);
 	Socket server = new TcpSocket(inet.addressFamily());
 
 	bool flag = true;
 
 	server.bind(inet);
 	server.listen(255);
Is there any particular reason to use "0.0.0.0" creating your InternetAddress? I think it should be the ip of your server or just send port and ADDR_ANY will be used. From Wikipedia: In the Internet Protocol version 4 the address 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown or non applicable target.
Sep 27 2013
parent reply "wagtail" <kashiwagi513 gamil.com> writes:
On Saturday, 28 September 2013 at 05:28:05 UTC, ollie wrote:
 On Fri, 27 Sep 2013 03:22:32 +0200, wagtail wrote:

 A part of code shown below.
 
 /++++++++++++++++++++++++++ Server main()
 ++++++++++++++++++++++++++++++++/
          ushort port = 9876;
 
 	auto inet = new InternetAddress("0.0.0.0",port);
 	Socket server = new TcpSocket(inet.addressFamily());
 
 	bool flag = true;
 
 	server.bind(inet);
 	server.listen(255);
Is there any particular reason to use "0.0.0.0" creating your InternetAddress? I think it should be the ip of your server or just send port and ADDR_ANY will be used. From Wikipedia: In the Internet Protocol version 4 the address 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown or non applicable target.
Thank you for your reply! I thought ADDR_ANY is the same as "0.0.0.0",so I used it. This Server doesn't know ip of opponent client. I tried rewriting code with using "ADDR_ANY", but do not work...
Sep 27 2013
parent reply ollie <ollie home.net> writes:
On Sat, 28 Sep 2013 08:42:16 +0200, wagtail wrote:

 I tried rewriting code with using "ADDR_ANY", but do not work...
Ali Çehreli posted some examples in the D.learn group earlier. He creates the socket then uses its member functions to setup the connection, but it should work either way. Try something like this: auto inet = new InternetAddress(port); The constructor for class InternetAddress will set addr to ADDR_ANY. This should work if your server and client are on the same machine. Otherwise you need to set the address to the IP of your server. Would need some basic compilable code to know for sure how to make that work in your situation.
Sep 28 2013
parent reply "wagtail" <kashiwagi513 gamil.com> writes:
On Saturday, 28 September 2013 at 17:13:06 UTC, ollie wrote:

 Try something like this:

 auto inet = new InternetAddress(port);
Oh,I'm sorry. I forgot writing I already tried above instance.
 The constructor for class InternetAddress will set addr to 
 ADDR_ANY.
 This should work if your server and client are on the same 
 machine.
 Otherwise you need to set the address to the IP of your server.
When my server and client are on the same machine,these succeed. If I try communicating with other machine via global network,it do not work. IP of my server which you say above should set to server side?
Sep 28 2013
parent reply ollie <ollie home.net> writes:
On Sun, 29 Sep 2013 03:47:27 +0200, wagtail wrote:

 When my server and client are on the same machine,these succeed.
 If I try communicating with other machine via global network,it do not
 work.
 IP of my server which you say above should set to server side?
When you instantiate your InternetAddress class, set it to the assigned IP of your server machine. It's starting to look like more of a network configuration problem and not a D.learn problem. I'd rather not pollute this forum with those type of issues. Good luck.
Sep 29 2013
parent "wagtail" <kashiwagi513 gamil.com> writes:
On Sunday, 29 September 2013 at 15:25:53 UTC, ollie wrote:
 When you instantiate your InternetAddress class, set it to the 
 assigned
 IP of your server machine.

 It's starting to look like more of a network configuration 
 problem and
 not a D.learn problem. I'd rather not pollute this forum with 
 those
 type of issues. Good luck.
I'll do my best. Thank you.
Sep 30 2013
prev sibling parent reply "Kapps" <opantm2+spam gmail.com> writes:
This is just a guess, but it is because you're setting the socket 
to be blocking after the call to accept? If it defaults to 
non-blocking, this would cause accept to return immediately, so 
the client connecting would fail as the server isn't currently 
accepting connections. Also to verify it's not a firewall issue, 
for connecting try using 127.0.0.1.
Sep 28 2013
parent "wagtail" <kashiwagi513 gamil.com> writes:
On Saturday, 28 September 2013 at 23:25:20 UTC, Kapps wrote:
 This is just a guess, but it is because you're setting the 
 socket to be blocking after the call to accept? If it defaults 
 to non-blocking, this would cause accept to return immediately, 
 so the client connecting would fail as the server isn't 
 currently accepting connections. Also to verify it's not a 
 firewall issue, for connecting try using 127.0.0.1.
Thank you for your reply:) Seeing your reply, I try commenting "client.blocking(true)" out, but it do not work. My server and client do work using 127.0.0.1, So ,maybe I think firewall setting is correct.
Sep 28 2013