显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

NDEB Exam Busters

加拿大面对面及远程考牌辅导

 
 
 
 
 
 

海外 加拿大 狮子座

 发消息  写留言

 
NDEB, NBDE, Part1, Part2, 移民, 考试 资料库 真题 AFK, National Board Dental Exam, Foreign Trained, 下载, Download, 美国 加拿大 行医资格考试
 
近期心愿N/A
人生格言中国交通很行 中国农业很行 中国工商很行 中国建设很行 中国人民很行 中国很行
博客等级加载中...
今日访问加载中...
总访问量加载中...
最后登录加载中...
 
 
 
 
 
 
 

包过

NDEB AFK, ACS, ACJ  是否让您觉得是一座座难以逾越的大山?
请电邮联系
mail to: 
ndebinc@gmail.com 

NDEB AFK one-on-one tutoring (Vancouver)

http://vancouver.craigslist.ca/van/lss/4676875485.html
http://www.kijiji.ca/v-view-details.html?adId=1020184747
http://www.kijiji.ca/v-view-details.html?adId=1020187381
http://vancouver.craigslist.ca/van/lss/4676875485.html





作者  | 2014-9-20 20:50:36 | 阅读(55) |评论(0) | 阅读全文>>



在 "明朝那些事"  里面有一句话是这样的:
南非的一位著名政治家曾经说过:西方人来到我们面前时,手中拿着圣经,我们手中有黄金,后来就变成了,他们手中有黄金,我们手中拿着圣经。

它的原话可能是这样的:

Desmond Tutu:
When the missionaries came to Africa they had the Bible and we had the land. They said "Let us pray." We closed our eyes. When we opened them, we had the Bible and they had the land.

作者  | 2012-10-18 16:57:21 | 阅读(194) |评论(1) | 阅读全文>>

[置顶] 窝洞分类 - G.V.Black Cavity classification 分类

2010-3-13 18:15:18 阅读2887 评论0 132010/03 Mar13

G.V.Black分类

龋洞分类 - G.V.Black Cavity classification 分类 - godsonx - godsonx的博客

 

 

 考题:

哪些洞型可以出现在任何牙上?

 

答案:   Class I, Class V & Class VI   一类, 五类和六类洞

 

 

Cavity classification standardized methods of recording the need for restoration exist to facilitate communication among clinicians, researchers, and dental educators. The most commonly accepted means of classifying cavities is by the names of the surfaces involved. Cavity type is classified further based on the type of treatment and anatomical area involved. This classification, developed by Dr. G. V. Black in 1908, is designated by Roman numerals as Class I, Class II, Class III, Class IV, Class V, and Class VI (this is the only category that has been added to his original classification system). Note: It is important to remember that the classification relates to location and not size of the cavity.

#  Class I cavities -> involve the pits and fissures, while all other classifications involve smooth surfaces
of the teeth.
      #  Class II cavities -> involve the proximal surfaces and occlusal surfaces of premolars and molars.
      #  Class III cavities -> involve the proximal surfaces of incisors and canines that do not involve the
incisal angle.
      #  Class IV cavities -> are located on the proximal surface of incisors and canines and do involve
the incisal angle.
      #  Class V cavities -> are on the facial or lingual surface of ail teeth and do not involve a pit or fissure.
      #  Class VI cavities -> are on the incisal edges of anterior teeth or on the occlusal cusp heights of
posterior teeth.

** Remember: The best method for definitive detection of incipient carious lesions on the interproximal surfaces of posterior teeth (distal surface of canines through molars) is by bite-wing radiographs. 

 

 

 

I 类洞:为发生于所有牙齿的发育窝、沟内的龋损所制备的洞形。包括磨牙[牙合]面窝沟洞,磨牙颊(舌)面的颊(舌)沟洞,前磨牙的[牙合]面窝沟洞,上前牙的腭面窝洞。

II 类洞:为发生于后牙邻面的龋损所制备的洞形。包括前磨牙的邻面洞、邻[牙合]面洞和邻颊(舌)面洞,磨牙的邻[牙合]面洞和邻颊(舌)面洞及邻面洞。

III类洞:为发生于前牙邻面未损及切角的龋损所制备的洞形。包括切牙、尖牙的邻面洞、邻腭(舌)面洞、邻唇面洞。

IV类洞:为发生于前牙邻面并损及切角的龋损所制备的洞形。包括切牙、尖牙的邻唇腭(舌)面洞,目前含义延伸及牙外伤引起切角缺损的洞。

V类洞:为发生与所有牙齿的颊(唇)、舌(腭)面近龈1/3牙面的龋损所制备的洞形。包括前牙、前磨牙、磨牙在颊或舌面的近龈1/3洞。

 

窝洞定义、结构、各部名称、代表符号

(1)窝洞定义:牙齿龋洞去净龋坏组织,经手术制备的具有特定形状的洞。要求填入充填材料后,充填材料及牙齿均能承担正常咀嚼

压力,不折断、不脱落。

(2)窝洞结构:窝洞由洞壁、洞角及洞缘角构成。


    1)洞壁:组成窝洞的内面统称为壁。按其所在牙面部位命名如近中壁、远中壁、颊壁、舌壁、龈壁、髓壁、轴壁等。

    2)洞角:两个洞壁相交构成的角称为线角(Line angles),三个洞壁相交形成的角称为点角(Point angles)。线角及点角的命名

均以构成他们的各洞壁名称联合命名,如颊轴线角、轴髓线角、颊龈轴点角、舌龈轴点角等。

    3)洞缘角(Cavosurface Margin):洞侧壁与牙齿表面的相交线称为洞缘角,也称为洞面角。


(3)窝洞的名称及符号

    1)窝洞的名称:可根据窝洞所在的牙面命名,如牙合面洞、近中洞、近中牙合面洞等;也可以窝洞所包括牙面数命名,如单面

洞、复面洞等。

    2)窝洞的符号:以所在牙面英文名称的第一个字母或前两个字母作为符号,具体如下:

    切端为I(incisive S.)颊侧为B(buccal S.)

    舌侧为L(lingual S.)牙合面为O(occlusal S.)

    唇侧为La(labial S.)近中面为M(medial S.),远中面为D(distal S.)等。


=======================================================================================

Tooth Preparation Walls
---------------------------
Internal Wall. An internal wall is a prepared (cut) surface that does not extend to the external tooth
surface (Fig. 6-10).

Axial Wall. An axial wall is an internal wall parallel
with the long axis of the tooth (see Fig. 6-10).

Pulpal Wall. A pulpal wall is an internal wall that
is perpendicular to the long axis of the tooth and
occlusal of the pulp (see Figs. 6-10 and 6-13 [p]).

External Wall. An external wall is a prepared (cut)
surface that extends to the external tooth surface. Such
a wall takes the name of the tooth surface (or aspect)
that the wall is toward (see Fig. 6-10).

Floor (or Seat). A floor (or seat) is a prepared (cut) wall that is reasonably flat and perpendicular to the
occlusal forces that are directed occlusogingivally (generally parallel to the long axis of the tooth).
Examples are the pulpal and gingival walls (see Fig. 6-10).
Such floors may be purposefully prepared to provide
stabilizing seats for the restoration, distributing the
stresses in the tooth structure, rather than concentrating
them. This preparation increases the resistance form (see
later) of the restored tooth against postrestorative fracture.
More regarding this type of resistance form is
presented in a later section.

Enamel Wall. The enamel wall is that portion of
a prepared external wall consisting of enamel (see
Fig. 6-2D).

Dentinal Wall. The dentinal wall is that portion of
a prepared external wall consisting of dentin, in which
mechanical retention features may be located (see
Fig. 6-2D).


龋洞分类 - G.V.Black Cavity classification 分类 - godsonx - NDEB Board Busters
 
龋洞分类 - G.V.Black Cavity classification 分类 - godsonx - NDEB Board Busters
 
龋洞分类 - G.V.Black Cavity classification 分类 - godsonx - NDEB Board Busters



==================================================================================================



洞形设计
--------------

外形设计

窝洞外形的范围应包括所有病变组织和可疑的点隙裂沟,外形应作预防性扩展,邻面侧壁应扩展到接触点以外的自洁区,龈壁应置于平齐眼乳突边缘健康的牙休组织上。窝洞外形线应为圆缓曲线,以减少应力集中。



抗力形设计
-----------
抗力形是使充填体和余留牙能够承受咬合力而不会破裂的特定形状。Ⅰ、Ⅱ类洞对抗力形要求较高,V类洞要求可稍低。
1、洞形深度:窝洞底必须建立在牙本质上,后牙洞深应达釉牙本质界下0.2---0.5mm,前牙应达釉牙本质界的牙本质面。
2、盒状洞形:窝洞应制备成盒状,即除特殊情况外,要洞底平,侧壁平直与洞底相垂直,各侧壁之间相互平行。洞底各点线角应明确而圆钝,使应力不集中,要力均匀分布。
3、梯阶形成:复面洞的洞底应形成梯阶以均匀分担咬合力,其中龈壁与髓壁平行,轴壁与近、远中侧壁平行,各壁交接呈直角,点、线角圆钝。注意龈壁一定要与轴壁垂直,切勿形成向龈方的斜面。
4、无基釉、脆弱牙体处理:窝洞釉质壁应与釉柱排列方向平行,洞口不能留有无基釉;对脆弱的牙尖牙嵴,应适当降低高度,减轻要力负担。



固位形设计
-----------
固位形是使充填体能保留于洞内,承受更力后不移位、不脱落的特定形状。当充填材料与牙体组织无粘结力时,充填体的固位主要靠密合的摩擦力和一定的机械样合力。
1、侧壁固位:相互平行且具有一定深度的侧壁,可使充填体通过和洞壁的密合摩擦而达固位目的。
2、倒凹固位:单面洞可以在牙尖下制备倒凹增强固位,制备倒凹时要防止伤及髓角,因此洞底深度超过釉牙本质界0.5mm以上,应先垫底再制倒凹,较深的洞可以不制倒凹,使用粘结性强的修复材料时也可不制倒凹。
3、 鸠尾固位:鸠尾固位用于复面洞的固位,它借助鸠尾峡部的锁扣作用,防止充填体水平方向的脱出。鸠尾峡必须有一定的深度和宽度,宽度在后牙一般为颊舌牙尖间距的1/3。位置应在洞底轴髓线角的靠中线侧。鸠尾的宽度必须大于鸠尾峡。
4、 梯形固位:也是复面洞采用的固位形,邻雯面洞的邻面设计为龈方大于雯方的梯形,防止充填体呈垂直方向脱出。梯形的外形应作预防性扩展,梯形深度应达釉牙本质界下0.2一0.5mm。




便利形设计
-------------
在维护外形的基础上,在需要的地方略加修整,便于器械和充填物能够达到窝洞的任何部位。要达此目的,可选用适当器械,对洞形作适当延伸;当洞外形位于不健康牙龈处时,可用分离器或木楔分离牙龈,必要时切除部分牙龈。





-----------------------------------------------------

预备步骤

