📄 client.java__.htm
字号:
<html><head><title>src.zip - Client.java</title></head><body>
<script language="JavaScript">
function openwin(url)
{
window.open(url, 'ProgramSourceCode');
}
</script>
<textarea cols=105 rows=17>文件头:
import java.nio.*;
import java.nio.channels.*;
import java.net.*;
import java.io.*;
import java.nio.channels.spi.*;
import java.nio.charset.*;
import java.lang.*;
public class Client
{
public SocketChannel client = null;
public InetSocketAddress isa = null;
public RecvThread rt = null;
public Client()
{
}
public void makeConnection()
{
int result = 0;
try
{
client = SocketChannel.open();
isa = new InetSocketAddress("nicholson",4900);
client.connect(isa);
client.configureBlocking(false);
receiveMessage();
}
catch(UnknownHostException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
while ((result = sendMessage()) != -1)
{
}
try
{
client.close();
System.exit(0);
}
catch(IOException e)
{
e.printStackTrace();
}
}
public int sendMessage()
{
System.out.println("Inside SendMessage")</textarea><BR>
<table width=756 border=0>
<tr><td width=1 bgcolor=#B0B0B0></td><td>
<script type="text/javascript"><!--
google_ad_client = "pub-8055710228382273";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="0099118804";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "000000";
google_color_text = "333333";
google_color_url = "666666";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td>
<td width=15 bgcolor=#E4E0D8></td></tr></table>
<textarea cols=105 rows=12>文件尾:
= false;
}
public static void main(String args[])
{
Client cl = new Client();
cl.makeConnection();
}
public class RecvThread extends Thread
{
public SocketChannel sc = null;
public boolean val = true;
public RecvThread(String str,SocketChannel client)
{
super(str);
sc = client;
}
public void run() {
System.out.println("Inside receivemsg");
int nBytes = 0;
ByteBuffer buf = ByteBuffer.allocate(2048);
try
{
while (val)
{
while ( (nBytes = nBytes = client.read(buf)) > 0){
buf.flip();
Charset charset = Charset.forName("us-ascii");
CharsetDecoder decoder = charset.newDecoder();
CharBuffer charBuffer = decoder.decode(buf);
String result = charBuffer.toString();
System.out.println(result);
buf.flip();
}
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
}
</textarea><BR>
<a href=http://www.pudn.com><small><font color=#A0A0A0>程序员联合开发网</font></small></a> <a href="/downloads81\sourcecode\java\applet\game/detail312386.html"><small><font color=#A0A0A0>返回src.zip</font></small></a>
<a href="javascript:openwin('/view_src.asp?id=312386&f=Client.java');"><small><font color=#A00000>在线阅读整个文件</font></small></a>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -