changeset 0:536b29f11352

add some files
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sat, 28 Apr 2012 21:01:53 +0900
parents
children 68307ce6839d
files echoServer/echoClient.k echoServer/echoServer.c echoServer/echoServer.k error/modifyMissType.k error/returnValue.k factorial/factorial.k test/addField.k test/math.k test/out.k test/output.txt
diffstat 10 files changed, 245 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/echoServer/echoClient.k	Sat Apr 28 21:01:53 2012 +0900
@@ -0,0 +1,24 @@
+using konoha.socket.*;
+using konoha.io.*;
+
+void main(String[] args) 
+{
+	int port = 8888;
+	String host = "localhost";
+	print "port number = " + port;
+	print "host = " + host;
+
+	Socket sock = new Socket(host, port);
+
+	InputStream in = sock.getInputStream();
+	OutputStream out = sock.getOutputStream();
+
+	out <<< "test" <<< EOL;
+	out.flush();
+	String b = in.readLine();
+	print b;
+	in.close();
+	out.close();
+	
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/echoServer/echoServer.c	Sat Apr 28 21:01:53 2012 +0900
@@ -0,0 +1,76 @@
+/*
+ * http://blog.majide.com/2009/02/socket-programming-server/
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <unistd.h>
+
+#define PORT 8888
+#define MAXDATA 2048
+
+int main()
+{
+	struct sockaddr_in saddr;
+	struct sockaddr_in caddr;
+	
+	int listen_fd;
+	int conn_fd;
+	
+	int len = sizeof(struct sockaddr_in);
+
+	int rsize;
+	char buf[MAXDATA];
+	
+	if ((listen_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+		perror("socket");
+		exit(EXIT_FAILURE);
+	} 
+	
+	bzero((char *)&saddr, sizeof(saddr));
+
+	saddr.sin_family = PF_INET;
+	saddr.sin_addr.s_addr = INADDR_ANY;
+	saddr.sin_port = htons(PORT);
+	if (bind(listen_fd, (struct sockaddr *)&saddr, len) < 0) {
+		perror("bind");
+		exit(EXIT_FAILURE);
+	}
+
+	if (listen(listen_fd, SOMAXCONN) < 0) {
+		perror("listen");
+		exit(EXIT_FAILURE);
+	}
+	printf("Start Listening Port : %d", PORT);
+
+	if ((conn_fd = accept(listen_fd, (struct sockaddr *)&caddr, &len)) < 0) {
+		perror("accept");
+		exit(EXIT_FAILURE);
+	}
+	printf("\nconn_fd = %d\n",conn_fd);
+	close(listen_fd);
+	do {
+		rsize = recv(conn_fd, buf, MAXDATA, 0);
+		if (rsize == 0) {
+			break;
+		} else if (rsize == -1) {
+			perror("recv");
+			exit(EXIT_FAILURE);
+		} else {
+			write(conn_fd, buf, rsize);
+		}
+	} while(1);
+		
+	if ( close(conn_fd) < 0) {
+		perror("error");
+		exit(EXIT_FAILURE);
+	}
+	
+	printf("Connection close.\n");
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/echoServer/echoServer.k	Sat Apr 28 21:01:53 2012 +0900
@@ -0,0 +1,23 @@
+using konoha.socket.*;
+using konoha.io.*;
+
+void main(String[] args) 
+{
+	int port = 8888;
+	print "port number = " + port;
+	ServerSocket servSock = new ServerSocket(port, 1);
+
+	print "accept..."
+	Socket sock = servSock.accept();
+	print "accepted"
+
+	InputStream in = sock.getInputStream();
+	OutputSteram out = sock.getOutputStream();
+
+	while ( !in.isClosed() ) {
+		String b = in.readLine();
+		print b;
+		out <<< b <<< EOL;
+		out.flush();
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/error/modifyMissType.k	Sat Apr 28 21:01:53 2012 +0900
@@ -0,0 +1,8 @@
+int f() {
+    return 3;
+}
+
+void main(String[] args) {
+     String a = f(); 
+     String b = f(); 
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/error/returnValue.k	Sat Apr 28 21:01:53 2012 +0900
@@ -0,0 +1,11 @@
+void f() {
+     return 0;
+}
+byte g() {
+     return 0;
+}
+ 
+void main(String[] args) {
+     f();
+     g();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/factorial/factorial.k	Sat Apr 28 21:01:53 2012 +0900
@@ -0,0 +1,17 @@
+def factorial(n) {
+    if(n == 1) 1;
+    return n * factorial(n-1);
+}
+
+void main(String[] args) {
+//       OUT << "output test" << EOL;
+       unsigned int result;
+       if(args.size > 0) {
+       	 result = factorial((int)args[0]);
+	 print "factorial(" + args[0] +")";
+       } else {
+       	 result = factorial(3);
+	 print "factorial(3)";
+       }
+       print result;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/addField.k	Sat Apr 28 21:01:53 2012 +0900
@@ -0,0 +1,22 @@
+
+class PersonA {
+      String name;
+}
+
+@Expando class PersonB {
+      String name;
+}
+
+void main(String[] args) {
+
+     PersonA p = new PersonA();
+     p.name = "maro";
+//     p.age = 22; // error
+     print p.name;
+     
+     pp = new PersonB();
+     pp.name = "goro";
+     pp.age = 22;
+     print pp.name + ":" + pp.age
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/math.k	Sat Apr 28 21:01:53 2012 +0900
@@ -0,0 +1,49 @@
+using konoha.math.*;
+
+void main(String[] args) {
+	int x, y;
+	if (args.size > 2 ) {
+		x = (int)args[0];
+		y = (int)args[1];
+	} else if (args.size == 1) {
+		x = (int)args[0];
+		y = 45;
+	} else {
+		x = 45;
+		y = 45;
+	}
+	int e,d;
+	e = 10;
+	d = 3;
+
+	print "x = " + x;
+	print "y = " + y;
+	print "e = " + e;
+	print "d = " + d;
+
+	print "Math.abs(x) = " + Math.abs(x);
+	print "Math.fabs(x) = " + Math.fabs(x);
+	print "Math.pow(x,y) = " + Math.pow(x,y);
+	print "Math.ldexp( x, e) = " + Math.ldexp( x, e);
+	print "Math.modf( x, y) = " + Math.modf( x, y);
+	print "Math.frexp( x, y) = " + Math.frexp( x, y);
+	print "Math.fmod( x, d) = " + Math.fmod( x, d);
+	print "Math.ceil( x) = " + Math.ceil( x);
+	print "Math.floor(x) = " + Math.floor(x);
+	print "Math.sqrt(x) = " + Math.sqrt(x);
+	print "Math.exp(x) = " + Math.exp(x);
+	print "Math.log10(x) = " + Math.log10(x);
+	print "Math.log(x) = " + Math.log(x);
+	print "Math.sin(x) = " + Math.sin(x);
+	print "Math.cos(x) = " + Math.cos(x);
+	print "Math.tan(x) = " + Math.tan(x);
+	print "Math.asin(x) = " + Math.asin(x);
+	print "Math.acos(x) = " + Math.acos(x);
+	print "Math.atan(x) = " + Math.atan(x);
+	print "Math.atan2(x, y) = " + Math.atan2(x, y);
+	print "Math.sinh(x) = " + Math.sinh(x);
+	print "Math.cosh(x) = " + Math.cosh(x);
+	print "Math.tanh(x) = " + Math.tanh(x);
+	
+	 
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/out.k	Sat Apr 28 21:01:53 2012 +0900
@@ -0,0 +1,13 @@
+void main(String[] args) {
+	int size = 0;
+	OutputStream out = new OutputStream("output.txt");
+	String m = "out put test";
+	out <<< m <<< EOL;
+	if(args.size > 0) {
+		out <<< args[0] <<< EOL;
+	}
+	else  {
+		out <<< "test" <<< EOL;
+	}
+	out.close();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/output.txt	Sat Apr 28 21:01:53 2012 +0900
@@ -0,0 +1,2 @@
+out put test
+test