窝洞预备的基本步骤
1、开扩洞口或寻人口:病变部位较隐蔽的龋洞,应首先开扩洞口或寻人口,使龋洞充分暴露或为手术操作形成通路,便于观察和进行操作。可用裂钻或球钻去除洞缘的无基釉质,依病变范围开扩,或用裂钻从龋洞一侧作沟,以形成手术通路。
2、去除腐质:病变范围较大时,应先去除腐质。可先用挖匙除去洞内食物残渣和大部分腐质,然后用球钻将洞缘周围腐质除尽,最后除尽洞底腐质。洞底近髓腔处的少量软化牙本质的去留,应视实际情况而定。
3、设计并制备洞形:窝洞的洞缘线构成窝洞外形。虽然各类窝洞都有基本的外形要求,但洞形的制备还应兼顾病变破坏的范围。腐质除尽后,应依病变范围设计窝洞外形。窝洞应包括所有的病变部位,其颊(唇)、舌壁应达自洁区。窝洞的形态应符合固位形和抗力形的基本原则。制备过程中不可过多磨除健康的牙体组织。
4、修整洞形、清洗窝洞:完成洞形制备后,应去除洞内牙本质碎屑,仔细检查窝洞各部是否腐质已除尽,抗力形、固位形是否符合要求。不符合要求时应进一步去除腐质、修改洞形至达到要求。最后修整洞缘釉质,使与釉柱排列方向一致,并彻底清洗窝洞,除去所有碎屑。
5、窝洞消毒:窝洞预备后洞内牙本质小管中不可避免地会有少量细菌残留,理想的消毒药物,既可杀灭小管中的细菌,又不致损伤牙髓,对窝洞的消毒无疑有益。但目前所用的消毒药物尚不能达到上述要求。因此,除尽腐质远比消毒窝洞重要。除尽腐质即可除去绝大部分细菌,即使有少量细菌残留,由于充填修复后的环境不利细菌生长,经一定时间后也会逐渐丧失活动能力或死亡。
I类洞的制备
I类洞多为单面洞,但当龋损波及颊、舌侧面时,应制成复面洞。单面洞应底平、壁直,窝洞深度达釉牙本质界处。较深的龋损不必要求窝洞底平整,在去尽腐质后可借助垫底形成平底。复面洞时,颊面或舌面窝洞的龈壁应与牙长轴垂直,其近远中和颊舌宽度均不小于1.5mm。近、远中壁相互平行并垂直于龈壁,轴壁与龈壁垂直。要面鸠尾固位形的洞形要求同单面洞。鸠尾峡的宽度不小于1.5mm,用高速气涡轮牙钻(裂钻)沿颊沟或舌沟向更面中央窝沟或远中窝沟扩展形成鸠尾形。洞底髓壁与轴壁垂直,形成梯阶。
Ⅱ类洞的制备
Ⅱ类洞依病变破坏范围可制备单面洞或复面洞。当病变已累及接触区时,应制备复面洞;若病变未累及接触区,为避免过多磨除健康的牙齿组织,可从邻面制备单面洞;如果从邻面操作极为困难,也可制成复面洞,从更面进行操作。Ⅱ类洞多数情况下需制备成复面洞。
邻面部分制备:用裂钻从舌面边缘蜻处开扩洞口,钻轴与更面垂直,洞口的大小与邻面破坏范围一致。将邻面洞制备成盒状洞形,龈壁与轴壁垂直,宽度不超过2mm。颊舌壁位于自洁区并在要方略靠拢,使龈方颊舌壁间距略大于雯方。
Ⅲ类洞的制备
视病变范围的大小和邻面的存在与否可备成单面洞或复面洞。
1、单面洞的制备:病变范围较小,龋洞的颊、舌壁有一定厚度且同时伴有龋损侧邻牙缺失,可制备单面洞。
1.1 用倒锥钻从邻面去除龋损腐质。
1.2 按单面洞制备方法将窝洞制备成与患牙邻面外形相一致的三角形,洞底与牙面形态一致呈凸形,深度达釉牙本质界即可。
1.3 可在唇轴舌点角处制作倒凹,倒凹位于釉牙本质界下约0.5毫米处的牙本质中。
2、复面洞的制备:若前牙邻面龋损破坏范围大,或龋损侧邻牙存在,无备洞操作空间,须制备复面洞。
2.1 视龋损破坏范围及方向确定从舌侧或唇侧扩大洞口,如唇侧未遭破坏则尽量从舌侧人口。
2.2 用裂钻从舌面边缘峰处开扩洞口,洞口的切龈向宽度应与邻面破坏范围一致。邻面洞形与单面洞相同。
2.3 用裂钻从邻面约lmm深处向舌侧窝扩展形成鸠尾形,裂钻的长轴应与舌面垂直。舌面窝洞的洞形与I类洞相同。鸠尾一般不过中线,其切龈宽度约为2.5mm。切牙的鸠尾应不损伤切嵴、对侧的边缘嵴和舌隆突;由于切牙的唇舌径较小,制作鸠尾固位形时,不可加深窝洞,以免降低牙齿的抗力和意外穿髓。舌面洞底(髓壁)与邻面洞底(轴壁)互相垂直并形成梯阶。
IV类洞的制备
因受银汞合金充填材料性能所限,目前一般不用银汞合金修复IV类洞而改用复合树脂类修复材料。
V类洞的制备
1、用小号倒锥钻从唇、颊侧备洞,钻针应垂直于牙面,深度约达釉牙本质界处的牙本质中。
2、洞外形呈肾形,洞底呈凸面,与牙面平行。
3、龈壁与洞底垂直,可在轴龈线角或轴妥线角处作倒凹以增进固位。

作者  | 2010-3-13 18:15:18 | 阅读(2887) |评论(0) | 阅读全文>>

Engineer's Choice - John Eargle

2015-6-22 14:13:42 阅读21 评论0 222015/06 June22

Engineer's Choice - John Eargle - Delos (1991)
Audiophile, Classical | Exact Audio Copy, log file | FLAC separated 277MB | CD covers & booklet 18MB

An excellent compilation from the Delos catalog. Recording Engineer John Eargle picks his favorite demo tracks. Individual tracks commented in the scanned booklet


John Eargle, one of the most respected and honored recording engineers of our time and a nobble man, passed away. 
May he rest in peace


Track list
1. Symphony No. 10: Scherzo 
2. Gimpel The Fool: 'Jester's Song And Mazel Tov' 
3. Through The Looking Glass: Looking-Glass Insects 
4. Grand Canyon Suite: Sunset 
5. Billy The Kid: Gun Battle 
6. Symphony No.6: Movements III. And IV. 
7. Piano Concerto: Adagio 
8. Wassail Song 
9. Fleurs 
10. Menuetto 
11. Symphony No. 51: Finale (Allegro) 
12. Suite For Skip And Sadie: Good Morning 
13. Piano Trio: Tema con Variazioni 
14. Treestone: Tristopher Tristian 
15. Prelude In G Minor 
16. A Quaker Reader: Movements IV and VIII 
17. Symphony No. 6: Scherzo (Leggerissimo vivace) 
18. The Miraculous Mandarin: The Miraculous Mandarin (excerpts) 
19. Symphony No. 2: Finale (Allegro vigoroso) (Excerpt) 
20. Roman Festivals: Roman Festivals (excerpts) 
21. Nights In The Gardens Of Spain (excerpts) 
22. Daphnis And Chloe: Daphnis and Chloe (excerpt) 

作者  | 2015-6-22 14:13:42 | 阅读(21) |评论(0) | 阅读全文>>

PB条码打印探讨

2015-6-21 8:23:58 阅读24 评论0 212015/06 June21

PB条码打印探讨


在信息系统开发时通常有用户要求能够打印条码,笔者现在就power builder 工具开发的系统初略的介绍一下条码的实现方式及其优缺点。本文主要讨论code39和code128的实现方法。
       code39总共可表示的字符范围:0~9,A~Z以及 +、-、*、/、%、$、.等特殊字符,在加上空格符‘ ’,共计44组编码,条码没有长度限制。但code39码能表示的字符的范围挺小的,而且表示出来的条码也比较长。然而,这种条码这pb中实现起来很简单。
       Code128相对较为复杂,支持的字元也相对较多,又有不同的编码方式可供交互运用。它具有A、B、C三种不同的编码类型,可表示的范围也很广,具体特性大家可以到网上查找相关资料。它能表示高密度数据,条码不会太长。
一、使用条形码字体实现code39、code128
       需要在本机上安装code39或code128字体,需要注意的是由于CODE128码字符串包含不可正常显示的字符,你必须使用支持Unicode码的PB版本,如PB10以上。
       对于code39来说,通常用“*”号作为起始、终止符,校验码不用。如‘6921168509256’的值为:*6921168509256* 。在数据窗口中可以加一列计算列,表示为:'*'+yourcode+'*' ,然后在将计算列的字体选为:3 of 9 Barcode ,设置一下大小就可以了。需要注意的是code39条码一般都会很长,最好不要用它来表示太长的条码。在pb9和pb10中测试没有问题,用激光打印机打出来的条码可以在普通的条码扫描枪上正确识别。
       对于code128来说实现起来没那么容易,Code128编码规则:开始位 + [FNC1(为EAN128码时加)] + 数据位 + 检验位 + 结束位。所以这要求我们先要计算出编码结果,然后用128字体表示出来。笔者在网上找了一个实现code128B版本的转换函数,使用它可以将字符串轻松转换。当然,如果大家有时间可以到网上好好查查code128的编码规则,然后自己写个函数。
附CODE128码在PB中的实现源代码。
/*******************************************************************/
//CODE128条码基础知识
//CODE128有三个版本
//CODE128A: 标准数字和字母, 控制符, 特殊字符
//CODE128B: 标准数字和字母, 小写字母, 特殊字符
//CODE128C: [00]-[99]的数字对集合, 共100个
//本函数采用CODE128B版本
//条码由开始位、数据位、校验位、停止位组成
//计算过程:
//1.取各字符ASC码乘以字符序号之和(以ASC=32为分界点,大于32减32,小于32加64)
//2.计算校验码
//3.组合条码:开始位+数据位+校验位+停止位
int li_asc_total = 104 
int li_asc_tmp,i
char lc_start=char(204)//采用CODE128B版本
char lc_stop=char(206)
int li_check_digit
string ls_check_digit


//1.取各字符ASC码乘以字符序号之和(以ASC=32为分界点,大于32减32,小于32加64)
For i = 1 To len(as_sourcetext)
        li_asc_tmp = Asc(mid(as_sourcetext,i, 1)) 
        If li_asc_tmp >= 32 Then 
                li_asc_total = li_asc_total + (li_asc_tmp - 32) * i 
        Else 
                li_asc_total = li_asc_total + (li_asc_tmp + 64) * i 
        End If 
Next 
//2.计算校验码
li_check_digit = mod(li_asc_total,103)
If li_check_digit >= 95 Then//特殊字符
       li_check_digit = li_check_digit + 100
Else 
        li_check_digit = li_check_digit + 32 
end if
ls_check_digit = char(li_check_digit) 
//3.组合条码:开始位+数据位+校验位+停止位
Return lc_start + as_sourcetext + ls_check_digit  + lc_stop


       先感谢一下函数的作者辛苦劳动。将转换后的字符串以128字体的方式显示即可。最后测试没问题,激光打印机打出来的条码可以在普通的条码扫描枪上正确识别。
