Tuesday, April 6, 2010

A list of RTOS overview.

From : http://blog.csdn.net/reniuliu/archive/2009/03/06/3963726.aspx


从网上搜集一些资料,整理了下,能对EOS有个整体认识。



EOS与通用的桌面OS相比较主要特点在于:

1,小内核,稳定可靠。

2,需要可装卸、可裁剪,以便能灵活应对各种不同的硬件平台。

3,面向应用,强实时性,可用于各种设备控制当中。

国际上常见的嵌入式操作系统大约有40种左,右如:Linux、uClinux、WinCE、PalmOS、Symbian、eCos、uCOS-II、 VxWorks、pSOS、Nucleus、ThreadX 、Rtems 、QNX、INTEGRITY、OSE、C Executive 。他们基本可以分为两类,一类是面向控制、通信等领域的实时操作系统,如windriver公司的vxworks、isi的psos、qnx系统软件公司的qnx、ati的nucleus等;另一类是面向消费电子产品的非实时操作系统,这类产品包括个人数字助理(pda)、移动电话、机顶盒、电子书、 webphone等,系统有Microsoft的WinCE,3Com的Palm,以及Symbian和Google的Android等。

(一)VxWorks
VxWorks操作系统是美国WindRiver公司于1983年设计开发的一种嵌入式实时操作系统(RTOS),是Tornado嵌入式开发环境的关键组成部分。良好的持续发展能力、高性能的内核以及友好的用户开发环境,在嵌人式实时操作系统领域逐渐占据一席之地。
VxWorks具有可裁剪微内核结构;高效的任务管理;灵活的任务间通讯;微秒级的中断处理;支持POSIX 1003.1b实时扩展标准;支持多种物理介质及标准的、完整的TCP/IP网络协议等。
然而其价格昂贵。由于操作系统本身以及开发环境都是专有的,价格一般都比较高,通常需花费10万元人民币以上才能建起一个可用的开发环境,对每一个应用一般还要另外收取版税。一般不通供源代码,只提供二进制代码。由于它们都是专用操作系统,需要专门的技术人员掌握开发技术和维护,所以软件的开发和维护成本都非常高。支持的硬件数量有限。

(二)Windows CE
Windows CE与Windows系列有较好的兼容性,无疑是Windows CE推广的一大优势。其中WinCE3.0是一种针对小容量、移动式、智能化、32位、了解设备的模块化实时嵌人式操作系统。为建立针对掌上设备、无线设备的动态应用程序和服务提供了一种功能丰富的操作系统平台,它能在多种处理器体系结构上运行,并且通常适用于那些对内存占用空间具有一定限制的设备。它是从整体上为有限资源的平台设计的多线程、完整优先权、多任务的操作系统。它的模块化设计允许它对从掌上电脑到专用的工业控制器的用户电子设备进行定制。操作系统的基本内核需要至少200KB的ROM。由于嵌入式产品的体积、成本等方面有较严格的要求,所以处理器部分占用空间应尽可能的小。系统的可用内存和外存数量也要受限制,而嵌入式操作系统就运行在有限的内存(一般在ROM或快闪存储器)中,因此就对操作系统的规模、效率等提出了较高的要求。从技术角度上讲,Windows CE作为嵌入式操作系统有很多的缺陷:没有开放源代码,使应用开发人员很难实现产品的定制;在效率、功耗方面的表现并不出色,而且和Windows一样占用过的系统内存,运用程序庞大;版权许可费也是厂商不得不考虑的因素。

(三)嵌入式Linux
这是嵌入式操作系统的一个新成员,其最大的特点是源代码公开并且遵循GPL协议,在近一年多以来成为研究热点,据IDG预测嵌入式Linux将占未来两年的嵌入式操作系统份额的50%。
由于其源代码公开,人们可以任意修改,以满足自己的应用,并且查错也很容易。遵从GPL,无须为每例应用交纳许可证费。有大量的应用软件可用。其中大部分都遵从GPL,是开放源代码和免费的。可以稍加修改后应用于用户自己的系统。有大量的免费的优秀的开发工具,且都遵从GPL,是开放源代码的。有庞大的开发人员群体。无需专门的人才,只要懂Unix/Linux和C语言即可。随着 Linux在中国的普及,这类人才越来越多。所以软件的开发和维护成本很低。优秀的网络功能,这在Internet时代尤其重要。稳定——这是Linux 本身具备的一个很大优点。内核精悍,运行所需资源少,十分适合嵌入式应用。
支持的硬件数量庞大。嵌入式Linux和普通Linux并无本质区别,PC上用到的硬件嵌入式Linux几乎都支持。而且各种硬件的驱动程序源代码都可以得到,为用户编写自己专有硬件的驱动程序带来很大方便。
在嵌入式系统上运行Linux的一个缺点是Linux体系提供实时性能需要添加实时软件模块。而这些模块运行的内核空间正是操作系统实现调度策略、硬件中断异常和执行程序的部分。由于这些实时软件模块是在内核空间运行的,因此代码错误可能会破坏操作系统从而影响整个系统的可靠性,这对于实时应用将是一个非常严重的弱点。

