帮忙写个socket客户端代码,要求能连接到Socks5代理服务器,服务器有用户名密码验证。

plplum 2010-01-29 05:16:57
帮忙写个socket客户端代码,要求能连接到Socks5代理服务器,服务器有用户名密码验证。
...全文
674 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hskire 2012-09-29
  • 打赏
  • 举报
回复
楼主,你找到问题解决方法没,,我也在郁闷这个
新手不懂怎么入手
plplum 2010-02-02
  • 打赏
  • 举报
回复

这里应该有密码验证的API。


[Quote=引用 11 楼 plplum 的回复:]
引用 10 楼 plplum 的回复:
我说的是  SOCKET5 , 是个代理服务器。


错了,是 Socks5 !

[/Quote]
plplum 2010-02-02
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 plplum 的回复:]
我说的是  SOCKET5 , 是个代理服务器。
[/Quote]

错了,是 Socks5 !
plplum 2010-02-02
  • 打赏
  • 举报
回复
我说的是 SOCKET5 , 是个代理服务器。
nicole3life 2010-02-02
  • 打赏
  • 举报
回复
这个代码是老师给我们的
已测试 好用
nicole3life 2010-02-01
  • 打赏
  • 举报
回复
先写一个空白文档

import java.util.*;
import java.io.*;
class Password implements java.io.Serializable{
String name;
String password;
public Password(){name = ""; password = "";}
public Password(String n, String p){
name = n;
password = p;
}
public boolean equals(Object p){
Password pw = (Password)p;
return name.equals(pw.name) && password.equals(pw.password);
}
public String toString(){
String s = name +" "+password;
return s;
}
}



import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;
class PasswordServer{
final static int portNum = 1234; // any number > 1024
final static int numThreads = 10;
static ExecutorService pool;
public static void main(String[] args){
ArrayList<Password> passwords = new ArrayList<Password>();
loadPasswords(passwords);
pool = Executors.newFixedThreadPool(numThreads);
System.out.print("Server running ...");
try{
ServerSocket servesock = new ServerSocket(portNum);
// for service requests on port portSqrt
while (true){
// wait for a service request on port portSqrt
Socket socket = servesock.accept();
// submit request to pool
pool.submit(new CheckPassword(socket,passwords));
}
}catch(IOException e){}
}






static void loadPasswords(ArrayList<Password> p){
String s;
StringTokenizer t;
try{
FileReader fr = new FileReader("Password.txt");
BufferedReader in = new BufferedReader(fr);
s = in.readLine();
while(s != null){
t = new StringTokenizer(s);
Password pWord = new Password(t.nextToken(),t.nextToken());
p.add(pWord);
s = in.readLine();
}
in.close();
}catch(IOException e){
System.out.println(e.getMessage());
}
}
}
class CheckPassword implements Runnable{
Socket socket;
ArrayList<Password> pWords;
public CheckPassword(Socket s, ArrayList<Password> p){
socket = s;
pWords = p;
}
public void run() {
try {
ObjectInputStream in =
new ObjectInputStream(socket.getInputStream());
DataOutputStream out =
new DataOutputStream(socket.getOutputStream());
Password pw = (Password)in.readObject();
if(pWords.contains(pw)) // password found
out.writeBoolean(true);
else
out.writeBoolean(false);
socket.close(); // close connection
}
catch (IOException e) {}
catch(ClassNotFoundException e1){}

}
}




import java.io.*;
import java.net.*;
import java.util.*;
class LoginPassword{
private final static int port = 1234;
public static void main(String args[]){
try{
Socket socket;
socket = new Socket(InetAddress.getLocalHost(),port);
DataInputStream in = new DataInputStream(socket.getInputStream());
ObjectOutputStream out = new
ObjectOutputStream(socket.getOutputStream());
// get user name and password
Scanner keyIn = new Scanner(System.in);
System.out.print("User name: ");
String user = keyIn.next();
System.out.print("Password: ");
String pw = keyIn.next();
Password pWord = new Password(user,pw);

//write object and flush any buffered data
out.writeObject(pWord);
out.flush();

// wait for reply from server
boolean valid = in.readBoolean();
if(valid)
System.out.println("Registered user");
else
System.out.println("Not registered");
socket.close();
in.close();
out.close();
}catch(IOException e){System.out.println(e);}
}
}



plplum 2010-02-01
  • 打赏
  • 举报
回复
咋没人回答呢??
小小都不懂 2010-02-01
  • 打赏
  • 举报
回复
楼上的代码有人测试了吗?
plplum 2010-01-30
  • 打赏
  • 举报
回复
???
Gen_Sun 2010-01-29
  • 打赏
  • 举报
回复
期待。。
plplum 2010-01-29
  • 打赏
  • 举报
回复
期待答案
小贝壳666 2010-01-29
  • 打赏
  • 举报
回复
深切关注此帖。。。

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