二、使用MSBCODE9.OCX实现
       这是微软提供的条码控件,可以表示多种条码字体,具体资料大家可以查阅MSBCODE9.CHM,可以到office安装目录下查找。
  msbcode9.ocx是微软公司OFFICE自带的一个条码控件。不需要条码字体直接就可以打印一些条码,比如CODE128、CODE39等。而且对于开发环境没有太多的限制,至少pb9、pb10都测试通过。
  1、首先你要注册一下msbcode9.ocx控件。regsvr32 msbcode9.ocx
  2、使用ole在PB中把注册的控件增加到窗口中或数据窗口中。
  3、双击控件就会看到一些属性,包括选择条码字体。
  4、不过也可以在程序中用代码来控制。
    dw_1.o b j e c t.ole_1.o b j e c t.style = 7 //7代表CODE128 6代表CODE39
    dw_1.o b j e c t.ole_1.o b j e c t.value = '条码值'


MSBCODE9的帮助文件:MSBCODE9.HLP

目录在:C:\Program Files\Microsoft Office\OFFICE11\2052


       然后就可以打印了,最后测试没问题,激光打印机打出来的条码可以在普通的条码扫描枪上正确识别,而且扫描效果很好,比用字体实现的要好。但存在另一个问题,如果想要打印一批单据,每个单据都带条码的话,用条码字体比较好实现,用控件的话不好实现。可以先把ole对象存在数据库中,最后检索出来,但日后数据库检索的速度会很慢,这是因为存储ole对象的缘故。
三、其他
       还有一些使用图片生成条码的,其实质也是先通过字符串编码转换为条码编码,然后以图片的形式进行显示,感觉倒不如使用控件更直接。对于直接向打印机发送控制命令来实现条码的方式,笔者没有进行测试,希望有兴趣的可以试试。

作者  | 2015-6-21 8:23:58 | 阅读(24) |评论(0) | 阅读全文>>

British diplomat set up by the Russian secret service?

2015-6-21 4:52:42 阅读28 评论0 212015/06 June21

http://www.xvideos.com/video382848/the_adventures_of_mr._hudson_in_rusia
Adventures of Mr Hudson in Russia
http://xhamster.com/movies/172737/the_adventures_of_mr_hudson_in_rusia.html

Was British diplomat set up by the Russian secret service?

Official filmed having sex with prostitutes may have been victim of 'honey trap'

 
 

Friday 10 July 2009

The Foreign Office says it is fed up with "silly jokes" about "from Russia with love". The official line is that there are far too many real problems in places like Iran and Afghanistan to spend time worrying about a junior diplomat being indiscreet in the Urals.

Yesterday, a four-minute video surfaced featuring 37-year-old British diplomat James Hudson, entitled "Adventures of Mr Hudson in Russia". It shows the deputy consul general in Ekaterinburg cavorting with two prostitutes. He has since resigned.

A spokeswoman for the Foreign and Commonwealth Office (FCO) said: "The FCO expects all its staff to demonstrate high levels of personal and professional integrity and takes all allegations of inappropriate behaviour seriously.

"That said, we are not in a position to confirm or deny the allegations in this story, and we do not generally comment or individual members of staff or individual personal matters."

But, her colleagues confirmed that Mr Hudson was indeed the man in the film, seen entering a room – reportedly a brothel – drinking on a sofa, and kissing two blonde women in their underwear. In one scene a female voice asks in broken English: "Would you like it?"

Last weekend, it emerged that the holiday snaps of the next head of MI6, Sir John Sawers, taken by his wife, were freely available for the public to view on Facebook. Thanks to comments by the Foreign Secretary, David Miliband, he is in danger of being known forever as "the spy in Speedos".

But the case of Mr Hudson is a bit more serious. It has been suggested that the diplomat might have been lured into a "honey trap" by the Russian intelligence service FSB, the successor to the KGB, with the aim of embarrassing the British Government.

Mr Hudson joined the FCO in 1994, and his postings had included Sarajevo, Havana and Budapest. He married his wife, Sally, in London in 1996, but they divorced the following year. The couple have one child.

There is no evidence that he worked for any of the UK's intelligence arms, and his rank would not have given him access to many secrets. The consensus in diplomatic and security circles was that the FSB had merely taken advantage of an opportunity which presented itself.

One source told The Independent: "FCO staff are given warnings about the risks involved, and this is what happened when this was ignored. There is a more relaxed approach to using brothels in Russia among certain sections of the business community, but this should not extend to diplomats."

There has been a series of rows between Britain and Russia over spying in recent years. Last week, the British Government accused Russia of being actively engaged in cyber espionage, while security agencies have claimed there is a steady rise in the number of Russian agents active in the UK.

The murder of former FSB officer Alexander Litvinenko continues to provoke controversy, with Russia refusing Britain's request to extradite a suspect, Andrei Lugovoy.

One of the most widely reported allegations of recent years was MI6's use of a fake "rock" left in a Moscow street, acting as a transmitter and sending data to a palmtop computer. The plan was supposedly inspired by a David Attenborough wildlife programme in which a tiny camera was hidden inside artificial elephant dung.

作者  | 2015-6-21 4:52:42 | 阅读(28) |评论(0) | 阅读全文>>

Linear Technology Magazine Circuit Collection

2015-6-19 16:26:59 阅读21 评论0 192015/06 June19

Linear Technology Magazine Circuit Collection
http://cds.linear.com/docs/en/application-note/an52f.pdf
http://cds.linear.com/docs/en/application-note/an66f.pdf
http://cds.linear.com/docs/en/application-note/an67f.pdf

http://cds.linear.com/docs/en/application-note/an84f.pdf



http://cds.linear.com/docs/en/application-note/an87f.pdf



bonus:
http://ww1.microchip.com/downloads/en/DeviceDoc/00924b.pdf

作者  | 2015-6-19 16:26:59 | 阅读(21) |评论(0) | 阅读全文>>

Use the Right Word: Modern Guide to Synonyms and Related Words

2015-6-19 16:13:53 阅读16 评论0 192015/06 June19

S. I. Hayakawa, "Use the Right Word: Modern Guide to Synonyms and Related Words" 
Reader’s Digest | 1982 | ISBN: 0895770253 | 726 pages | CHM | 2,1 MB

Reader's Digest use the right word : modern guide to synonyms and related words, lists of antonyms, copious cross-references, a complete and legible index 


http://www.amazon.com/Use-Right-Word-Synonyms-Related/dp/0895770253

作者  | 2015-6-19 16:13:53 | 阅读(16) |评论(0) | 阅读全文>>

Books Collection on Writing

2015-6-19 16:10:33 阅读20 评论0 192015/06 June19