(四)μC/OS一Ⅱ
μC/OS一Ⅱ是著名的源代码公开的实时内核,是专为嵌入式应用设计的,可用于8位,16位和32位单片机或数字信号处理器(DSP)。它是在原版本μC /OS的基础上做了重大改进与升级,并有了近十年的使用实践,有许多成功应用该实时内核的实例。它的主要特点如下:
公开源代码,容易就能把操作系统移植到各个不同的硬件平台上;
可移植性,绝大部分源代码是用C语言写的,便于移植到其他微处理器上;
可固化;
可裁剪性,有选择的使用需要的系统服务,以减少斗所需的存储空间;
占先式,完全是占先式的实时内核,即总是运行就绪条件下优先级最高的任务;
多任务,可管理64个任务,任务的优先级必须是不同的,不支持时间片轮转调度法;
可确定性,函数调用与服务的执行时间具有其可确定性,不依赖于任务的多少;
实用性和可靠性,成功应用该实时内核的实例,是其实用性和可靠性的最好证据。
由于μC/OS一Ⅱ仅是一个实时内核,这就意味着它不像其他实时存在系统那样提供给用户的只是一些API函数接口,还有很多工作需要用户自己去完成。

(五)QNX

由QNX软件公司所开发的QNX操作系统,也是一套类UNIX的嵌入式操作系统,跟VxWorks同样的,QNX也是一套符合POSIX规范的操作系统。

与 VxWorks同样发迹于1980年代的QNX,其特殊之处,在于其并非采用传统的高阶硬件虚拟层方式设计,而是以非常细碎的tasks形式来执行,由许多的微核心为基础组成完整的OS服务,因此QNX的硬件设计者可以自由的选择加载执行或不加载某些特定的服务,而不用去变更QNX的核心程序部份。因此基于QNX的嵌入式操作系统可以做到非常小的程度,而且依然可以具有相当高的效率与完整的菜单现。

QNX 操作系统核心仅包含了CPU任务排程、进程间通讯、中断重导向以及定时器等部份,而除此之外包含驱动程序、档案系统堆叠协议以及使用者应用程序的所有程序都是属于在使用者阶段执行。QNX操作系统有个相当特殊的Proc阶段,专门负责程序process的建立,以及存储器管理等交集在系统微核心中的组件。基本上,QNX所有的组件都能透过消息传递这个函式来进行沟通,而具有良好定义的通讯机制,也能保障所有的组件都有完全独立且被保护的储存及执行空间。因此有问题的应用程序不会影响到其它组件的稳定性,发生问题的程序将会被自动终止并重新启动。

与传统的操作系统架构相较起来,微核心架构可以让嵌入式系统获得更为快速的平均回覆时间(MTTR),当硬件驱动程序失效,QNX可以在数毫秒之内,就对该驱动程序进行终止、回收资源并重新启动的步骤,让嵌入式设备可接近无停摆时间表现。

不过微核心RTOS的架构除了优点以外,由于其process间的讯息传递功能将会占用存储器频宽,影响到校能表现,因此在实际应用上,就必须采用特殊的最佳化手段,以避免掉讯息传递功能所带来的性能耗损。

虽然QNX整间公司在2004年出售给Haman International Industries,但QNX操作系统的发展脚步依旧没有停止,在国外,除了与各家国际汽车大厂合作,成为车用电子的主力操作系统以外,也获得相当多的航空公司与重要军事单位采用。而在2005年底,QNX也与国内几家包含联电、Zinwell等公司进行了合作,研华、控创等工业计算机厂商也都有针对这方面在发展。


(六)Nucleus Plus

这款嵌入式操作系统主要特征就是轻薄短小,其架构上的延展性,可以让Nucleus RTOS所占的储存空间压缩到仅有13K左右,而且Nucleus Plus是一款不需授权费的操作系统,并且提供了原始码。

