[诚送60分]何用Java 的socket 来实现服务器和客户端的图象交互传输,急盼!!! 源代码我没有,其实挺简单的,写一个服务器端用SOCKETSERVER,如果需要多线程,继承THREAD,客户端用SOCKET,然后连接服务器,服务器读入请求,发送图象数据,客户端接收,显示就可以了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把图象和其他信息,包成一个对象,然后就可以用objectoutputstream……但是可能图象大的时候有问题。 实现很简单把输入流存成一个jpg格式即可然后去读这个文件! 到 mb.yipsilon.com 里看看,那里有GIF和JPEG编码源代码。 mb.yipsilon.com 看过了,不是基于socket的,而且没有交互啊 //package pSocket;import java.io.*;import java.net.*;import java.util.Vector;/** * * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @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 < mVector.size(); i ++) { System.out.println(mSocket.getInetAddress().getHostAddress()+"Êä³ö£º" + (String)mVector.elementAt(i)); } //±£´æ¿Í»§¶ËÐÅÏ¢£º´æÈëÎļþ»òÁÙʱÄÚ´æÖÐ this.mTestSocketServer.mAllClientVector.addElement(mVector); //°ÑmAllClientVectorÖеÄËùÓÐÐÅÏ¢·µ»Ø¸ø¿Í»§¶Ë } catch(Exception iDios) { } } }} import java.io.*;import java.net.*;import java.util.Vector;public class TestSocketClient{ Socket mSocket = null; DataInputStream dis = null; DataOutputStream dos = null; Vector mVector = new Vector(5,1); public TestSocketClient(String [] args) { mVector.addElement("aa"); mVector.addElement("bb"); try { mSocket = new Socket("192.168.95.3",9009); dos = new DataOutputStream(mSocket.getOutputStream()); ObjectOutputStream oos = new ObjectOutputStream(dos); oos.writeObject(mVector); } catch(Exception eSocket) { } } public static void main(String [] args) { new TestSocketClient(args); }} sorry, my windows is english version, so the commentaries is wrong! java编程思想中的问题空间和问题空间元素,解空间怎么理解? 关于facade模式 关于weblogic日志的问题,急!!! 菜鸟求救GUI 怎样用16进制形式读取对象流 问下大家都是怎么避免书写错误的? utf8的编码问题,急.... 我的applet和socket结合的问题, 关于socket,请大牛们帮忙看一下。。。。 如何在java的程序中,调用其他的可执行文件? 一点感想 无聊 为了过四级 做点善事吧 散分
把输入流存成一个jpg格式即可
然后去读这个文件!
import java.net.*;
import java.util.Vector;/**
*
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @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 < mVector.size(); i ++)
{
System.out.println(mSocket.getInetAddress().getHostAddress()+"Êä³ö£º" + (String)mVector.elementAt(i));
}
//±£´æ¿Í»§¶ËÐÅÏ¢£º´æÈëÎļþ»òÁÙʱÄÚ´æÖÐ
this.mTestSocketServer.mAllClientVector.addElement(mVector);
//°ÑmAllClientVectorÖеÄËùÓÐÐÅÏ¢·µ»Ø¸ø¿Í»§¶Ë
}
catch(Exception iDios)
{
}
}
}}
import java.net.*;
import java.util.Vector;public class TestSocketClient
{
Socket mSocket = null;
DataInputStream dis = null;
DataOutputStream dos = null;
Vector mVector = new Vector(5,1);
public TestSocketClient(String [] args)
{
mVector.addElement("aa");
mVector.addElement("bb");
try
{
mSocket = new Socket("192.168.95.3",9009); dos = new DataOutputStream(mSocket.getOutputStream());
ObjectOutputStream oos = new ObjectOutputStream(dos);
oos.writeObject(mVector);
}
catch(Exception eSocket)
{
}
} public static void main(String [] args)
{ new TestSocketClient(args);
}
}