Calibre Quick Start Guide John Schember 
The 90-Day Novel Alan Watt 
The Supernatural Book of Monsters, Spirits, Demons, and Ghouls Alex Irvine 
How to Write a Damn Good Thriller: A Step-By-Step Guide for Novelists and Screenwriters James N. Frey 
Key: How to Write Damn Good Fiction Using the Power of Myth James N. Frey 
Bullies, Bastards & Bitches: How to Write the Bad Guys of Fiction Jessica Morrell 
Manage Your Day-To-Day: Build Your Routine, Find Your Focus, and Sharpen Your Creative Mind Jocelyn K. Glei, 99u 
Oxford Guide to English Gramma John Eastwood 
Dostoevsky: A Writer in His Time Joseph Frank 
APA Style Guide to Electronic References, Sixth Edition American Psychological Association 
Publication Manual of the American Psychological Association American Psychological Association 
Literary Rogues: A Scandalous History of Wayward Authors Andrew Shaffer 
The Adweek Copywriting Handbook: The Ultimate Guide to Writing Powerful Advertising and Marketing Copy From One of America's Top Copywriters Joseph Sugarman 
Writing Academic English With Criterion(TM) Publisher's Version Alice Oshima 
Bird by Bird: Some Instructions on Writing and Life Anne Lamott 
Elements of Writing Fiction -Plot Ansen Dibell 
Fiction Writer's Workshop Josip Novakovich 
The Oxford Dictionary of Idioms Judith Siefring 
The Artist's Way Julia Cameron 
Writer's Digest Flip Dictionary Barbara Ann Kipfer 
The Handbook of English Linguistics Bas Aarts 
Beyond WikiLeaks: Implications for the Future of Communications, Journalism and Society Benedetta Brevini, Arne Hintz, Patrick McCurdy 
The AMA Handbook of Business Writing: The Ultimate Guide to Style, Grammar, Punctuation, Usage, Construction, and Formatting Kevin Wilson 
Take Control of Scrivener 2 Kirk McElhearn 
Telling Lies for Fun & Profit Lawrence Block, Sue Grafton 
Wired for Story: The Writer's Guide to Using Brain Science to Hook Readers From the Very First Sentence Lisa Cron 
Grant Writing for Dummies Beverly A. Browning 
Bryson's Dictionary of Troublesome Words: A Writer's Guide to Getting It Right Bill Bryson 
The Novel Writer's Toolkit: A Guide to Writing Novels and Getting Published Bob Mayer 
Quick Access Compact (Custom Joliet Junior College Edition) Lynn Quitman Troyka, Douglas Hesse 
Writing From Sources Brenda Spatt 
Daily Rituals: How Artists Work Mason Currey 
Writing Feature Articles Brendan Hennessy 
The Chicago Guide to Writing About Numbers Jane E. Miller 
Principles of Successful Freelancing Miles Burke 
Creative Writer's Workbook, The Cathy Birch 
Elements of Fiction Writing -Beginnings, Middles & Ends Nancy Kress 
Elements of Fiction Writing -Characters & Viewpoint: Proven Advice and Timeless Techniques for Creating Compelling Characters by an Award-Winning Author Orson Scott Card 
Harbrace Essentials Cheryl Glenn, Loretta Gray 
Paperback Oxford English Dictionary Oxford Dictionaries 
Talking About Detective Fiction P. D. James 
The Harbrace Guide to Writing, Concise Edition Cheryl Glenn 
The No Plot? No Problem! Novel-Writing Kit Chris Baty 
Encyclopedia of 19th-and 20th-Century British Writers Christine L. Krueger, George Stade, Karen Karbiener 
The Oxford Book of English Detective Stories Patricia Craig 
How to Write Reports and Proposals Patrick Forsyth 
Reading of Theoretical Texts Peter Ekegren 
The Writer's Journey: Mythic Structure for Writers Christopher Vogler 
The Encyclopedia of the Novel Peter Melville Logan 
Essays and Poems Ralph Waldo Emerson 
A Guide to Writing as an Engineer David F. Beer, David A. McMurrey 
The Describer's Dictionary: A Treasury of Terms & Literary Quotations David Grambs 
The Cambridge Introduction to Creative Writing David Morley 
The College Writer: A Guide to Thinking, Writing, and Researching Randall VanderMey, Patrick Sebranek, Verne Meyer, John van Rys 
Writing Popular Fiction Dean R. Koontz 
The Extreme Searcher's Internet Handbook: A Guide for the Serious Searcher Randolph Hock, Gary Price 
Zen in the Art of Writing Ray Bradbury 
Reference and Research Guide to Mystery and Detective Fiction Richard J. Bleiler 
The St. Martin's Guide to Writing Rise B. Axelrod, Charles R. Cooper 
2012 Writer's Market Robert Lee Brewer 
20 Master Plots and How to Build Them Ronald B Tobias 
Writing for Academic Journals Rowena Murray 
Exercises for a Writer's Reference Large Format Diana Hacker, Nancy Sommers 
The Psychology of Creative Writing Scott Barry Kaufman 
Stein on Writing Sol Stein, Christopher Lane 
Rules for Writers Diana Hacker, Nancy I. Sommers 
Fundamentals of New Testament Greek Stanley E. Porter 
On Writing: A Memoir of the Craft Stephen King 
The Marshall Plan for Novel Writing Evan Marshall 
The Handbook of Creative Writing Steven Earnshaw 
Writing Mysteries Sue Grafton 
Writing Systems of the World Florian Coulmas 
Literary Theory: An Introduction Terry Eagleton 
English Grammar for Today: A New Introduction Geoffrey Leech 
The Theory of the Novel Georg Lukacs 
The Oxford Companion to the English Language Tom McArthur, Thomas McArthur 
Writing a Novel and Getting Published for Dummies George Green, Lizzy Kremer 
The Oxford Essential Guide to Writing Thomas S. Kane 
Lifehacker: 88 Tech Tricks to Turbocharge Your Day Gina Trapani 
Writing Fiction: The Practical Guide From New York's Acclaimed Creative Writing School Alexander Steele, Gotham Writers' Workshop 
On Creative Writing Graeme Harper 
Mugging the Muse: Writing Fiction for Love and Money: Second Edition: New and Updated Holly Lisle 
The 100 Most Influential Writers of All Time J. E. Luebering 
The Writer's Idea Book: How to Develop Great Ideas for Fiction, Nonfiction, Poetry, & Screenplays Jack Heffron 
The Oxford Book of American Detective Stories Rosemary Herbert 
How to Write a Damn Good Novel, 2: Advanced Techniques for Dramatic Storytelling James N. Frey 
Critical Thinking: A Concise Guide Tracy Bowell, Gary Kemp 
How to Write a Damn Good Novel James N. Frey 
Writing Tricia Hedge, Alan Maley 
The Oxford Dictionary of Quotations Elizabeth Knowles 
Story Structure Architect Victoria Lynn Schmidt 
Serial Crime, Second Edition: Theoretical and Practical Issues in Behavioral Profiling Wayne Petherick 
A Jane Austen Education: How Six Novels Taught Me About Love, Friendship, and the Things That Really Matter William Deresiewicz 
On Writing Well: The Classic Guide to Writing Nonfiction William Zinsser 
The Elements of Style by William Strunk William Strunk 
Writing for Journalists Wynford Hicks 
Handbook of Research on Digital Libraries: Design, Development, and Impact Yin-Leng Theng, Schubert Foo, Dion Goh, Jin Cheon Na 
The Anatomy of Story: 22 Steps to Becoming a Master Storyteller John Truby 
From Inquiry to Academic Writing: A Text and Reader Stuart Greene, April Lidinsky 
Art of Plotting: Add Emotion Suspense and Depth to Your Screenplay Linda J. Cowgill 
Story Physics: Harnessing the Underlying Forces of Storytelling Larry Brooks 
Politics and the English Language and Other Essays George Orwell 
Writing Fiction for Dummies Randy Ingermanson, Peter Economy 
Writing: A Manual for the Digital Age, Brief David Blakesley, Jeffrey Laurence Hoogeveen 
Crafting Novels & Short Stories: Everything You Need to Know to Write Great Fiction Editors Of Writer's Digest 
A Writer's Book of Days: A Spirited Companion & Lively Muse for the Writing Life Judith Reeves 
Persecution and the Art of Writing Leo Strauss 
Schaum's Quick Guide to Writing Great Short Stories Margaret Lucke 
Write Good or Die Various 
The Emotion Thesaurus: A Writer's Guide to Character Expression Angela Ackerman, Becca Puglisi 
Plotting and Writing Suspense Fiction Patricia Highsmith 
Writers Workshop of Science Fiction & Fantasy Michael Knost 
How to Write Great Essays Learningexpress Editors 
The Complete Handbook of Novel Writing Editors Of Writers Digest Books 
The Facts on File Dictionary of Allusions Martin H. Manser 
It Was the Best of Sentences, It Was the Worst of Sentences: A Writer's Guide to Crafting Killer Sentences June Casagrande 
Pocket Oxford American Dictionary & Thesaurus Oxford University Press, Usa 
2011 Children's Writer's and Illustrator's Market Alice Pope 
Time and Narrative, Volume 1 Paul Ricoeur 
MLA Handbook for Writers of Research Papers Joseph Gibaldi, Modern Language Association Of America 
Writer's Reference (Instructor's Edition) Diana Hacker, Nancy Sommers 
Simon & Schuster Handbook for Writers Lynn Quitman Troyka, Douglas Dean Hesse 
The Chicago Manual of Style, 16th Edition University Of Chicago Press Staff 
A Practical Guide to Graphics Reporting: Information Graphics for Print, Web & Broadcast Jennifer George-Palilonis 
Scientific Writing = Thinking in Words David Lindsay 
On the Commerce of Thinking: Of Books and Bookstores Jean-Luc Nancy, David Wills 
Rules of Thumb: A Guide for Writers: 7th (Seventh) Edition Elaine Hughes, Diana Roberts Wienbroer Jay Silverman 
Dictionary of Problem Words and Expression Harry Shaw 
Content Rules: How to Create Killer Blogs, Podcasts, Videos, Ebooks, Webinars (And More) That Engage Customers and Ignite Your Business Ann Handley, C. C. Chapman 
The Dramatic Writer's Companion: Tools to Develop Characters, Cause Scenes, and Build Stories Will Dunne 
Narrative in Fiction and Film: An Introduction Jakob Lothe 
How to Be a Writer: Secrets From the Inside Stewart Ferris 
Writing Fiction: An Introduction to the Craft Garry Disher 
Journalism, Ethics and Society David Berry 
Writing FAST: How to Write Anything With Lightning Speed Jeff Bollow 
In a Word: 750 Words and Their Fascinating Stories and Origins Rosalie Baker, Tom Lopes 
The New American Webster Handy College Dictionary Albert H. Morehead, Loy Morehead, Philip D. Morehead 
The Fable of the Southern Writer Lewis P. Simpson 
Writers on Writing Robert Pack, Jay Parini 
Internet Guide for Writers, The Malcolm Chilsholm 
Ancient Gonzo Wisdom: Interviews With Hunter S. Thompson Anita Thompson 
Careers in Publishing Blythe Camenson 
Grant Application Writer's Handbook Liane Reif-Lehrer 
Encyclopedia of Beat Literature Kurt Hemmer 
The Facts on File Companion to the World Novel: 1900 to the Present, 2-Volume Set Michael D. Sollars 
Careers for Writers & Others Who Have a Way With Words Robert Bly 
Writing for Scholarly Publication: Behind the Scenes in Language Education Christine Pearson Casanave, Stephanie Vandrick 
Writing Groups Inside and Outside the Classroom Edited By Beverly J. Moss 
Resources for Writers: An Annotated Bibliography R. Baird Shuman 
Researching for Writers: How to Gather Material for Articles, Novels and Non-Fiction Books Marion Field 
Creative Writing: How to Develop Successful Writing Skills for Fiction and Non-Fiction Publication Adele Ramet 
Writing Features & Interviews: 2nd Edition Christine Hall 
Academic Writing and Publishing: A Practical Handbook James Hartley 
Talking With Texas Writers: Twelve Interviews Patrick Bennett 
On the Art of Writing Copy Herschell Gordon Lewis 
Classic Mystery Writers Harold Bloom 
Modern Crime and Suspense Writers Harold Bloom 
Landmark Essays on Basic Writing Kay Halasek, Nels P. Highberg 
Scientific Writing 2.0: A Reader and Writer'S Guide Lebrun Jean-Luc 
Linguistics for Writers Colleen Donnelly 
The Irish Writer and the World Declan Kiberd 
Careers in Writing Blythe Camenson 
The Writer's Legal Guide: An Authors Guild Desk Reference Tad Crawford, Kay Murray 
Technical Writing Julie M. Zeleznik, Philippa Jane Benson, Rebecca E. Burnett 
Professional Feature Writing Bruce Garrison 
Classic Crime and Suspense Writers Harold Bloom 
Kurt Vonnegut: A Critical Companion Thomas Marvin, Thomas F. Marvin 
Southern Writers and Their Worlds Susan A. Eacker, Anne Goodwyn Jones, Bertram Wyatt-Brown, 
Writing Research: Transforming Data Into Text, 1e (Clare, Writing Research) Judith Clare Rn Ba Ma(hons) Phd Frcna, Helen Hamilton Rn Ba 
Modern Mystery Writers Harold Bloom 
The Bedford Introduction to Literature: Reading, Thinking, Writing Michael Meyer 
The Fiction Writer's Toolkit Bob Mayer 
Writing Well: The Essential Guide Mark Tredinnick 
$30 Writing School Michael W. Dean 
Revision & Self-Editing: Techniques for Transforming Your First Draft Into a Finished Novel James Scott Bell 
Concise Oxford English Dictionary Catherine Soanes, Angus Stevenson 
The Concise Oxford Dictionary of Literary Terms Chris Baldick 
The Concise Oxford Companion to English Literature Dinah Birch, Katy Hooper 
Dictionary of the Bible John L. Mckenzie 
A Dictionary of World History Edmund Wright, Jonathan Law 
The Oxford Dictionary of English Grammar Sylvia Chalker, Edmund Weiner 
The Oxford Dictionary of Idioms Jennifer Speake 
The Oxford Dictionary of Philosophy Simon Blackburn 
The Oxford Dictionary of Twentieth-Century Quotations Elizabeth Knowles 
Oxford Paperback Thesaurus Maurice Waite 
Self-Editing for Fiction Writers Renni Browne, Dave King, George Booth 
I Never Knew There Was a Word for It Adam Jacot de Boinod 
Interviewing for Journalists Sally Adams, Wynford Hicks 
The Artful Edit: On the Practice of Editing Yourself Susan Bell 
On Writing: 10th Anniversary Edition: A Memoir of the Craft Stephen King 
The Best American Crime Reporting 2009 Jeffrey Toobin, Otto Penzler, Thomas H. Cook 
The Best American Crime Writing 2006 Mark Bowden, Otto Penzler, Thomas H. Cook 
The Best American Crime Writing: 2003 Edition: The Year's Best True Crime Reporting Otto Penzler, Thomas H. Cook 
The Call to Write John Trimbur 
The Plot Whisperer: Secrets of Story Structure Any Writer Can Master Martha Alderson 
Keys for Writers Ann Raimes, Susan K. Miller-Cochran 
The Imaginative Argument: A Practical Manifesto for Writers Frank L. Cioffi 
The 101 Habits of Highly Successful Screenwriters: Insider's Secrets From Hollywood's Top Writers Karl Iglesias 
The Big Sleep & Farewell, My Lovely: AND Farewell My Lovely Raymond Chandler 
Why We Read Fiction: Theory of Mind and the Novel Lisa Zunshine

作者  | 2015-6-19 16:10:33 | 阅读(20) |评论(0) | 阅读全文>>

套接 SOCKET原理

2015-6-8 1:21:29 阅读45 评论0 82015/06 June8

套接 SOCKET原理

