Server is not active?

wagtail kashiwagi513 at gamil.com
Thu Sep 26 18:22:32 PDT 2013


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");
	}

	......


More information about the Digitalmars-d-learn mailing list