接收端(服務(wù)端)中的socket要實時處于監(jiān)聽狀態(tài),即要設(shè)置一個死循環(huán)。
成都創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站設(shè)計、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的杜爾伯特網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
例如:
while(1){
//.....
}
當(dāng)接收到一個客戶端的消息,再為其開辟新的進(jìn)程進(jìn)行數(shù)據(jù)處理。
我也只是說個大概,具體建議網(wǎng)絡(luò)上百度一下socket通信方法,看看人家服務(wù)器端是怎么寫的。
我?guī)湍銓懥四切㎎AVA代碼了,效果包你滿意!呵呵……
至于網(wǎng)頁的代碼嘛,這里就不貼了。你要的話HI我吧^_^。
JAVA代碼如下:
import?java.awt.BorderLayout;
import?javax.swing.*;
import?java.awt.Dimension;
import?java.awt.Rectangle;
public?class?MyLuRu?extends?JFrame?{
private?static?final?long?serialVersionUID?=?1L;
private?JPanel?jContentPane?=?null;
private?JLabel?jLabel?=?null;
private?JLabel?jLabel1?=?null;
private?JLabel?jLabel2?=?null;
private?JLabel?jLabel3?=?null;
private?JTextField?jTextField?=?null;
private?JRadioButton?jRadioButton?=?null;
private?JRadioButton?jRadioButton1?=?null;
private?JComboBox?jComboBox?=?null;
private?JComboBox?jComboBox1?=?null;
private?JButton?jButton?=?null;
private?JButton?jButton1?=?null;
private?JTextArea?jTextArea?=?null;
private?ButtonGroup?mybg=new?ButtonGroup();
/**
*?This?is?the?default?constructor
*/
public?MyLuRu()?{
super();
initialize();
}
/**
*?This?method?initializes?this
*
*?@return?void
*/
private?void?initialize()?{
this.setSize(268,?407);
this.setContentPane(getJContentPane());
this.setTitle("錄入");
this.addWindowListener(new?java.awt.event.WindowAdapter()?{
public?void?windowClosing(java.awt.event.WindowEvent?e)?{
System.exit(0);
}
});
this.setVisible(true);
}
/**
*?This?method?initializes?jContentPane
*
*?@return?javax.swing.JPanel
*/
private?JPanel?getJContentPane()?{
if?(jContentPane?==?null)?{
jLabel3?=?new?JLabel();
jLabel3.setBounds(new?Rectangle(16,?150,?65,?18));
jLabel3.setText("文化程度:");
jLabel2?=?new?JLabel();
jLabel2.setBounds(new?Rectangle(16,?108,?39,?18));
jLabel2.setText("專業(yè):");
jLabel1?=?new?JLabel();
jLabel1.setBounds(new?Rectangle(16,?66,?39,?18));
jLabel1.setText("性別:");
jLabel?=?new?JLabel();
jLabel.setBounds(new?Rectangle(16,?24,?39,?18));
jLabel.setText("姓名:");
jContentPane?=?new?JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel,?null);
jContentPane.add(jLabel1,?null);
jContentPane.add(jLabel2,?null);
jContentPane.add(jLabel3,?null);
jContentPane.add(getJTextField(),?null);
jContentPane.add(getJRadioButton(),?null);
jContentPane.add(getJRadioButton1(),?null);
mybg.add(jRadioButton);
mybg.add(jRadioButton1);
jContentPane.add(getJComboBox(),?null);
jContentPane.add(getJComboBox1(),?null);
jContentPane.add(getJButton(),?null);
jContentPane.add(getJButton1(),?null);
jContentPane.add(getJTextArea(),?null);
}
return?jContentPane;
}
/**
*?This?method?initializes?jTextField
*
*?@return?javax.swing.JTextField
*/
private?JTextField?getJTextField()?{
if?(jTextField?==?null)?{
jTextField?=?new?JTextField();
jTextField.setBounds(new?Rectangle(61,?24,?180,?18));
}
return?jTextField;
}
/**
*?This?method?initializes?jRadioButton
*
*?@return?javax.swing.JRadioButton
*/
private?JRadioButton?getJRadioButton()?{
if?(jRadioButton?==?null)?{
jRadioButton?=?new?JRadioButton();
jRadioButton.setBounds(new?Rectangle(61,?62,?38,?26));
jRadioButton.setText("男");
}
return?jRadioButton;
}
/**
*?This?method?initializes?jRadioButton1
*
*?@return?javax.swing.JRadioButton
*/
private?JRadioButton?getJRadioButton1()?{
if?(jRadioButton1?==?null)?{
jRadioButton1?=?new?JRadioButton();
jRadioButton1.setBounds(new?Rectangle(117,?62,?38,?26));
jRadioButton1.setText("女");
}
return?jRadioButton1;
}
/**
*?This?method?initializes?jComboBox
*
*?@return?javax.swing.JComboBox
*/
private?JComboBox?getJComboBox()?{
if?(jComboBox?==?null)?{
String[]?strcb={"計算機","電子","工商"};
jComboBox?=?new?JComboBox(strcb);
jComboBox.setBounds(new?Rectangle(62,?108,?93,?18));
}
return?jComboBox;
}
/**
*?This?method?initializes?jComboBox1
*
*?@return?javax.swing.JComboBox
*/
private?JComboBox?getJComboBox1()?{
if?(jComboBox1?==?null)?{
String[]?strcb2={"大專","本科","碩士","博士"};
jComboBox1?=?new?JComboBox(strcb2);
jComboBox1.setBounds(new?Rectangle(92,?150,?125,?18));
}
return?jComboBox1;
}
/**
*?This?method?initializes?jButton
*
*?@return?javax.swing.JButton
*/
private?JButton?getJButton()?{
if?(jButton?==?null)?{
jButton?=?new?JButton();
jButton.setBounds(new?Rectangle(66,?181,?60,?28));
jButton.setText("提交");
jButton.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
String?strname=jTextField.getText();
String?strsex="男";
if(jRadioButton1.isSelected()){
strsex="女";
}
String?strzy=jComboBox.getSelectedItem().toString();
String?strwh=jComboBox1.getSelectedItem().toString();
jTextArea.setText("姓名:"+strname+"\r\n"+"性別:"+strsex+"\r\n"+"專業(yè):"+strzy+"\r\n"+"文化:"+strwh);
}
});
}
return?jButton;
}
/**
*?This?method?initializes?jButton1
*
*?@return?javax.swing.JButton
*/
private?JButton?getJButton1()?{
if?(jButton1?==?null)?{
jButton1?=?new?JButton();
jButton1.setBounds(new?Rectangle(158,?181,?60,?28));
jButton1.setText("取消");
jButton1.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
System.exit(0);
}
});
}
return?jButton1;
}
/**
*?This?method?initializes?jTextArea
*
*?@return?javax.swing.JTextArea
*/
private?JTextArea?getJTextArea()?{
if?(jTextArea?==?null)?{
jTextArea?=?new?JTextArea();
jTextArea.setBounds(new?Rectangle(16,?225,?229,?130));
}
return?jTextArea;
}
public?static?void?main(String?args[]){
new?MyLuRu();
}
}
效果如下圖:
1.TCP/IP協(xié)議要求信息必須在塊(chunk)中發(fā)送和接收,而塊的長度必須是8位的倍數(shù),因此,我們可以認(rèn)為TCP/IP協(xié)議中傳輸?shù)男畔⑹亲止?jié)序列。如何發(fā)送和解析信息需要一定的應(yīng)用程序協(xié)議。
2.信息編碼:
首先是Java里對基本整型的處理,發(fā)送時,要注意:1)每種數(shù)據(jù)類型的字節(jié)個數(shù);2)這些字節(jié)的發(fā)送順序是怎樣的?(little-endian還是
big-endian);3)所傳輸?shù)臄?shù)值是有符號的(signed)還是無符號的(unsigned)。具體編碼時采用位操作(移位和屏蔽)就可以了。
具體在Java里,可以采用DataOutputStream類和ByteArrayOutputStream來實現(xiàn)?;謴?fù)時可以采用
DataInputStream類和ByteArrayInputStream類。
其次,字符串和文本,在一組符號與一組整數(shù)之間的映射稱為編碼字符集(coded character
set)。發(fā)送者與接收者必須在符號與整數(shù)的映射方式上達(dá)成共識,才能使用文本信息進(jìn)行通信,最簡單的方法就是定義一個標(biāo)準(zhǔn)字符集。具體編碼時采用
String的getBytes()方法。
最后,位操作。如果設(shè)置一個特定的設(shè)為1,先設(shè)置好掩碼(mask),之后用或操作;要清空特定一位,用與操作。
3.成幀與解析
成幀(framing)技術(shù)解決了接收端如何定位消息的首位位置的問題。
如果接收者試圖從套接字中讀取比消息本身更多的字節(jié),將可能發(fā)生以下兩種情況之一:如果信道中沒有其他消息,接收者將阻塞等待,同時無法處理接收
到的消息;如果發(fā)送者也在等待接收端的響應(yīng)消息,則會形成死鎖(dealock);另一方面,如果信道中還有其他消息,則接收者會將后面消息的一部分甚至
全部讀到第一條消息中去,這將產(chǎn)生一些協(xié)議錯誤。因此,在使用TCP套接字時,成幀就是一個非常重要的考慮因素。
有兩個技術(shù):
1.基于定界符(Delimiter-based):消息的結(jié)束由一個唯一的標(biāo)記(unique
marker)指出,即發(fā)送者在傳輸完數(shù)據(jù)后顯式添加的一個特殊字節(jié)序列。這個特殊標(biāo)記不能在傳輸?shù)臄?shù)據(jù)中出現(xiàn)。幸運的是,填充(stuffing)技術(shù)
能夠?qū)ο⒅谐霈F(xiàn)的定界符進(jìn)行修改,從而使接收者不將其識別為定界符。在接收者掃描定界符時,還能識別出修改過的數(shù)據(jù),并在輸出消息中對其進(jìn)行還原,從而
使其與原始消息一致。
2.顯式長度(Explicit length):在變長字段或消息前附加一個固定大小的字段,用來指示該字段或消息中包含了多少字節(jié)。這種方法要確定消息長度的上限,以確定保存這個長度需要的字節(jié)數(shù)。
接口:
Java代碼 import java.io.IOException; import java.io.OutputStream; public interface Framer { void frameMsg(byte [] message,OutputStream out) throws IOException; byte [] nextMsg() throws IOException; }
定界符的方式:
Java代碼 import java.io.ByteArrayOutputStream; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class DelimFramer implements Framer { private InputStream in;//data source; private static final byte DELIMTER=(byte)'\n';//message delimiter public DelimFramer(InputStream in){ this.in=in; } @Override public void frameMsg(byte[] message, OutputStream out) throws IOException { //ensure that the message dose not contain the delimiter for(byte b:message){ if(b==DELIMTER) throw new IOException("Message contains delimiter"); } out.write(message); out.write(DELIMTER); out.flush(); } @Override public byte[] nextMsg() throws IOException { ByteArrayOutputStream messageBuffer=new ByteArrayOutputStream(); int nextByte; while((nextByte=in.read())!=DELIMTER){ if(nextByte==-1){//end of stream? if(messageBuffer.size()==0){ return null; }else{ throw new EOFException("Non-empty message without delimiter"); } } messageBuffer.write(nextByte); } return messageBuffer.toByteArray(); } }
顯式長度方法:
Java代碼 import java.io.DataInputStream; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class LengthFramer implements Framer { public static final int MAXMESSAGELENGTH=65535; public static final int BYTEMASK=0xff; public static final int SHOTMASK=0xffff; public static final int BYTESHIFT=8; private DataInputStream in;// wrapper for data I/O public LengthFramer(InputStream in) throws IOException{ this.in=new DataInputStream(in); } @Override public void frameMsg(byte[] message, OutputStream out) throws IOException { if(message.lengthMAXMESSAGELENGTH){ throw new IOException("message too long"); } //write length prefix out.write((message.lengthBYTEMASK)BYTEMASK); out.write(message.lengthBYTEMASK); //write message out.write(message); out.flush(); } @Override public byte[] nextMsg() throws IOException { int length; try{ length=in.readUnsignedShort(); }catch(EOFException e){ //no (or 1 byte) message; return null; } //0=length=65535; byte [] msg=new byte[length]; in.readFully(msg);//if exception,it's a framing error; return msg; } }
用Json格式的消息就可以了。基于標(biāo)準(zhǔn)的,php可以寫,Java可以解析。
或者你自己定義一個你自己可以解析的格式,讓php組織好返回給java,java解析。
下面是一個示例,可以看著改改。教育經(jīng)歷2007/09—至今xxxx大學(xué)信息學(xué)院計算機科學(xué)與技術(shù)將于2011年6月獲工科學(xué)士學(xué)位項目經(jīng)驗項目名稱:xxxx有限公司生產(chǎn)管理信息系統(tǒng)開發(fā)環(huán)境:struts2+hibernate+spring開發(fā)工具:sqlserver2000,MyEclipse、ireport、tomcat項目描述:公司內(nèi)部軟件,實現(xiàn)了整個化工廠的生產(chǎn)流程操作、員工的管理、報表的導(dǎo)出、文件的上傳下載、用戶權(quán)限控制,提高了工作效率。責(zé)任描述:參與部分模塊的設(shè)計、報表設(shè)計、編碼工作和用戶手冊的編寫1.工藝員模塊:實現(xiàn)了增刪查改等功能和文件上傳、下載、報表導(dǎo)出2.下游客戶模塊:實現(xiàn)了增刪查改、報表導(dǎo)出等功能3.對外函件匯總:實現(xiàn)了增刪查改等功能和文件上傳、下載、報表導(dǎo)出4.設(shè)備管理:實現(xiàn)了配件儲備定額一覽表中的增刪查改、報表導(dǎo)出5.質(zhì)檢管理:實現(xiàn)了中控分析報告單中的增刪查改、報表導(dǎo)出6.還有就是其他模塊中的一些后期修改項目總結(jié):通過這個項目的開發(fā),對S2SH有了更深一層的認(rèn)識。同時也學(xué)習(xí)了部分Ajax的應(yīng)用,增強了團(tuán)隊意識和協(xié)調(diào)能力。也認(rèn)識到學(xué)習(xí)的重要性,軟件行業(yè)技術(shù)更新的很快,每天都要去努力的學(xué)習(xí)新知識。批注:最好能細(xì)化到你具體做了哪一部分的工作,現(xiàn)在看我不知道描述的各個模塊的功能是你自己完成的部分還是團(tuán)隊工作成果。個人技能IT技能熟練掌握J(rèn)AVA面向?qū)ο缶幊陶Z言,有良好的編碼習(xí)慣;熟練使用HTML,并了解Ajax熟練使用jsp、servlet、JavaBean進(jìn)行web應(yīng)用開發(fā);熟練掌握Struts2、Hibernate、Spring等開源框架技術(shù),并能夠用Struts2.0+Hibernate+Spring進(jìn)行大型項目的開發(fā);熟練操作MSSQLSERVER、MySQL數(shù)據(jù)庫,了解Oracle數(shù)據(jù)庫,熟悉SQL語句;能夠熟練運用Eclipse和myEclipse等開發(fā)工具英語技能四級2008.12通過六級2009.06通過批注:1.專業(yè)技能中最好能按照你熟練的程度降序排列,把你最擅長的放到最前面,這樣方面HR了解你的技能方向,與職位要求做對比。2.英語技能中通過了六級就不需要說明四級了。獲獎情況獲得2007-2008學(xué)年國家勵志獎學(xué)金獲得2007-2008學(xué)年學(xué)校優(yōu)秀學(xué)生三等獎學(xué)金社會實踐2009學(xué)年-至今作為09屆計科2班班主任助理,幫助班主任與班級學(xué)生交流。2008-2009學(xué)年擔(dān)任班長,幫助班主任與班級同學(xué)交流,組織了班里同學(xué)東海島的出游和北海的出游,個人組織能力、團(tuán)隊意識和溝通能力得到很大提升。2008-2009學(xué)年在學(xué)生處助學(xué)信貸科勤工儉學(xué),負(fù)責(zé)學(xué)生貸款材料和申請獎助學(xué)金材料的核查,整理分析數(shù)據(jù)和分發(fā)材料,有責(zé)任心和吃苦耐勞精神。2008-2009學(xué)年組隊參加了xxxx大學(xué)第一屆編程大賽,并進(jìn)入決賽。END注意事項java軟件工程師簡歷批注:1.“個人經(jīng)歷”就不是簡歷中一個合適的模塊名稱,因為簡歷其實就是個人經(jīng)歷的一個另外說法,怎么會在簡歷中再存在一個個人經(jīng)歷呢?應(yīng)該是“社會實踐”之類的名稱更合適。2.第一、二條中“幫助班主任與班級學(xué)生交流”“組織了班里同學(xué)東海島的出游和北海的出游”語法存在錯誤,“幫助……交流”本身就不是一個正確的搭配,第二句也有不通順的地方,簡歷中語言雖然不需要華麗,但是也不能有明顯語法錯誤,畢竟是母語簡歷,這樣有些說不過去。
public boolean mainto()
{
boolean flag = true;
//建立郵件會話
Properties pro = new Properties();
pro.put("mail.smtp.host","smtp.qq.com");//存儲發(fā)送郵件的服務(wù)器
pro.put("mail.smtp.auth","true"); //通過服務(wù)器驗證
Session s =Session.getInstance(pro); //根據(jù)屬性新建一個郵件會話
//s.setDebug(true);
//由郵件會話新建一個消息對象
MimeMessage message = new MimeMessage(s);
//設(shè)置郵件
InternetAddress fromAddr = null;
InternetAddress toAddr = null;
try
{
fromAddr = new InternetAddress(451144426+"@qq.com"); //郵件發(fā)送地址
message.setFrom(fromAddr); //設(shè)置發(fā)送地址
toAddr = new InternetAddress("12345367@qq.com"); //郵件接收地址
message.setRecipient(Message.RecipientType.TO, toAddr); //設(shè)置接收地址
message.setSubject(title); //設(shè)置郵件標(biāo)題
message.setText(content); //設(shè)置郵件正文
message.setSentDate(new Date()); //設(shè)置郵件日期
message.saveChanges(); //保存郵件更改信息
Transport transport = s.getTransport("smtp");
transport.connect("smtp.qq.com", "451144426", "密碼"); //服務(wù)器地址,郵箱賬號,郵箱密碼
transport.sendMessage(message, message.getAllRecipients()); //發(fā)送郵件
transport.close();//關(guān)閉
}
catch (Exception e)
{
e.printStackTrace();
flag = false;//發(fā)送失敗
}
return flag;
}
這是一個javaMail的郵件發(fā)送代碼,需要一個mail.jar
當(dāng)前標(biāo)題:java發(fā)送接收簡歷代碼 java發(fā)送接收簡歷代碼是什么
瀏覽路徑:http://chinadenli.net/article44/hgcdhe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)站維護(hù)、虛擬主機、定制開發(fā)、商城網(wǎng)站、移動網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)