类比
Socket非常类似于电话插座。以一个国家级电话网为例,电话的通话双方相当于相互通信的2个进程,区号是它的网络地址;区内一个单位的交换机相当于一台主机,主机分配给每个用户的局内号码相当于Socket号。任何用户在通话之前,首先要占有一部电话机,相当于申请一个Socket;同时要知道对方的号码,相当于对方有一个固定的Socket。然后向对方拨号呼叫,相当于发出连接请求(假如对方不在同一区内,还要拨对方区号,相当于给出网络地址)。假如对方在场并空闲(相当于通信的另一主机开机且可以接受连接请求),拿起电话话筒,双方就可以正式通话,相当于连接成功。双方通话的过程,是一方向电话机发出信号和对方从电话机接收信号的过程,相当于向Socket发送数据和从socket接收数据。通话结束后,一方挂起电话机相当于关闭Socket,撤消连接。
在电话系统中,一般用户只能感受到本地电话机和对方电话号码的存在,建立通话的过程,话音传输的过程以及整个电话系统的技术细节对他都是透明的,这也与Socket机制非常相似。Socket利用网间网通信设施实现进程通信,但它对通信设施的细节毫不关心,只要通信设施能提供足够的通信能力,它就满足了。
至此,我们对Socket进行了直观的描述。抽象出来,Socket实质上提供了进程通信的端点。进程通信之前,双方首先必须各自创建一个端点,否则是没有办法建立联系并相互通信的。正如打电话之前,双方必须各自拥有一台电话机一样。
在网间网内部,每一个Socket用一个半相关描述:(协议,本地地址,本地端口)。
一个完整的Socket有一个本地唯一的Socket号,由操作系统分配。
最重要的是,Socket是面向客户/服务器模型而设计的,针对客户和服务器程序提供不同的Socket系统调用。客户随机申请一个Socket(相当于一个想打电话的人可以在任何一台入网电话上拨号呼叫),系统为之分配一个Socket号;服务器拥有全局公认的Socket,任何客户都可以向它发出连接请求和信息请求(相当于一个被呼叫的电话拥有一个呼叫方知道的电话号码)。
Socket利用客户/服务器模式巧妙地解决了进程之间建立通信连接的问题。服务器Socket半相关为全局所公认非常重要。读者不妨考虑一下,两个完全随机的用户进程之间如何建立通信?假如通信双方没有任何一方的Socket固定,就好比打电话的双方彼此不知道对方的电话号码,要通话是不可能的。

3连接过程根据连接启动的方式以及本地套接字要连接的目标,套接字之间的连接过程可以分为三个步骤:服务器监听,客户端请求,连接确认。

(1)服务器监听:是服务器端套接字并不定位具体的客户端套接字,而是处于等待连接的状态,实时监控网络状态。
(2)客户端请求:是指由客户端的套接字提出连接请求,要连接的目标是服务器端的套接字。为此,客户端的套接字必须首先描述它要连接的服务器的套接字,指出服务器端套接字的地址和端口号,然后就向服务器端套接字提出连接请求。
(3)连接确认:是指当服务器端套接字监听到或者说接收到客户端套接字的连接请求,它就响应客户端套接字的请求,建立一个新的线程,把服务器端套接字的描述发给客户端,一旦客户端确认了此描述,连接就建立好了。而服务器端套接字继续处于监听状态,继续接收其他客户端套接字的连接请求。
============================================================================================

   (1)套接字(socket)概念:
套接字(socket)是通信的基石,是支持TCP/IP协议的网络通信的基本操作单元。它是网络通信过程中端点的抽象表示,包含进行网络通信必须的五种信息:连接使用的协议,本地主机的IP地址,本地进程的协议端口,远地主机的IP地址,远地进程的协议端口。
应用层通过传输层进行数据通信时,TCP会遇到同时为多个应用程序进程提供并发服务的问题。多个TCP连接或多个应用程序进程可能需要通过同一个 TCP协议端口传输数据。为了区别不同的应用程序进程和连接,许多计算机操作系统为应用程序与TCP/IP协议交互提供了套接字(Socket)接口。应用层可以和传输层通过Socket接口,区分来自不同应用程序进程或网络连接的通信,实现数据传输的并发服务。

(2)建立socket连接:
建立Socket连接至少需要一对套接字,其中一个运行于客户端,称为ClientSocket ,另一个运行于服务器端,称为ServerSocket 。
套接字之间的连接过程分为三个步骤:服务器监听,客户端请求,连接确认。
服务器监听:服务器端套接字并不定位具体的客户端套接字,而是处于等待连接的状态,实时监控网络状态,等待客户端的连接请求 
客户端请求:指客户端的套接字提出连接请求,要连接的目标是服务器端的套接字。为此,客户端的套接字必须首先描述它要连接的服务器的套接字,指出服务器端套接字的地址和端口号,然后就向服务器端套接字提出连接请求。
连接确认:当服务器端套接字监听到或者说接收到客户端套接字的连接请求时,就响应客户端套接字的请求,建立一个新的线程,把服务器端套接字的描述发给客户端,一旦客户端确认了此描述,双方就正式建立连接。而服务器端套接字继续处于监听状态,继续接收其他客户端套接字的连接请求。

(3)SOCKET连接与TCP连接
创建Socket连接时,可以指定使用的传输层协议,Socket可以支持不同的传输层协议(TCP或UDP),当使用TCP协议进行连接时,该Socket连接就是一个TCP连接。



Berkeley套接字接口,一个应用程序接口(API),使用一个Internet套接字的概念,使主机间或者一台计算机上的进程间可以通讯。 它可以在很多不同的输入/输出设备和驱动之上运行,尽管这有赖于操作系统的具体实现。 接口实现用于TCP/IP协议,因此它是维持Internet的基本技术之一。 它是由加利福尼亚的伯克利大学开发,最初用于Unix系统。 如今,所有的现代操作系统都有一些源于Berkeley套接字接口的实现,它已成为连接Internet的标准接口。

套接字接口的接入有三个不同的级别,最基础的也是最有效的就是raw socket级别接入。 很少的应用程序需要在外向通讯控制的这个级别接入,所以raw socket级别是只为了用于开发计算机Internet相关技术的。 最近几年,大多数的操作系统已经实现了对它的全方位支持,包括Windows XP。

使用Berkeley套接字的系统[编辑]

由于Berkeley套接字是第一个socket,大多数程序员很熟悉它们,所以大量系统把伯克利套接字作为其主要的网络API。一个不完整的列表如下:

  • Windows Sockets (Winsock) ,和Berkeley Sockets很相似,最初是为了便于移植Unix程序。
  • Java Sockets
  • Python sockets
  • Perl sockets

头文件[编辑]

Berkeley套接字接口的定义在几个头文件中。这些文件的名字和内容与具体的实现之间有些许的不同。 大体上包括:

<sys/socket.h>
核心BSD套接字核心函数和数据结构。
AF_INET、AF_INET6 地址集和它们相应的协议集PF_INET、PF_INET6. 广泛用于Internet,这些包括了IP地址和TCP、UDP端口号。
<netinet/in.h>
AF_INET 和AF_INET6 地址家族和他们对应的协议家族 PF_INET 和 PF_INET6。在互联网编程中广泛使用,包括IP地址以及TCP和UDP端口号。
<sys/un.h>
PF_UNIX/PF_LOCAL 地址集。用于运行在一台计算机上的程序间的本地通信,不用于网络通讯。
<arpa/inet.h>
处理数值型IP地址的函数。
<netdb.h>
将协议名和主机名翻译为数值地址的函数。搜索本地数据以及DNS。

套接字API函数[编辑]

这个列表是一个Berkeley套接字API库提供的函数或者方法的概要:

  • socket() 创建一个新的确定类型的套接字,类型用一个整型数值标识(文件描述符),并为它分配系统资源。
  • bind() 一般用于服务器端,将一个套接字与一个套接字地址结构相关联,比如,一个指定的本地端口和IP地址。
  • listen() 用于服务器端,使一个绑定的TCP套接字进入监听状态。
  • connect() 用于客户端,为一个套接字分配一个自由的本地端口号。 如果是TCP套接字的话,它会试图获得一个新的TCP连接。
  • accept() 用于服务器端。 它接受一个从远端客户端发出的创建一个新的TCP连接的接入请求,创建一个新的套接字,与该连接相应的套接字地址相关联。
  • send()recv(),或者write()read(),或者recvfrom()sendto(), 用于往/从远程套接字发送和接受数据。
  • close() 用于系统释放分配给一个套接字的资源。 如果是TCP,连接会被中断。
  • gethostbyname()gethostbyaddr() 用于解析主机名和地址。
  • select() 用于修整有如下情况的套接字列表: 准备读,准备写或者是有错误。
  • poll() 用于检查套接字的状态。 套接字可以被测试,看是否可以写入、读取或是有错误。
  • getsockopt() 用于查询指定的套接字一个特定的套接字选项的当前值。
  • setsockopt() 用于为指定的套接字设定一个特定的套接字选项。

更多的细节如下给出。

socket()[编辑]

socket() 为通讯创建一个端点,为套接字返回一个文件描述符。 socket() 有三个参数:

  • domain 为创建的套接字指定协议集。 例如:
    • AF_INET 表示IPv4网络协议
    • AF_INET6 表示IPv6
    • AF_UNIX 表示本地套接字(使用一个文件)
  • type 如下:
    • SOCK_STREAM (可靠的面向流服务或流套接字
    • SOCK_DGRAM (数据报文服务或者数据报文套接字
    • SOCK_SEQPACKET (可靠的连续数据包服务)
    • SOCK_RAW (在网络层之上的原始协议)
  • protocol 指定实际使用的传输协议。 最常见的就是IPPROTO_TCPIPPROTO_SCTPIPPROTO_UDPIPPROTO_DCCP。这些协议都在<netinet/in.h>中有详细说明。 如果该项为“0”的话,即根据选定的domain和type选择使用缺省协议。

如果发生错误,函数返回值为-1。 否则,函数会返回一个代表新分配的描述符的整数。

原型:
int socket(int domain, int type, int protocol); 

bind()[编辑]

bind() 为一个套接字分配地址。当使用socket()创建套接字后,只赋予其所使用的协议,并未分配地址。在接受其它主机的连接前,必须先调用bind()为套接字分配一个地址。bind()有三个参数:

  • sockfd, 表示使用bind函数的套接字描述符
  • my_addr, 指向sockaddr结构(用于表示所分配地址)的指针
  • addrlen, 用socklen_t字段指定了sockaddr结构的长度

如果发生错误,函数返回值为-1,否则为0。

原型
int bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen); 

listen()[编辑]

当socket和一个地址绑定之后,listen()函数会开始监听可能的连接请求。然而,这只能在有可靠数据流保证的时候使用,例如:数据类型(SOCK_STREAMSOCK_SEQPACKET)。

listen()函数需要两个参数:

  • sockfd, 一个socket的描述符.
  • backlog, 一个决定监听队列大小的整数,当有一个连接请求到来,就会进入此监听队列;当一个连接请求被accept()接受,则从监听队列中移出;当队列满后,新的连接请求会返回错误。

一旦连接被接受,返回0表示成功,错误返回-1。

原型:

int listen(int sockfd, int backlog); 

accept()[编辑]

当应用程序监听来自其他主机的面对数据流的连接时,通过事件(比如Unix select()系统调用)通知它。必须用 accept()函数初始化连接。 Accept() 为每个连接创立新的套接字并从监听队列中移除这个连接。它使用如下参数:

  • sockfd,监听的套接字描述符
  • cliaddr, 指向sockaddr 结构体的指针,客户机地址信息。
  • addrlen,指向 socklen_t的指针,确定客户机地址结构体的大小 。

返回新的套接字描述符,出错返回-1。进一步的通信必须通过这个套接字。

Datagram 套接字不要求用accept()处理,因为接收方可能用监听套接字立即处理这个请求。

函数原型:
int accept(int sockfd, struct sockaddr *cliaddr, socklen_t *addrlen); 

connect()[编辑]

connect()系统调用为一个套接字设置连接,参数有文件描述符和主机地址。

某些类型的套接字是无连接的,大多数是UDP协议。对于这些套接字,连接时这样的:默认发送和接收数据的主机由给定的地址确定,可以使用 send()和 recv()。 返回-1表示出错,0表示成功。

函数原型:
int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen); 