Nucleus Plus本身只是Acclerated Technology公司完整解决方案里面的其中一环,这个RTOS本身架构属于先占式多工设计,有超过95%的原始码是用标准的ANSI C语言所编写,因此可以非常有效率的移植到各种不同的平台。Nucleus Plus在CISC架构处理器中,核心部份大约占去20KB左右的储存空间,而在RISC处理器上则是40KB左右,核心资料结构仅占约1.5KB,由于其即时回应、先占式多工、以及多process并行,并且开放原始码等特性,在国防、工控、航天工业、铁路、网络、POS、自动化控制以及信息家电等领域广泛受到应用。

就如同QNX一般,Nucleus Plus也可以根据目标产品的需求,来自行剪裁所需要的系统功能,达到精简体积的目的。而配合相对应的编译器(Borland c/c++、Microsoft c/c++)以及动态连结程序库和各种底层驱动程序,在开发上拥有非常相当大的便利性。诸如飞思卡尔(Freescale)、罗技(Logitech)公司、美国NEC、SK Telecom等公司,都有采用Nucleus Plus嵌入式操作系统作为开发产品使用。

Wednesday, March 24, 2010

Static variable inside a function

int nonestatic_var_Test(void)
{
int number_of_times=0;

for(int y=0; y<10; y++)
{
number_of_times++;
}

return number_of_times;

}


int static_var_Test(void)
{
static int static_number_of_times = 0;

for(int y=0; y<10; y++)
{
static_number_of_times++;
}

return static_number_of_times;

}


int main()
{

int i;
int func_invoke_times;

for(i=0;i<10;i++)
func_invoke_times=static_var_Test();

printf("static_func_invoke_times is %d\n",func_invoke_times);

for(i=0;i<10;i++)
func_invoke_times=static_var_Test();
printf("static_func_invoke_times is %d\n",func_invoke_times);

for(i=0;i<10;i++)
func_invoke_times=nonestatic_var_Test();

printf("nonstatic_func_invoke_times is %d\n",func_invoke_times);

for(i=0;i<10;i++)
func_invoke_times=nonestatic_var_Test();
printf("nonstatic_func_invoke_times is %d\n",func_invoke_times);

}





result:

static_func_invoke_timers is 100
static_func_invoke_timers is 200
nonstatic_func_invoke_timers is 10
nonstatic_func_invoke_timers is 10

Tuesday, November 17, 2009

FW: How to copy arrays and objects in Javascript

from: http://my.opera.com/GreyWyvern/blog/show.dml/1725165

How to copy arrays and objects in Javascript

Friday, 8. February 2008, 01:29:48

object, tip, clone, copy, array, javascript
There are a few things that trip people up with regards to Javascript. One is the fact that assigning a boolean or string to a variable makes a copy of that value, while assigning an array or an object to a variable makes a reference to the value. The trouble this causes can range from befuddlement - when two variables you assume are separate are in fact references to the same value - to frustration when you realize there is no native way to tell the Javascript engine to pass a value rather than a reference.

In PHP, for example, all assignments make copies unless you explicitly tell the engine to pass a reference using the =& operator. If only it were so simple in Javascript.

I'm pretty much reinventing the wheel with this post since this issue has been solved before, but the reason I'm writing it is because up until recently I had always been designing custom functions to copy objects of types I designed myself. Very efficient on a per-case basis, but not very reusable. There had to be a way to make such a thing work for any and all arrays and objects. So I searched the interwebs and was enlightened.

Firstly, arrays. Surprisingly, arrays are easy to copy because a couple of native Array object methods actually return a copy of the array. The easiest to use is the slice() method:

var foo = [1, 2, 3];
var bar = foo;
bar[1] = 5;
alert(foo[1]);
// alerts 5

var foo = [1, 2, 3];
var bar = foo.slice(0);
bar[1] = 5;
alert(foo[1]);
// alerts 2


The slice(0) method means, return a slice of the array from element 0 to the end. In other words, the entire array. Voila, a copy of the array. The only caveat to remember here is that this method works if the array contains only simple data types, like numbers, strings and booleans. If the array contains objects or other arrays (a multi-dimensional array), then those contained "objects" will be copied by reference, retaining a connection with the source array. In such a case you will need to copy the array as a full-fledged object.

Objects are trickier because there is no native method which returns a copy of the object. So instead we add one ourselves using a prototype method:

