当前位置: 技术问答>java相关
[诚送60分]何用Java 的socket 来实现服务器和客户端的图象交互传输,急盼!!!
来源: 互联网 发布时间:2015-06-10
本文导语: 如何用Java 的socket 来实现服务器和客户端的图象交互传输。 所谓图像交互指的是socket通信的双方互相发送图像信息和其他的消息。我不知道我说清楚了没有。请各位大侠快来帮帮我,我很着急。最好能有源代码。一...
如何用Java 的socket 来实现服务器和客户端的图象交互传输。
所谓图像交互指的是socket通信的双方互相发送图像信息和其他的消息。我不知道我说清楚了没有。请各位大侠快来帮帮我,我很着急。最好能有源代码。一定送分!!!
所谓图像交互指的是socket通信的双方互相发送图像信息和其他的消息。我不知道我说清楚了没有。请各位大侠快来帮帮我,我很着急。最好能有源代码。一定送分!!!
|
//package pSocket;
import java.io.*;
import java.net.*;
import java.util.Vector;
/**
*
*
*
*
*
* @author unascribed
* @version 1.0
*/
public class TestSocketServer
{
ServerSocket mServerSocket = null;
Socket mSocket = null;
public Vector mAllClientVector = new Vector(5,2);//´æ·ÅËùÓпͻ§¶ËÐÅÏ¢
public TestSocketServer()
{
try
{
mServerSocket = new ServerSocket(9009,15);
mSocket = mServerSocket.accept();
ReceiveClientThread rCT = new ReceiveClientThread(this,mSocket);
rCT.start();
}
catch(Exception eSocket)
{
}
}
public static void main(String [] args)
{
new TestSocketServer();
}
}
class ReceiveClientThread extends Thread
{
private TestSocketServer mTestSocketServer = null;
private Socket mSocket = null;
private boolean mRunning = true;
DataInputStream dis = null;
DataOutputStream dos = null;
Vector mVector = null;
public ReceiveClientThread(TestSocketServer pTestSocketServer,Socket pSocket)
{
this.mTestSocketServer = pTestSocketServer;
this.mSocket = pSocket;
}
public void run()
{
while(true)
{
if(!mRunning)
{
//ÔÚÄÚ´æÖÐɾ³ýÏàÓ¦µÄ¿Í»§¶ËÐÅÏ¢
break;
}
try
{
dis = new DataInputStream(mSocket.getInputStream());
ObjectInputStream ois = new ObjectInputStream(dis);
mVector = (Vector)ois.readObject();
for(int i = 0 ; i
import java.io.*;
import java.net.*;
import java.util.Vector;
/**
*
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @author unascribed
* @version 1.0
*/
public class TestSocketServer
{
ServerSocket mServerSocket = null;
Socket mSocket = null;
public Vector mAllClientVector = new Vector(5,2);//´æ·ÅËùÓпͻ§¶ËÐÅÏ¢
public TestSocketServer()
{
try
{
mServerSocket = new ServerSocket(9009,15);
mSocket = mServerSocket.accept();
ReceiveClientThread rCT = new ReceiveClientThread(this,mSocket);
rCT.start();
}
catch(Exception eSocket)
{
}
}
public static void main(String [] args)
{
new TestSocketServer();
}
}
class ReceiveClientThread extends Thread
{
private TestSocketServer mTestSocketServer = null;
private Socket mSocket = null;
private boolean mRunning = true;
DataInputStream dis = null;
DataOutputStream dos = null;
Vector mVector = null;
public ReceiveClientThread(TestSocketServer pTestSocketServer,Socket pSocket)
{
this.mTestSocketServer = pTestSocketServer;
this.mSocket = pSocket;
}
public void run()
{
while(true)
{
if(!mRunning)
{
//ÔÚÄÚ´æÖÐɾ³ýÏàÓ¦µÄ¿Í»§¶ËÐÅÏ¢
break;
}
try
{
dis = new DataInputStream(mSocket.getInputStream());
ObjectInputStream ois = new ObjectInputStream(dis);
mVector = (Vector)ois.readObject();
for(int i = 0 ; i