gethostbyname() 和 gethostbyaddr()[编辑]

gethostbyname() 和 gethostbyaddr()函数是用来解析主机名和地址的。可能会使用DNS服务或者本地主机上的其他解析机制(例如查询/etc/hosts)。返回一个指向 struct hostent的指针,这个结构体描述一个IP主机。函数使用如下参数:

  • name 指定主机名。例如 www.wikipedia.org
  • addr 指向 struct in_addr的指针,包含主机的地址。
  • len 给出 addr的长度,以字节为单位。
  • type 指定地址族类型 (比如 AF_INET)。

出错返回NULL指针,可以通过检查 h_errno 来确定是临时错误还是未知主机。正确则返回一个有效的struct hostent *

这些函数并不是伯克利套接字严格的组成部分。这些函数可能是过时了,新函数是 getaddrinfo() and getnameinfo(), 这些新函数是基于addrinfo数据结构。

函数原型:
struct hostent *gethostbyname(const char *name); struct hostent *gethostbyaddr(const void *addr, int len, int type); 

协议和地址[编辑]

套接字API是Unix网络的通用接口,允许使用各种网络协议和地址。

下面列出了一些例子,在现在的 Linux 和 BSD 中一般都已经实现了。

PF_LOCAL, PF_UNIX, PF_FILE Local to host (pipes and file-domain) PF_INET IP protocol family PF_AX25 Amateur Radio AX.25 PF_IPX Novell Internet Protocol PF_APPLETALK Appletalk DDP PF_NETROM Amateur radio NetROM PF_BRIDGE Multiprotocol bridge PF_ATMPVC ATM PVCs PF_X25 Reserved for X.25 project PF_INET6 IP version 6 PF_ROSE Amateur Radio X.25 PLP PF_DECnet Reserved for DECnet project PF_NETBEUI Reserved for 802.2LLC project PF_SECURITY Security callback pseudo AF PF_KEY PF_KEY key management API PF_NETLINK, PF_ROUTE routing API PF_PACKET Packet family PF_ASH Ash PF_ECONET Acorn Econet PF_ATMSVC ATM SVCs PF_SNA Linux SNA Project PF_IRDA IRDA sockets PF_PPPOX PPPoX sockets PF_WANPIPE Wanpipe API sockets PF_BLUETOOTH Bluetooth sockets 

使用TCP的服务器客户机举例[编辑]

服务器[编辑]

设置一个简单的TCP服务器涉及下列步骤:

  • 调用socket函数建立套接字,应当使用的参数参见例程。
  • 调用bind函数把套接字绑定到一个监听端口上。注意bind函数需要接受一个sockaddr_in结构体作为参数,因此在调用bind函数之前, 程序要先声明一个 sockaddr_in结构体,用memset函数将其清零,然后将其中的sin_family设置为AF_INET,接下来,程序需要设置其sin_port成员变量,即监听端口。需要说明的是,sin_port中的端口号需要以网络字节序存储,因此需要调用htons函数对端口号进行转换(函数名是"host to network short"的缩写)。
  • 调用listen函数,使该套接字成为一个处在监听状态的套接字。
  • 接下来,服务器可以通过accept函数接受客户端的连接请求。若没有收到连接请求,accept函数将不会返回并阻塞程序的执行。接收到连接请求后,accept函数会为该连接返回一个套接字描述符。accept函数可以被多次调用来接受不同客户端的连接请求,而且之前的连接仍处于监听状态——直到其被关闭为止。
  • 现在,服务器可以通过对send,recv或者对write,read等函数的调用来同客户端进行通信。
  • 对于一个不再需要的套接字,可以使用close函数关闭它。 Note that if there were any calls tofork(), each process must close the sockets it knew about (the kernel keeps track of how many processes have a descriptor open), and two processes should not use the same socket at once.
 /* Server code in C */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(void) { struct sockaddr_in stSockAddr; int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(-1 == SocketFD) { perror("can not create socket"); exit(EXIT_FAILURE); } memset(&stSockAddr, 0, sizeof(struct sockaddr_in)); stSockAddr.sin_family = AF_INET; stSockAddr.sin_port = htons(1100); stSockAddr.sin_addr.s_addr = INADDR_ANY; if(-1 == bind(SocketFD,(const struct sockaddr *)&stSockAddr, sizeof(struct sockaddr_in))) { perror("error bind failed"); close(SocketFD); exit(EXIT_FAILURE); } if(-1 == listen(SocketFD, 10)) { perror("error listen failed"); close(SocketFD); exit(EXIT_FAILURE); } for(;;) { int ConnectFD = accept(SocketFD, NULL, NULL); if(0 > ConnectFD) { perror("error accept failed"); close(SocketFD); exit(EXIT_FAILURE); } /* perform read write operations ... */ shutdown(ConnectFD, SHUT_RDWR); close(ConnectFD); } close(SocketFD); return 0; } 

客户机[编辑]

建立一个客户机连接涉及以下步骤:

  • 调用 socket()建立套接字。
  • connect()连接到服务器,类似服务器端的操作,将一个sin_family设为AF_INET,sin_port设为服务器的监听端口(依然要以网络字节序),sin_addr设为服务器IP地址的(还是要用网络字节序)的sockaddr_in作为参数传入。
  • send() 和 recv() 或者 write() 和 read()进行通信。
  • close()终止连接。如果调用fork(), 每个进程都要用close()
 /* Client code in C */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(void) { struct sockaddr_in stSockAddr; int Res; int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (-1 == SocketFD) { perror("cannot create socket"); exit(EXIT_FAILURE); } memset(&stSockAddr, 0, sizeof(struct sockaddr_in)); stSockAddr.sin_family = AF_INET; stSockAddr.sin_port = htons(1100); Res = inet_pton(AF_INET, "192.168.1.3", &stSockAddr.sin_addr); if (0 > Res) { perror("error: first parameter is not a valid address family"); close(SocketFD); exit(EXIT_FAILURE); } else if (0 == Res) { perror("char string (second parameter does not contain valid ipaddress"); close(SocketFD); exit(EXIT_FAILURE); } if (-1 == connect(SocketFD, (const struct sockaddr *)&stSockAddr, sizeof(struct sockaddr_in))) { perror("connect failed"); close(SocketFD); exit(EXIT_FAILURE); } /* perform read write operations ... */ shutdown(SocketFD, SHUT_RDWR); close(SocketFD); return 0; } 

使用UDP的服务器客户机举例[编辑]

用户数据报协议(UDP)是一个不保证正确传输的无连接协议。 UDP数据包可能会乱序到达,多次到达或者直接丢失。但是设计的负载比TCP小。

UDP地址空间,也即是UDP端口,和TCP端口是没有关系的。

服务器[编辑]

Code may set up a UDP server on port 7654 as follows:

#include <stdio.h> #include <errno.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <unistd.h> /* for close() for socket */  #include <stdlib.h> int main(void) { int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); struct sockaddr_in sa; char buffer[1024]; ssize_t recsize; socklen_t fromlen; memset(&sa, 0, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_addr.s_addr = INADDR_ANY; sa.sin_port = htons(7654); if (-1 == bind(sock,(struct sockaddr *)&sa, sizeof(struct sockaddr))) { perror("error bind failed"); close(sock); exit(EXIT_FAILURE); } for (;;) { printf ("recv test....\n"); recsize = recvfrom(sock, (void *)buffer, 1024, 0, (struct sockaddr *)&sa, &fromlen); if (recsize < 0) fprintf(stderr, "%s\n", strerror(errno)); printf("recsize: %d\n ",recsize); sleep(1); printf("datagram: %s\n",buffer); } } 

上面的无限循环用recvfrom()接收给UDP端口7654的数据包。使用如下参数:

  • 指向缓存数据指针
  • 缓存大小
  • 标志
  • 地址
  • 地址结构体大小

客户机[编辑]

用UDP数据包发送一个"Hello World!" 给地址127.0.0.1(回环地址),端口 7654 。


#include <stdlib.h> #include <stdio.h> #include <errno.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <unistd.h> /* for close() for socket */ int main(int argc, char *argv[]) { int sock; struct sockaddr_in sa; int bytes_sent, buffer_length; char buffer[200]; buffer_length = snprintf(buffer, sizeof(buffer), "Hello World!"); sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); if (-1 == sock) /* if socket failed to initialize, exit */ { printf("Error Creating Socket"); exit(EXIT_FAILURE); } memset(&sa, 0, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_addr.s_addr = htonl(0x7F000001); sa.sin_port = htons(7654); bytes_sent = sendto(sock, buffer, buffer_length, 0,(struct sockaddr*)&sa, sizeof (struct sockaddr_in)); if (bytes_sent < 0) printf("Error sending packet: %s\n", strerror(errno)); close(sock); /* close the socket */ return 0; } 

buffer指定要发送数据的指针, buffer_length指定缓存内容的大小。

参见[编辑]

参考资料[编辑]

  1. ^ http://www.ruby-doc.org/core/classes/Socket.html

作者  | 2015-6-8 1:21:29 | 阅读(45) |评论(0) | 阅读全文>>

