麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Java socket 入門編程實(shí)例

2019-11-18 10:40:59
字體:
供稿:網(wǎng)友

這是一個(gè)C/S之間通信的例子,在JDK1.4下測(cè)試通過.
//服務(wù)器端源程序tcpserver.java

import java.io.*;
import java.net.*;
public class tcpserver
{
public static void main(String[] args) throws IOException
{
ServerSocket svrsoc=null;
Socket soc=null;
DataInputStream in=null;
PRintStream out=null;
InetAddress clientip=null;
String str=null;
try
{
svrsoc=new ServerSocket(8000);
System.out.println("Server start....");
soc=svrsoc.accept();

in=new DataInputStream(soc.getInputStream());
out=new PrintStream(soc.getOutputStream());
clientIP=soc.getInetAddress();
System.out.println("Client's IP address:"+clientIP);
out.println("welcome.....");
str=in.readLine();
while (!str.equals("quit"))
{
System.out.println("Client said:"+str);
str=in.readLine();
}
System.out.println("Client want to leave");
}
catch(Exception e)
{
System.out.println("error:"+e);
}
finally
{
in.close();
out.close();
soc.close();
svrsoc.close();
System.exit(0);
}
}
}

//客戶端源程序tcpclient.java

import java.io.*;
import java.net.*;
public class tcpclient
{
public static void main(String[] args) throws IOException
{
Socket soc=null;
DataInputStream in=null;
PrintStream out=null;
DataInputStream sysin=null;
String strin=null;
String strout=null;
try
{
soc=new Socket(args[0],8000);
System.out.println("Connecting to the Server");
in=new DataInputStream(soc.getInputStream());
out=new PrintStream(soc.getOutputStream());
strin=in.readLine();
System.out.println("Server said:"+strin);
sysin=new DataInputStream(System.in);
strout=sysin.readLine();
while (!strout.equals("quit"))
{
out.println(strout);
strout=sysin.readLine();
}
out.println(strout);
}
catch(Exception e)
{
System.out.println("error:"+e);
}
finally
{
in.close();
out.close();
soc.close();
sysin.close();
System.exit(0);
}
}
}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产亚洲综合精品 | 亚洲国产精品久久久 | 国产乱xxxx | 成人国产在线视频 | 精品国产一区二区在线 | 久久国产成人午夜av浪潮 | 91精品国产乱码久 | 一级免费 | 国产一区二区午夜 | 一区二区三区播放 | 国产在线观看91一区二区三区 | 羞羞羞羞视频 | 日韩视频在线观看免费视频 | chinese乱子伦xxxx国语对白 | 精国品产一区二区三区有限公司 | 精品一区二区三区中文字幕老牛 | 一级空姐毛片 | 亚洲第一激情网 | 欧美亚洲国产成人 | 日韩精品久久久 | 日日操夜夜透 | 国产乱淫av片免费 | 成人免费网视频 | 免费视频xxxx | 一区二区免费看 | 成人免费毛片在线观看 | 亚洲成人高清在线观看 | 31freehdxxxx欧美 | av影院在线播放 | 亚洲精品成人在线视频 | 亚洲性综合网 | 国产流白浆高潮在线观看 | 可以免费看的av | 日韩在线毛片 | 久草在线最新免费 | www国产成人免费观看视频,深夜成人网 | 日韩视频不卡 | www.com超碰 | 综合国产在线 | 蜜桃视频在线观看免费 | 特级毛片免费视频 |