Object.prototype.clone = function() {
var newObj = (this instanceof Array) ? [] : {};
for (i in this) {
if (i == 'clone') continue;
if (this[i] && typeof this[i] == "object") {
newObj[i] = this[i].clone();
} else newObj[i] = this[i]
} return newObj;
};


Notice the recursion going on; isn't it divine? :smile: The clone() method steps through the properties of any object one by one. If the property is itself an object or array, it calls the clone() method on that object too. If the property is anything else, it just takes the value of the property. Then the result received is assigned to a property of the same name in a new object.

Finally, after we're done stepping through all properties, return the new object which is a copy of - not a reference to - the old object. A call to the clone method is as simple as this:

var foo = {a: 1, b: 2, c: 3};
var bar = foo;
bar.b = 5;
alert(foo.b);
// alerts 5

var foo = {a: 1, b: 2, c: 3};
var bar = foo.clone();
bar.b = 5;
alert(foo.b);
// alerts 2

Monday, November 2, 2009

Forms' element samples (checkbox,radio,select,option)

[HTML>
[HEAD>
[TITLE>Checkbox Inspector[/TITLE>
[SCRIPT LANGUAGE="JavaScript">
function inspectBox() {
if (document.forms[0].checkThis.checked) {
alert("The box is checked.")
} else {
alert("The box is not checked at the moment.")
}
}


function inspectRadio() {
for (var i = 0; i [ document.forms[0].sex.length; i++) {
if (document.forms[0].sex[i].checked) {
break
}
}
alert("You chose " + document.forms[0].sex[i].value + ".")
}


function verifySong(entry) {
var song = entry.value
alert("Checking whether " + song + " is a Beatles tune...")
}


function showCarSelected() {
var list = document.forms[0].carSelect
alert("SelectIndex="+list.selectedIndex+" Value="+list.options[list.selectedIndex].value+" "+list.options[list.selectedIndex].text+" Car is selected.");
}


function checkAll(field)
{
for (i = 0; i [ field.length; i++)
field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i [ field.length; i++)
field[i].checked = false ;
}

[/SCRIPT>
[/HEAD>
[BODY>
[FORM>
[INPUT TYPE='checkbox' NAME='checkThis' onClick='javascript:inspectBox()'>Check here[BR>

[input type="radio" name="sex" value="male" onClick='javascript:inspectRadio()' > Male
[br />
[input type="radio" name="sex" value="female" onClick='javascript:inspectRadio()'> Female
[br>

[INPUT TYPE="text" NAME="song" VALUE = "Eleanor Rigby" onChange="verifySong(this)">[P>


[select name="carSelect" onChange="showCarSelected()" >
[option value="0" >Volvo[/option>
[option value="1" >Saab[/option>
[option >Mercedes[/option>
[option selected >Audi[/option>
[/select>


[/FORM>

[form name="myform" action="checkboxes.asp" method="post">

[b>Your Favorite Scripts & Languages[/b>[br>
[input type="checkbox" name="list" value="1">Java[br>
[input type="checkbox" name="list" value="2">Javascript[br>
[input type="checkbox" name="list" value="3">Active Server Pages[br>
[input type="checkbox" name="list" value="4">HTML[br>
[input type="checkbox" name="list" value="5">SQL[br>

[input type="button" name="CheckAll" value="Check All"
onClick="checkAll(document.myform.list)">
[input type="button" name="UnCheckAll" value="Uncheck All"
onClick="uncheckAll(document.myform.list)">
[br>
[/FORM>
[/BODY>
[/HTML>

Thursday, October 22, 2009

转:PHP网站开发方案(开发新人必读)

PHP网站开发方案(开发新人必读)
发布时间:2009-9-18 11:30  作者: php.cn  信息来源: PHPchina  发表评论
一、开发成员

a)项目主管
b)页面美工
c)页面开发
d)服务端程序开发
e)系统与数据管理
f)测试与版本控制

二、 网站组开发简明流程


三、 开发工具与环境

a)服务器配置
i. WEB服务器: FreeBSD6.1+Apache2.0+PHP5.0,SVN版本控制服务(仅测试机)。
ii.数据库服务器: WIN2003 server+SQL server 2000+MySQL5.0,CLUSTERED SERVER 集群服务,邮件服务器。
iii. 100M/1000M交换机
b) 开发工具
i. 前台: Macromedia flash 8.0、Macromedia Dreamweaver 8.0、Adobe photoshop CS
ii. 后台: Zend Studio 5.2、SQL Server Enterprise Manager、PhpMyAdmin

四、 技术规则

a) 浏览器兼容策略: 兼容IE5.0以上版本,同时兼容FireFOX2.0以上浏览器。
b) 搜索引擎优化: 着重针对baidu、Google、Yahoo搜索优化,制作清晰明确的网站地图。
c) 字符编码规则:中文网站一率采用GB2312字符标准。[目前我统一使用UTF-8编码包括了数据库的文件内容的编码统一]
d) 文件与文件夹命名: 为兼容win32与unix系统,一率采用小写字母命名。
(统一全站的文件夹与文件的命名都使用小写的形式处理。这样不会出现问题了!)
e) 公共文件命名规则:
i. 默认首页: index.htm、index.html、index.php
ii. 主CSS文件: style.css
iii. 主JS文件: main.js
iv. 主程序配置文件:config.php
f) 公共文件目录统一命名
i. 图片目录: /images 或者 /pic
ii. CSS样式目录: /css
iii. JS脚本程序目录:/js
iv.模板文件目录:/tpl
v. 类或者组件目录:/class 或者 /lib
g) 页面脚本规范: 统一采用JavaScript
h)代码中的类、函数、变量名:统一使用近似英文单词命名,如:DefaultClass 或者 default_class
i) 代码注释规则:所有程序中的函数或者过程必须加确切的注释。
j) 数据库相关规则
i. 数据表与字段命名规则: 全部小写字母命名,并归类命名前缀,如:用户表组,user_passport、user_info、user_service….
ii. 日期类型字段: 统一使用unix时间戳,char(12)
iii. 主关键字命名: 所有表必须建立以id命名的主键。
k) 模板组件规则:统一使用兼容版本的Smarty,统一缓存目录,便于Unix下权限控制。
(设置全部的可写文件统一放入到一个目录下面去做成缓存目录用)
l) 数据库虚拟层: 统一使用Adodb 或 Pdo,SQL语句要兼容现有主流数据库规则。
m)工厂模式开发规则: 以comm.php为中心开发或继承组件类,统一控制文件调用IO与类的实例化。
n) 面向对象开发规则: 所有函数必须以类 ---> 过程的方式存在。
(学会封装代码成类的形式出现)
o) SQL封装规则: 所有SQL语句及数据库查询必须存在于过程中。

p) URL转向规则: 为优化搜索引擎,尽量使用Apache的mod_rewrite模块来美化URL,如:http://www.yourname.com/action.php?id=123转化为:http://www.yourname.com/action/id/123或者http://www.yourname.com/action/id_123.html


五、 网站安全与维护策略

a) 服务器与数据库安全:
i. 建立完善的病毒防御机制,安装防火墙,关闭服务器上任何不必要的端口以及服务。
ii. 统一管理用户权限,定期跟踪用户及系统事件,定期查看系统日志。
b) 容灾与备份机制:
i. 建立数据库集群,至少保持一台服务器同步数据,确保意外发生时数据库系统可自动转移到正常的服务器稳定运行。
ii. 定期备份文件及数据,通过各种方式保存数据与文件。
c) 程序安全策略:
i. SQL注入防范:坚决过滤不可预见的非法字符,严格做好数据库查询、更新的SQL语句检验。
ii. 不使用来路不明的第三方源码,不轻易将未知代码拷贝到服务器。

TAG: 新人 网站开发 PHP php 方案

Tuesday, October 20, 2009

Convert binary file to ASCII file

/************************************************/
/* Convert binary file to ASCII file */
/************************************************/


#include < D:/VC6Green/VC98/Include/math.h>
#include < D:/VC6Green/VC98/Include/stdio.h>
#include < D:/VC6Green/VC98/Include/string.h>



void __ConvertBinFile_To_ASCIIFile(void *ptrInRd, void *ptrOutWr)
{
unsigned char lcByteIn,i;
FILE *ptrRd,*ptrWr;

ptrRd=(FILE *)(ptrInRd);
ptrWr=(FILE *)(ptrOutWr);


i=0;

fprintf(ptrWr, " ");

while (1)
{
lcByteIn = fgetc(ptrRd);
if(feof(ptrRd)!=0)
break;
printf("%02X ",lcByteIn); /* O/P the character to the screen */
fprintf(ptrWr, "%02X ",lcByteIn);
i++;
if (i==16)
{
printf("\n");
fprintf(ptrWr, "\n ");
i=0;
}
}

fclose(ptrRd); /* Close the file. */
fclose(ptrWr); /* Close the file. */

printf("\n");
printf("////////////Done Bin To ASCII conversion //////////// \n");

}




main()
{
FILE *fileRdPtr, *fileWrtPtr;

/* Open Binary file for output. */
fileWrtPtr = fopen("Result.txt","w");
fileRdPtr = fopen("BinaryFile2Convert.bin", "rb");

if(fileRdPtr==NULL)
{
printf("Could not find input binary file: BinaryFile2Convert.bin \n");
return 0;
}

printf("Pls make sure binary input file is using file name: 'BinaryFile2Convert.bin'. Output file is: 'Result.txt'\n");


__ConvertBinFile_To_ASCIIFile(fileRdPtr,fileWrtPtr);

return 0;


}

Tuesday, October 6, 2009

java socket comms

/**
* SimpleSocketClient.java
*
* Created on October 2, 2002, 5:34 PM
*/

import java.awt.*;
import java.net.*; //contains socket class
import java.io.*; //The java.io package provides input and output classes that we will use to extract the data from the response

import java.applet.Applet;


/**
*
* @author Stephen Potts
*/
public class AppletSocketClient // extends Applet

{
Socket socket1;
int portNumber = 20000;
String str = "";


ObjectInputStream ois;

InputStream istream;
OutputStream ostream;

byte[] theByteArray;

/** Creates a new instance of AppletSocketClient */
public AppletSocketClient()
{



try
{


// socket1 = new Socket(InetAddress.getLocalHost(), portNumber);

socket1 = new Socket("192.168.0.201", portNumber);

// socket1 = new Socket("192.168.0.201", portNumber,"192.168.0.1", 8000);

System.out.println("--Debug: build socket ");

istream=socket1.getInputStream();

// ois = new ObjectInputStream(istream);

System.out.println("--Debug: build input stream ");

ostream=socket1.getOutputStream();

// ObjectOutputStream oos = new ObjectOutputStream(socket1.getOutputStream());

System.out.println("--Debug: build output stream ");

str = "initialize";

System.out.println("--Debug: about to send string "+str);

theByteArray=str.getBytes();

ostream.write(theByteArray);

// oos.writeObject(str);

// System.out.println("--Debug: out string"+str);;
//
// str = (String) ois.readObject();
//
// System.out.println("--Debug: input string"+str);
//
// oos.writeObject("bye");



// while ((str = (String) ois.readObject()) == null);

// while ((str = (String) ois.readObject()) != null)
// {
// System.out.println(str);
// oos.writeObject("bye");
//
// if (str.equals("bye bye"))
// break;
// }

System.out.println("--Debug:ois close, oos close, socket close");

// ois.close();
// oos.close();
socket1.close();

} catch (Exception e)
{
System.out.println("Exception " + e);
}
}

public void paint(Graphics g)
{
g.drawString("Hello, Applet", 10, 10);
}


public static void main(String args[])
{
System.out.println("--Debug: main start ");

AppletSocketClient lsp = new AppletSocketClient();
}

}



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

/*
* LoopingSocketServer.java
*
* Created on October 2, 2002, 5:24 PM
*/

import java.net.*;
import java.io.*;

/**
*
* @author Stephen Potts
*/
public class AppSocketServer
{
ServerSocket servSocket;
Socket fromClientSocket;
int cTosPortNumber = 20000;
String str;


/** Creates a new instance of LoopingSocketServer */
public AppSocketServer()
{
// Create ServerSocket to listen for connections
try
{
servSocket = new ServerSocket(cTosPortNumber);

// Wait for client to connnect, then get Socket
System.out.println("ServerSocket created");
System.out.println("Waiting for a connection on " + cTosPortNumber);

fromClientSocket = servSocket.accept();
System.out.println("fromClientSocket accepted");

// Use ObjectOutputStream to send String to the client
ObjectOutputStream oos =
new ObjectOutputStream(fromClientSocket.getOutputStream());

//Use ObjectInputStream to get String from client
ObjectInputStream ois =
new ObjectInputStream(fromClientSocket.getInputStream());


while ((str = (String) ois.readObject()) != null)
{
System.out.println("The message from client is *** " + str);

if (str.equals("bye"))
{
oos.writeObject("bye bye");
break;
}
else
{
str = "Server returns " + str;
oos.writeObject(str);
}

}
oos.close();

// Close Sockets
fromClientSocket.close();
} catch (Exception e)
{
System.out.println("Exception " + e);
}
}

public static void main(String args[])
{
AppSocketServer lss = new AppSocketServer();
}


}