亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? server.java

?? java socket server,對初學(xué)者很好的參考意義
?? JAVA
字號:
// a Java socket server// Keith Vertanen 4/99import java.io.*;import java.net.*;import java.awt.*;public class Server {   boolean VERBOSE = true;		 // turn on/off debugging output   static int BUFFSIZE = 128000;         // how many bytes our incoming buffer can hold   static int INT_SIZE = 4;   static int DOUBLE_SIZE = 8;   static int FLOAT_SIZE = 4;   byte data[];   byte buff[];   int port;   int dataport;   boolean reverse = false;   ServerSocket server;   Socket sock;   DatagramSocket recv_sock, send_sock;   String address;   BufferedInputStream input;   BufferedOutputStream output;      public Server(int p, int datap) throws IOException   {	port = p;	dataport = datap;          try {		server = new ServerSocket(port, 100);	}      	catch ( IOException e ) {         	e.printStackTrace();      	}	// allocate the datagram socket	try {		recv_sock = new DatagramSocket(dataport);		send_sock = new DatagramSocket();	} 	catch (SocketException se) {		se.printStackTrace();	}	// amortize the buffer allocation by just doing it once	buff = new byte[BUFFSIZE];	data = new byte[BUFFSIZE];    }    // wait for somebody to connect on our socket    public void connect() throws IOException    {	byte rev[] = new byte[1];	rev[0] = 0;		sock = server.accept();	address = sock.getInetAddress().getHostName();	if (VERBOSE) System.out.println("Client: opening socket to " +			address + " on port " + port + 			", datagrams on port = " + dataport);	input = new BufferedInputStream(sock.getInputStream(), BUFFSIZE);	output = new BufferedOutputStream(sock.getOutputStream(),BUFFSIZE);	// now find out if they want reversed bytes or not	input.read(rev);		if (VERBOSE) 		if (rev[0]==1) 		{			reverse = true;			System.out.println("Client:  requested reversed bytes");		}		else			System.out.println("Client:  requested normal byte order");   }   // send a string down the socket   public void send_string(String str) throws IOException   {	/* convert our string into an array of bytes */	ByteArrayOutputStream bytestream;	bytestream = new ByteArrayOutputStream(str.length());	DataOutputStream out;	out = new DataOutputStream(bytestream);	for (int i=0; i<str.length(); i++)		out.write((byte) str.charAt(i));	output.write(bytestream.toByteArray(), 0, bytestream.size());	output.flush(); 	if (VERBOSE) System.out.println("Client: sending '" + str +"'");	recv_ack();	send_ack();   }   public void send_bytes(byte vals[], int len) throws IOException   {	if (VERBOSE) 	{		System.out.print("Client: sending " + len +" bytes: ");		for (int i=0; i<len; i++)			System.out.print(vals[i] + " ");	}	output.write(vals, 0, len);	output.flush(); 	if (VERBOSE) System.out.println("");	recv_ack();	send_ack();   }   public void send_ints(int vals[], int len) throws IOException   {	if (VERBOSE) System.out.print("Client: sending " + len +" ints: ");	/* convert our array of ints into an array of bytes */	ByteArrayOutputStream bytestream;	bytestream = new ByteArrayOutputStream(len*INT_SIZE);	DataOutputStream out;	out = new DataOutputStream(bytestream);	for (int i=0; i<len; i++)	{		out.writeInt(vals[i]);	 	if (VERBOSE) System.out.print(vals[i]+" ");	}		byte byte_array[] = bytestream.toByteArray();	if (reverse)	{		// flip around our bytes if necessary		byte flip_array[] = new byte[bytestream.size()];		int i, j;		for (i=0; i<len; i++)		{			for (j=0; j<INT_SIZE; j++)			{				flip_array[(i+1) * INT_SIZE - j - 1] = 					byte_array[i * INT_SIZE + j];			}		}		output.write(flip_array, 0, bytestream.size());	}	else		output.write(byte_array, 0, bytestream.size());	output.flush(); 	if (VERBOSE) System.out.println("");	recv_ack();	send_ack();   }   public void send_floats(float vals[], int len) throws IOException   {	if (VERBOSE) System.out.print("Client: sending " + len +" floats: ");	/* convert our array of floats into an array of bytes */	ByteArrayOutputStream bytestream;	bytestream = new ByteArrayOutputStream(len*FLOAT_SIZE);	DataOutputStream out;	out = new DataOutputStream(bytestream);	for (int i=0; i<len; i++)	{		out.writeFloat(vals[i]);	 	if (VERBOSE) System.out.print(vals[i]+" ");	}		byte byte_array[] = bytestream.toByteArray();	if (reverse)	{		// flip around our bytes if necessary		byte flip_array[] = new byte[bytestream.size()];		int i, j;		for (i=0; i<len; i++)		{			for (j=0; j<FLOAT_SIZE; j++)			{				flip_array[(i+1) * FLOAT_SIZE - j - 1] = 					byte_array[i * FLOAT_SIZE + j];			}		}		output.write(flip_array, 0, bytestream.size());	}	else		output.write(byte_array, 0, bytestream.size());	output.flush(); 	if (VERBOSE) System.out.println("");	recv_ack();	send_ack();   }   public void send_doubles(double vals[], int len) throws IOException   {	if (VERBOSE) System.out.print("Client: sending " + len +" doubles: ");	/* convert our array of floats into an array of bytes */	ByteArrayOutputStream bytestream;	bytestream = new ByteArrayOutputStream(len*DOUBLE_SIZE);	DataOutputStream out;	out = new DataOutputStream(bytestream);	for (int i=0; i<len; i++)	{		out.writeDouble(vals[i]);	 	if (VERBOSE) System.out.print(vals[i]+" ");	}		byte byte_array[] = bytestream.toByteArray();	if (reverse)	{		// flip around our bytes if necessary		byte flip_array[] = new byte[bytestream.size()];		int i, j;		for (i=0; i<len; i++)		{			for (j=0; j<DOUBLE_SIZE; j++)			{				flip_array[(i+1) * DOUBLE_SIZE - j - 1] = 					byte_array[i * DOUBLE_SIZE + j];			}		}		output.write(flip_array, 0, bytestream.size());	}	else		output.write(byte_array, 0, bytestream.size());	output.flush();	if (VERBOSE) System.out.println("");		recv_ack();	send_ack();   }   public void send_datagram(byte vals[], int len) throws IOException   {	DatagramPacket sendPacket;	if (VERBOSE) 	{		System.out.print("Client: sending datagram of " + len +" bytes: ");		for (int i=0; i<len; i++)			System.out.print(vals[i] + " ");	}	sendPacket = new DatagramPacket(vals, len,					InetAddress.getByName(address), dataport);	send_sock.send(sendPacket); 	if (VERBOSE) System.out.println("");   }   // recv a string from the socket (terminates on terminal char)   public String recv_string(char terminal) throws IOException   {	char c;	String out;	// would have liked to use readUTF, but it didn't seem to work	// when talking to the c++ server	out = new String("");	while ((c=(char) input.read())!=terminal)		out = out + String.valueOf(c); 	if (VERBOSE) System.out.println("Client: recv'd '" + out +"'");	send_ack();	recv_ack();	return out;   }  public int recv_bytes(byte val[], int maxlen) throws IOException  {       int i;       int totalbytes = 0;       int numbytes;	if (maxlen>BUFFSIZE)		System.out.println("Sending more bytes then will fit in buffer!");	while (totalbytes < maxlen)	{		numbytes = input.read(data);		// copy the bytes into the result buffer		for (i=totalbytes; i<totalbytes+numbytes; i++)			val[i] = data[i-totalbytes];		totalbytes += numbytes;	}	if (VERBOSE) 	{		System.out.print("Client: received " + maxlen + " bytes - ");		for (i=0; i<maxlen; i++)			System.out.print(val[i]+" ");		System.out.println("");	}	// we now send an acknowledgement to the server to let them	// know we've got it	send_ack();	recv_ack();	return maxlen;  }  public int recv_ints(int val[], int maxlen) throws IOException  {       int i;       int totalbytes = 0;       int numbytes;	/* for performance, we need to receive data as an array of bytes		and then convert to an array of ints, more fun than		you can shake a stick at! */	if (maxlen*INT_SIZE>BUFFSIZE)		System.out.println("Sending more ints then will fit in buffer!");	while (totalbytes < maxlen*INT_SIZE)	{		numbytes = input.read(data);		// copy the bytes into the result buffer		for (i=totalbytes; i<totalbytes+numbytes; i++)			buff[i] = data[i-totalbytes];		totalbytes += numbytes;	}	// now we must convert the array of bytes to an array of ints	if (reverse)	{		// flip around our bytes if necessary	        ByteArrayInputStream bytestream_rev;		DataInputStream instream_rev;		byte flip_array[] = new byte[totalbytes];		int j;		for (i = 0; i < totalbytes / INT_SIZE; i++)		{			for (j = 0; j < INT_SIZE; j++)			{				flip_array[(i+1)*INT_SIZE - j - 1] = 					buff[i * INT_SIZE + j];			}		}		bytestream_rev = new ByteArrayInputStream(flip_array);		instream_rev = new DataInputStream(bytestream_rev);		for (i=0; i<maxlen; i++)			val[i] = instream_rev.readInt();	}	// end reverse section	else	{	        ByteArrayInputStream bytestream;		DataInputStream instream;		bytestream = new ByteArrayInputStream(buff);		instream = new DataInputStream(bytestream);		for (i=0; i<maxlen; i++)			val[i] = instream.readInt();	}	if (VERBOSE) 	{		System.out.print("Client: received " + maxlen + " ints - ");		for (i=0; i<maxlen; i++)			System.out.print(val[i]+" ");		System.out.println("");	}	// we now send an acknowledgement to the server to let them	// know we've got it	send_ack();	recv_ack();	return maxlen;  }  public int recv_doubles(double val[], int maxlen) throws IOException  {       int i;       int numbytes;       int totalbytes = 0;	/* for performance, we need to receive data as an array of bytes		and then convert to an array of ints, more fun than		you can shake a stick at! */	if (maxlen*8>BUFFSIZE)		System.out.println("Sending more doubles then will fit in buffer!");	while (totalbytes < maxlen*DOUBLE_SIZE)	{		numbytes = input.read(data);		// copy the bytes into the result buffer		for (i=totalbytes; i<totalbytes+numbytes; i++)			buff[i] = data[i-totalbytes];		totalbytes += numbytes;		}	// now we must convert the array of bytes to an array of doubles	if (reverse)	{		// flip around our bytes if necessary	        ByteArrayInputStream bytestream_rev;		DataInputStream instream_rev;		byte flip_array[] = new byte[totalbytes];		int j;		for (i = 0; i < totalbytes / DOUBLE_SIZE; i++)		{			for (j = 0; j < DOUBLE_SIZE; j++)			{				flip_array[(i+1)*DOUBLE_SIZE - j - 1] = 					buff[i * DOUBLE_SIZE + j];			}		}		bytestream_rev = new ByteArrayInputStream(flip_array);		instream_rev = new DataInputStream(bytestream_rev);		for (i=0; i<maxlen; i++)			val[i] = instream_rev.readDouble();	}	// end reverse section	else	{	        ByteArrayInputStream bytestream;		DataInputStream instream;		bytestream = new ByteArrayInputStream(buff);		instream = new DataInputStream(bytestream);		for (i=0; i<maxlen; i++)			val[i] = instream.readDouble();	}	if (VERBOSE) 	{		System.out.print("Client: received " + maxlen + " doubles - ");		for (i=0; i<maxlen; i++)			System.out.print(val[i]+" ");		System.out.println("");	}	send_ack();	recv_ack();	return maxlen;  }  public int recv_floats(float val[], int maxlen) throws IOException  {       int i;       int numbytes;       int totalbytes = 0;	/* for performance, we need to receive data as an array of bytes		and then convert to an array of ints, more fun than		you can shake a stick at! */	if (maxlen*FLOAT_SIZE>BUFFSIZE)		System.out.println("Sending more doubles then will fit in buffer!");	while (totalbytes < maxlen*FLOAT_SIZE)	{		numbytes = input.read(data);		// copy the bytes into the result buffer		for (i=totalbytes; i<totalbytes+numbytes; i++)			buff[i] = data[i-totalbytes];		totalbytes += numbytes;	}	// now we must convert the array of bytes to an array of ints	if (reverse)	{		// flip around our bytes if necessary	        ByteArrayInputStream bytestream_rev;		DataInputStream instream_rev;		byte flip_array[] = new byte[totalbytes];		int j;		for (i = 0; i < totalbytes / FLOAT_SIZE; i++)		{			for (j = 0; j < FLOAT_SIZE; j++)			{				flip_array[(i+1)*FLOAT_SIZE - j - 1] = 					buff[i * FLOAT_SIZE + j];			}		}		bytestream_rev = new ByteArrayInputStream(flip_array);		instream_rev = new DataInputStream(bytestream_rev);		for (i=0; i<maxlen; i++)			val[i] = instream_rev.readFloat();	}	// end reverse section	else	{	        ByteArrayInputStream bytestream;		DataInputStream instream;		bytestream = new ByteArrayInputStream(buff);		instream = new DataInputStream(bytestream);		for (i=0; i<maxlen; i++)			val[i] = instream.readFloat();	}	if (VERBOSE) 	{		System.out.print("Client: received " + maxlen + " floats - ");		for (i=0; i<maxlen; i++)			System.out.print(val[i]+" ");		System.out.println("");	}	send_ack();	recv_ack();	return maxlen;  }  public int recv_datagram(byte val[], int maxlen) throws IOException  {        int i;        int numbytes;	DatagramPacket receivePacket;	if (maxlen>BUFFSIZE)		System.out.println("Sending more bytes then will fit in buffer!");	receivePacket = new DatagramPacket(val, maxlen);	recv_sock.receive(receivePacket);	numbytes = receivePacket.getLength();	if (VERBOSE) 	{		System.out.print("Client: received " + numbytes + " bytes - ");		for (i=0; i<numbytes; i++)			System.out.print(val[i]+" ");		System.out.println("");	}	return numbytes;  }   // shutdown the socket   public void closesocket() throws IOException   {	sock.close(); 	if (VERBOSE) System.out.println("Client: closing socket");   }   // send a short ack to the server so they know we are ready for more   private void send_ack() throws IOException   {	int ack;	ack = 0;	if (VERBOSE)		System.out.println("Sending ack...");	output.write(ack);	output.flush();   }   // recv a short ack from the server so we know they are ready for more   private void recv_ack() throws IOException   {	int ack;	if (VERBOSE)		System.out.println("Waiting for ack...");	ack = (int) input.read();	if (VERBOSE)		System.out.println("Ack recieved.");   }}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线不卡中文字幕播放| 成人爽a毛片一区二区免费| 中文字幕在线不卡一区二区三区 | 中文在线资源观看网站视频免费不卡| 欧美日韩免费高清一区色橹橹| 91在线视频在线| 国产馆精品极品| 成人美女在线视频| 波多野结衣一区二区三区| 成人免费电影视频| 99精品欧美一区二区蜜桃免费| 粉嫩av一区二区三区粉嫩| 成人av网站在线观看免费| fc2成人免费人成在线观看播放| 懂色一区二区三区免费观看| 国产成人精品在线看| 成人短视频下载| 91精品91久久久中77777| 91高清在线观看| 在线综合亚洲欧美在线视频| 欧美videofree性高清杂交| 日韩精品一区二区三区老鸭窝| 精品国产污污免费网站入口 | 激情综合五月婷婷| 激情五月激情综合网| 成人爱爱电影网址| 欧美怡红院视频| 欧美一区二区三区免费视频 | 亚洲视频1区2区| 亚洲一区二区偷拍精品| 日韩成人一区二区| 粗大黑人巨茎大战欧美成人| 色综合中文字幕| 日韩天堂在线观看| 国产精品欧美一区二区三区| 亚洲视频免费在线| 久久精品国产一区二区三| 成人午夜视频福利| 欧美中文字幕一区| 久久久亚洲精品石原莉奈| 亚洲人成精品久久久久| 青娱乐精品视频| 91蜜桃视频在线| 日韩一区二区三区视频在线观看| 中文字幕中文字幕一区| 青青草国产精品亚洲专区无| 波多野洁衣一区| 精品电影一区二区三区| 亚洲色欲色欲www在线观看| 精品一区二区三区在线观看 | 天堂久久一区二区三区| 国产美女视频91| 欧美精品xxxxbbbb| 亚洲欧美韩国综合色| 久久99热狠狠色一区二区| 91福利精品第一导航| 国产日韩精品久久久| 肉色丝袜一区二区| 91成人免费在线| 国产精品麻豆视频| 国产精品一区二区久久不卡 | 亚洲美女视频一区| 国产乱一区二区| 日韩三级免费观看| 亚洲成人手机在线| aaa欧美色吧激情视频| 精品电影一区二区三区| 日韩av中文在线观看| 欧美私人免费视频| 亚洲综合999| 91福利国产成人精品照片| 自拍偷拍欧美精品| 成人动漫一区二区在线| 久久久一区二区| 国产精品影音先锋| 久久久久国产精品人| 久久97超碰色| 精品国产一区二区三区久久影院| 天堂va蜜桃一区二区三区漫画版| 欧美做爰猛烈大尺度电影无法无天| 国产精品第五页| 在线看日本不卡| 亚洲综合色在线| 欧美日韩国产精品自在自线| 午夜精品久久久久久久蜜桃app | 欧美一级久久久久久久大片| 午夜精品久久久久久不卡8050| 欧美日韩精品一区二区在线播放 | 日韩欧美一级特黄在线播放| 青草国产精品久久久久久| 日韩一级在线观看| 国产中文字幕一区| 国产亚洲综合av| 91色视频在线| 日韩国产欧美在线视频| 日韩美女主播在线视频一区二区三区| 久久99精品国产麻豆婷婷洗澡| 久久网站最新地址| 99久久精品99国产精品| 亚洲综合精品久久| 正在播放一区二区| 国产精品一二一区| 一区二区三区在线观看欧美| 91麻豆精品国产无毒不卡在线观看 | 国产久卡久卡久卡久卡视频精品| 国产色产综合产在线视频| 91看片淫黄大片一级在线观看| 亚洲一区日韩精品中文字幕| 日韩欧美国产精品| 北岛玲一区二区三区四区| 亚洲一区二区三区三| 欧美精品一区二区精品网| 色婷婷激情久久| 日韩电影网1区2区| 亚洲女同ⅹxx女同tv| 日韩欧美在线综合网| 99天天综合性| 免费观看30秒视频久久| 亚洲人成人一区二区在线观看| 欧美r级电影在线观看| 欧美艳星brazzers| 盗摄精品av一区二区三区| 日韩电影在线免费| 夜色激情一区二区| 久久精品人人做人人综合| 91精品午夜视频| 波多野结衣在线一区| 久久99深爱久久99精品| 亚洲一本大道在线| 综合久久国产九一剧情麻豆| 精品久久99ma| 欧美日韩国产经典色站一区二区三区| 成人午夜视频在线| 国产一区二区网址| 日韩1区2区日韩1区2区| 一区二区三区精品视频在线| 欧美激情一区二区三区全黄| 精品欧美久久久| 日韩一区二区三区三四区视频在线观看| k8久久久一区二区三区| 国产精品综合一区二区三区| 麻豆精品蜜桃视频网站| 亚洲自拍偷拍九九九| 亚洲男同性视频| 国产精品久久久久三级| 久久久久久久综合| 欧美xfplay| 精品毛片乱码1区2区3区| 欧美三片在线视频观看| 欧美色倩网站大全免费| 欧美亚洲综合色| 精品视频999| 欧美图片一区二区三区| 欧美日韩成人综合| 69成人精品免费视频| 在线电影国产精品| 91麻豆精品国产91久久久久久| 欧美日韩在线播放三区四区| 欧美日韩一级片网站| 欧美日韩你懂得| 3d成人动漫网站| 337p日本欧洲亚洲大胆精品 | 国产精品私房写真福利视频| 国产午夜三级一区二区三| 国产欧美日韩中文久久| 中文字幕精品一区二区三区精品| 久久精品亚洲国产奇米99| 国产欧美一区二区三区网站| 国产精品三级在线观看| 亚洲免费毛片网站| 亚洲一区欧美一区| 美女在线一区二区| 国产成人精品午夜视频免费| www.亚洲国产| 欧美日韩色一区| 精品国偷自产国产一区| 国产精品久久久久影院老司| 亚洲欧美日韩成人高清在线一区| 一区二区三区四区蜜桃| 日韩国产欧美三级| 国产福利精品导航| 91久久精品一区二区二区| 欧美日韩不卡一区二区| 久久综合色鬼综合色| 亚洲三级在线看| 日本va欧美va欧美va精品| 国产成人综合网站| 欧洲视频一区二区| 日韩欧美国产wwwww| 中文字幕日韩欧美一区二区三区| 亚洲一区二区三区在线| 国产一区二区伦理片| 91美女蜜桃在线| www国产精品av| 亚洲一区二区三区四区中文字幕| 久久激情综合网| 在线观看日韩一区| 国产午夜精品在线观看| 日韩中文字幕1| 91在线精品一区二区|