问号冒号操作符是什么意思? ?: Operator (C# Reference)

2015-6-7 10:23:11 阅读25 评论0 72015/06 June7

The conditional operator (?:) returns one of two values depending on the value of a Boolean expression. Following is the syntax for the conditional operator.

https://msdn.microsoft.com/en-us/library/ty67wk28.aspx
condition ? first_expression : second_expression;

Remarks

The condition must evaluate to true or false

If condition is truefirst_expression is evaluated and becomes the result. 

If condition is false,second_expression is evaluated and becomes the result. 

Only one of the two expressions is evaluated.

Either the type of first_expression and second_expression must be the same, or an implicit conversion must exist from one type to the other.

You can express calculations that might otherwise require an if-else construction more concisely by using the conditional operator. For example, the following code uses first an if statement and then a conditional operator to classify an integer as positive or negative.


class ConditionalOp { static double sinc(double x) { return x != 0.0 ? Math.Sin(x) / x : 1.0; } static void Main() { Console.WriteLine(sinc(0.2)); Console.WriteLine(sinc(0.1)); Console.WriteLine(sinc(0.0)); } } /* Output: 0.993346653975306 0.998334166468282 1 */

https://msdn.microsoft.com/en-us/library/ty67wk28.aspx

作者  | 2015-6-7 10:23:11 | 阅读(25) |评论(0) | 阅读全文>>

c# 错误提示: A new expression requires () or [] after type

2015-6-5 14:10:54 阅读25 评论0 52015/06 June5


very simple.
you forgot to add "()"  to the end.

e.g.

 DEMO32_ myDUT = new DEMO32_();   // ok

if you forget to add "()"  to the end:

DEMO32_ myDUT = new DEMO32_;   //  not good

then "A new expression requires () or [] "  will prompt you.......to add "()"  to the end.

作者  | 2015-6-5 14:10:54 | 阅读(25) |评论(0) | 阅读全文>>

uSize ---->>use this : Marshal.SizeOf(typeof(WAVEHDR))

2015-6-4 13:37:44 阅读83 评论0 42015/06 June4

C# Signature:

[DllImport("winmm.dll", SetLastError = true, CharSet = CharSet.Auto)]

public static extern uint waveOutPrepareHeader(IntPtr hWaveOut, ref WAVEHDR lpWaveOutHdr, int uSize);


http://www.pinvoke.net/default.aspx/winmm.waveoutprepareheader

ref:

https://msdn.microsoft.com/en-us/library/aa446573.aspx

https://msdn.microsoft.com/en-us/library/aa446573.aspx

https://msdn.microsoft.com/en-us/library/ms173187.aspx



Tips & Tricks:

The same WAVEHDR structure used with waveOutPrepareHeader() is also used with

the waveOutWrite() and waveOutUnPrepareHeader() functions. The latter is called

after the audio playback has been stopped with a call to waveOutReset(); The

audio driver will asynchronously set the WHDR_DONE bit in WAVEHDR.dwflags when

it has released the audio data block.

This means that the WAVEHDR struct passed to the waveOutWrite() function must be

allocated in unmanaged memory so it will survive after the call to waveOutWrite().

What I do is preallocate a block of unmanaged memory in my class's Open() method:

    waveHdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(waveHdr));

Then in the output method I use this:

    waveHdr.lpData = wavedata;  // audio buffer
    waveHdr.dwBufferLength = wf.nSamplesPerSec * wf.nBlockAlign;  // it's size
    waveHdr.dwFlags = 0;    // clear before waveOutPrepareHeader()

    Marshal.StructureToPtr(waveHdr, waveHdrPtr, true);    // copy to unmanaged memory

    if ((MMRESULT = waveOutPrepareHeader(waveDevice, waveHdrPtr, Marshal.SizeOf(waveHdr))) != MMSYSERR_NOERROR)
    {
       waveOutGetErrorText(MMRESULT, errmsg, MAXERRORLENGTH);

       MessageBox.Show(
       "waveOutPrepareHeader(): " + errmsg.ToString(),
        this.Text,
        MessageBoxButtons.OK,
        MessageBoxIcon.Error);

        return;
    }

    WAVEHDR wh = (WAVEHDR)Marshal.PtrToStructure(waveHdrPtr, typeof(WAVEHDR));  // copy struct back from unmanaged memory

    waveHdr = wh;  // reset managed struct

    waveHdr.dwFlags |= (WHDR_BEGINLOOP | WHDR_ENDLOOP);  // add the looping flag bits
    waveHdr.dwLoops = MINUS_ONE; ;

    Marshal.StructureToPtr(waveHdr, waveHdrPtr, true);   // and update the unmanaged struct.

Now we are ready to write:

    if ((MMRESULT = waveOutWrite(waveDevice, waveHdrPtr, Marshal.SizeOf(waveHdr))) != MMSYSERR_NOERROR)
        [snipped]

When we are done listening to this playback:

    while ((waveHdr.dwFlags & WHDR_DONE) == 0)  // wait for it
    {
       if ((MMRESULT = waveOutReset(waveDevice)) != MMSYSERR_NOERROR)
       {
        waveOutGetErrorText(MMRESULT, errmsg, MAXERRORLENGTH);

        MessageBox.Show(
        "waveOutReset(): " + errmsg.ToString(),
        this.Text,
        MessageBoxButtons.OK,
        MessageBoxIcon.Error);
       }

       WAVEHDR wh = (WAVEHDR)Marshal.PtrToStructure(waveHdrPtr, typeof(WAVEHDR)); // copy unmanaged struct

       waveHdr = wh;  // update managed struct
    }

When the WHDR_DONE bit sets we can call the waveOutUnPrepareHeader() function to release

the resources previously set up:

    if ((MMRESULT = waveOutUnprepareHeader(waveDevice, waveHdrPtr, Marshal.SizeOf(waveHdr))) != MMSYSERR_NOERROR)
          [snipped]

I release the unmanaged memory allocated in the Open() method in the class's Close method:

        Marshal.FreeHGlobal(waveHdrPtr);

Sample Code:

http://www.ipentec.com/document/document.aspx?page=csharp-play-wave-file-using-wave-api
http://stackoverflow.com/questions/1887288/marshal-allochglobal-vs-marshal-alloccotaskmem-marshal-sizeof-vs-sizeof




There are a number of samples out there that show how to work with the Wave API (ie sound recording and playback) on both Windows and Windows Mobile via either the .NET Framework or the .NET Compact Framework.  Unfortunately because of subtle differences between the platforms it is difficult to build a single library that works across both platforms. Over a series of posts I’m going to show you how to work with the api to build a library that will work across both platforms.

The starting point is to look at the api calls themselves.  There is plenty of documentation out there that discusses what each of the calls are supposed to do but essentially the api calls are the same between the platforms with the exception that they reside in different assemblies.  As they are native calls they need to be imported using a DllImport.  Here are most of the Windows (Desktop suffix) and Windows Mobile (CF suffix) imports – there are some additional api calls that you can include if you require them following a similar pattern.

[DllImport("coredll.dll", EntryPoint = "waveInGetNumDevs")] 
internal static extern int waveInGetNumDevs_CF();

[DllImport("winmm.dll", EntryPoint = "waveInGetNumDevs")] 
internal static extern int waveInGetNumDevs_Desktop();

[DllImport("coredll.dll", EntryPoint = "waveInOpen")] 
internal static extern MMSYSERR waveInOpen_CF(out IntPtr phwi, uint uDeviceID, ref WAVEFORMATEX pwfx, IntPtr callback, uint dwInstance, uint fdwOpen); 
[DllImport("winmm.dll", EntryPoint = "waveInOpen")] 
internal static extern MMSYSERR waveInOpen_Desktop(out IntPtr phwi, uint uDeviceID, ref WAVEFORMATEX pwfx, IntPtr callback, uint dwInstance, uint fdwOpen);

[DllImport("coredll.dll", EntryPoint = "waveInPrepareHeader")] 
internal static extern MMSYSERR waveInPrepareHeader_CF(IntPtr hwi, IntPtr pwh, uint cbwh);

[DllImport("winmm.dll", EntryPoint = "waveInPrepareHeader")] 
internal static extern MMSYSERR waveInPrepareHeader_Desktop(IntPtr hwi, IntPtr pwh, uint cbwh);

[DllImport("coredll.dll", EntryPoint = "waveInUnprepareHeader")] 
internal static extern MMSYSERR waveInUnprepareHeader_CF(IntPtr hwi, IntPtr pwh, uint cbwh);

[DllImport("winmm.dll", EntryPoint = "waveInUnprepareHeader")] 
internal static extern MMSYSERR waveInUnprepareHeader_Desktop(IntPtr hwi, IntPtr pwh, uint cbwh);

[DllImport("coredll.dll", EntryPoint = "waveInClose")] 
internal static extern MMSYSERR waveInClose_CF(IntPtr hwi);

[DllImport("winmm.dll", EntryPoint = "waveInClose")] 
internal static extern MMSYSERR waveInClose_Desktop(IntPtr hwi);

[DllImport("coredll.dll", EntryPoint = "waveInReset")] 
internal static extern MMSYSERR waveInReset_CF(IntPtr hwi);

[DllImport("winmm.dll", EntryPoint = "waveInReset")] 
internal static extern MMSYSERR waveInReset_Desktop(IntPtr hwi);

[DllImport("coredll.dll", EntryPoint = "waveInStart")] 
internal static extern MMSYSERR waveInStart_CF(IntPtr hwi);

[DllImport("winmm.dll", EntryPoint = "waveInStart")] 
internal static extern MMSYSERR waveInStart_Desktop(IntPtr hwi);

[DllImport("coredll.dll", EntryPoint = "waveInStop")] 
internal static extern MMSYSERR waveInStop_CF(IntPtr hwi);

[DllImport("winmm.dll", EntryPoint = "waveInStop")] 
internal static extern MMSYSERR waveInStop_Desktop(IntPtr hwi);

[DllImport("coredll.dll", EntryPoint = "waveInAddBuffer")] 
internal static extern MMSYSERR waveInAddBuffer_CF(IntPtr hwi, IntPtr pwh, uint cbwh);

[DllImport("winmm.dll", EntryPoint = "waveInAddBuffer")] 
internal static extern MMSYSERR waveInAddBuffer_Desktop(IntPtr hwi, IntPtr pwh, uint cbwh);

[DllImport("coredll.dll", EntryPoint = "waveInGetDevCaps")] 
internal static extern MMSYSERR waveInGetDevCaps_CF(uint uDeviceId, byte[] pwic, uint cbwic);

[DllImport("winmm.dll", EntryPoint = "waveInGetDevCaps")] 
internal static extern MMSYSERR waveInGetDevCaps_Desktop(uint uDeviceId, byte[] pwic, uint cbwic);

[DllImport("coredll.dll", EntryPoint = "waveOutGetNumDevs")] 
internal static extern int waveOutGetNumDevs_CF();

[DllImport("winmm.dll", EntryPoint = "waveOutGetNumDevs")] 
internal static extern int waveOutGetNumDevs_Desktop();

[DllImport("coredll.dll", EntryPoint = "waveOutOpen")] 
internal static extern MMSYSERR waveOutOpen_CF(out IntPtr phwo, uint uDeviceID, ref WAVEFORMATEX pwfx, IntPtr dwCallback, uint dwInstance, uint fdwOpen); 
[DllImport("winmm.dll", EntryPoint = "waveOutOpen")]        internal static extern MMSYSERR waveOutOpen_Desktop(out IntPtr phwo, uint uDeviceID, ref WAVEFORMATEX pwfx, IntPtr dwCallback, uint dwInstance, uint fdwOpen);        /// <summary>

[DllImport("coredll.dll", EntryPoint = "waveOutPrepareHeader")] 
internal static extern MMSYSERR waveOutPrepareHeader_CF(IntPtr hwo, IntPtr pwh, uint cbwh);

[DllImport("winmm.dll", EntryPoint = "waveOutPrepareHeader")] 
internal static extern MMSYSERR waveOutPrepareHeader_Desktop(IntPtr hwo, IntPtr pwh, uint cbwh);

[DllImport("coredll.dll", EntryPoint = "waveOutWrite")] 
internal static extern MMSYSERR waveOutWrite_CF(IntPtr hwo, IntPtr pwh, uint cbwh);

[DllImport("winmm.dll", EntryPoint = "waveOutWrite")] 
internal static extern MMSYSERR waveOutWrite_Desktop(IntPtr hwo, IntPtr pwh, uint cbwh);

[DllImport("coredll.dll", EntryPoint = "waveOutUnprepareHeader")] 
internal static extern MMSYSERR waveOutUnprepareHeader_CF(IntPtr hwo, IntPtr pwh, uint cbwh);

[DllImport("winmm.dll", EntryPoint = "waveOutUnprepareHeader")] 
internal static extern MMSYSERR waveOutUnprepareHeader_Desktop(IntPtr hwo, IntPtr pwh, uint cbwh);

[DllImport("coredll.dll", EntryPoint = "waveOutClose")] 
internal static extern MMSYSERR waveOutClose_CF(IntPtr hwo);

[DllImport("winmm.dll", EntryPoint = "waveOutClose")] 
internal static extern MMSYSERR waveOutClose_Desktop(IntPtr hwo);

[DllImport("coredll.dll", EntryPoint = "waveOutReset")] 
internal static extern MMSYSERR waveOutReset_CF(IntPtr hwo);

[DllImport("winmm.dll", EntryPoint = "waveOutReset")] 
internal static extern MMSYSERR waveOutReset_Desktop(IntPtr hwo);

[DllImport("coredll.dll", EntryPoint = "waveOutGetDevCaps")] 
internal static extern MMSYSERR waveOutGetDevCaps_CF(uint uDeviceID, byte[] pwoc, uint cbwoc);

[DllImport("winmm.dll", EntryPoint = "waveOutGetDevCaps")] 
internal static extern MMSYSERR waveOutGetDevCaps_Desktop(uint uDeviceID, byte[] pwoc, uint cbwoc);

You will notice that the Windows Mobile calls all reference coredll.dll, whilst the Windows calls reference winmm.dll.  In order to build a common library we need a way to abstract these calls so that after initialising the library we never have to worry about whether it’s running on a device or a desktop machine. To do this we just need to define a series of delegates that map to each of these functions, and then create instances of them that point to the relevant functions.

public delegate int HardwareDeviceCount(); 
public delegate MMSYSERR HardwareOpen(out IntPtr hardwareInterface, uint deviceId, ref WAVEFORMATEX waveFormatSettings, IntPtr callbackFunction, uint callbackData, uint callbackType); 
public delegate MMSYSERR HardwareGetDeviceCaps(uint deviceId, byte[] data, uint dataSize); 
public delegate MMSYSERR HardwarePrepareHeader(IntPtr hardwareInterface, IntPtr headerReference, uint headerSize); 
public delegate MMSYSERR HardwareAddBuffer(IntPtr hardwareInterface, IntPtr bufferReference, uint bufferSize); 
public delegate MMSYSERR HardwareStart(IntPtr hardwareInterface); 
public delegate MMSYSERR HardwareStop(IntPtr hardwareInterface); 
public delegate MMSYSERR HardwareUnprepareHeader(IntPtr hardwareInterface, IntPtr headerReference, uint headerSize); 
public delegate MMSYSERR HardwareClose(IntPtr hardwareInterface); 
public delegate MMSYSERR HardwareReset(IntPtr hardwareInterface); 
public delegate MMSYSERR HardwareGetPosition(IntPtr hardwareInterface, ref MMTIME timeReference, uint timeSize); 
public delegate MMSYSERR HardwareGetId(IntPtr hardwareInterface, ref uint deviceOutput);

private static HardwareDeviceCount waveInGetNumDevs; 
private static HardwareOpen waveInOpen; 
private static HardwareGetDeviceCaps waveInGetDevCaps; 
private static HardwarePrepareHeader waveInPrepareHeader; 
private static HardwareUnprepareHeader waveInUnprepareHeader; 
private static HardwareAddBuffer waveInAddBuffer; 
private static HardwareStart waveInStart; 
private static HardwareClose waveInClose; 
private static HardwareStop waveInStop; 
private static HardwareReset waveInReset;

private static HardwareDeviceCount waveOutGetNumDevs; 
private static HardwareOpen waveOutOpen; 
private static HardwareReset waveOutReset;

private static HardwareGetDeviceCaps waveOutGetDevCaps; 
private static HardwarePrepareHeader waveOutPrepareHeader; 
private static HardwareUnprepareHeader waveOutUnprepareHeader; 
private static HardwareClose waveOutClose; 
private static HardwareWrite waveOutWrite;

private static void SetupDesktopDelegates() 

    waveOutGetNumDevs = NativeMethods.waveOutGetNumDevs_Desktop; 
    waveOutOpen = NativeMethods.waveOutOpen_Desktop; 
    waveOutReset = NativeMethods.waveOutReset_Desktop;

    waveOutGetDevCaps = NativeMethods.waveOutGetDevCaps_Desktop; 
    waveOutPrepareHeader = NativeMethods.waveOutPrepareHeader_Desktop; 
    waveOutUnprepareHeader = NativeMethods.waveOutUnprepareHeader_Desktop; 
    waveOutClose = NativeMethods.waveOutClose_Desktop; 
    waveOutWrite = NativeMethods.waveOutWrite_Desktop;

    waveDataCallback = QueryOutgoingData; 
    waveDataCallbackPointer = Marshal.GetFunctionPointerForDelegate(waveDataCallback); 
    CALLBACK_TYPE = Wave.CALLBACK_FUNCTION; 
}

private static void SetupCompactDelegates() 

    waveOutGetNumDevs = NativeMethods.waveOutGetNumDevs_CF; 
    waveOutOpen = NativeMethods.waveOutOpen_CF; 
    waveOutReset = NativeMethods.waveOutReset_CF;

    waveOutGetDevCaps = NativeMethods.waveOutGetDevCaps_CF; 
    waveOutPrepareHeader = NativeMethods.waveOutPrepareHeader_CF; 
    waveOutUnprepareHeader = NativeMethods.waveOutUnprepareHeader_CF; 
    waveOutClose = NativeMethods.waveOutClose_CF; 
    waveOutWrite = NativeMethods.waveOutWrite_CF;

    WaveLibrary.Native.CF.SoundMessageWindow window = Wave.SetupMessageWindow(); 
    window.WaveOutDoneMessage += new WaveDoneEventHandler(MessageWindow_WaveDoneMessage); 
    waveDataCallbackPointer = window.Hwnd; 
    CALLBACK_TYPE = Wave.CALLBACK_WINDOW; 
}

In this code we have declared the set of delegates, a set of static instances and then have a two methods that create instances pointing to either the Windows or Windows Mobile imported functions.  Note that it’s important to have these abstracted into separate methods as the library will throw an exception when it attempts to reference a dll that can’t be located.  Having these calls in a separate function means that only the called function will be JIT’d meaning the exception won’t be thrown.

if (useDesktop) 
            { 
                SetupDesktopDelegates(); 
            } 
            else 
            { 
                SetupCompactDelegates(); 
            }

You can simply call the relevant setup function based on whether you are running on the desktop or a device.

http://nicksnettravels.builttoroam.com/post/2009/04/29/Working-with-the-Wave-API-for-Windows-and-Windows-Mobile-via-the-NET-Framework.aspx

https://msdn.microsoft.com/en-us/library/aa446573.aspx

https://msdn.microsoft.com/en-us/library/ms173187.aspx


作者  | 2015-6-4 13:37:44 | 阅读(83) |评论(0) | 阅读全文>>

C# 让窗体支持拖放文件进入的代码

2015-5-30 14:01:18 阅读34 评论0 302015/05 May30

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Media;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Controls;

        public Form1()
        {
            InitializeComponent();
            // Add using System.Windows.Controls;
            //listBox1. //AddHandler(RichTextBox.DragOverEvent, new DragEventHandler(RichTextBox_DragOver), true);
            //listBox1.AddHandler(RichTextBox.DropEvent, new DragEventHandler(RichTextBox_Drop), true);
            this.DragEnter += new DragEventHandler(Form1_DragEnter);
            this.DragDrop += new DragEventHandler(Form1_DragDrop);
        }

        void Form1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
        }

        void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            // foreach (string file in files) MessageBox.Show(file); //
            foreach (string file in files)
            { listBox1.Items.Add(file); }  
        }

作者  | 2015-5-30 14:01:18 | 阅读(34) |评论(0) | 阅读全文>>

VALIDATING X12: What Are Invalid EDI X12 Files?

2015-5-17 1:00:28 阅读50 评论0 172015/05 May17

What Are Invalid EDI X12 Files?

Once you open EDI file in some text editor like Notepad, it looks cryptic. However all valid EDI X12 files have same properties:


1. They all start with three letters: “ISA”

2. After 106 characters there is word “GS”. Sometimes “GS” is on the second line. If “GS” is on the second line then there might
be 108 characters between “ISA” and “GS” (there are two non-printable carriage return and line feed characters between
lines). There are also few exceptions to this rule. Example: if your segment separator is carriage return then you have 105
characters in ISA and one non-printable carriage return character at the end of line with GS following it.

3. ISA segment is 106 characters long and sometimes longer. Even 108 characters if you have ~ tilde segment separator and
carriage return and line feed characters at the end of segment (after the tilde).


Most translators read and break down EDI files using these two points above. Most common scenarios why translator might not be able
to process the file:

1. That is not an EDI X12 file. Period. It is flat file, XML or scanned print image form or something else but EDI file.

2. If you copy and paste EDI file from Internet Browser window in most cases resulting EDI file will not be valid anymore. This is
due to how spaces are displayed in the Internet Browsers. Instead of 103 characters between ISA and GS you might end up
having much less.

3. Usually EDI files are sent over secure connections using encryption/decryption communications. Sometimes not just
communications but EDI files are encrypted themselves. Encryption leaves ISA/GS part valid but all segments in the file
unreadable. Unless EDI file is decrypted translator will not be able to read it correctly.

4. Some EDI files come from mainframe computer systems. Occasionally they are formatted into columns of 80 characters long.
Extra carriage return and line feed characters break segments into multiple lines making EDI file invalid. Those files can not be
processed by some translators but Etasoft Extreme Translator can process them.

5. Rarely EDI software communication packages combine multiple EDI messages of various types into one file. There are two
variations of this combination:

a) Example: 810 invoices and 997 acknowledgements with the same separators in one file. This is valid EDI file however output of
translator might not look right. Example: in translations from EDI to flat files translator will try to flatten EDI loops and encounter
few loops repeating independent of each other (as per example above: 810 invoices will repeat separately from 997 loops). It is
like trying to combine two spreadsheets that have no common fields; at the end combined spreadsheet will have mix of lines
 that do not tie up.

b) Example: 810 invoices and 997 acknowledgements with the different separators in one file. This is not possible to process by
many translators. Usually translators detect separators at the start of the EDI file. If separators change somewhere in the middle
of the file, translator will continue processing the file using old separators found at the file start. Scenario when various EDI
messages are mixed in one file with different separators is very rare but we mention it here to complete possible list of files that
can not be processed.

作者  | 2015-5-17 1:00:28 | 阅读(50) |评论(0) | 阅读全文>>

查看所有日志>>

 
 
 
 
 

有道博客魔方

 
 
模块内容加载中...
 
 
 
 
 

有道博客搜索

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2015

下载LOFTER客户端

汇聚2000万达人的兴趣社区
下载即送20张免费照片冲印

注册 登录  
 加关注