使用java发送msn消息

本文介绍了一种使用Java实现MSN即时通讯的方法。通过创建Socket连接到MSN服务器,并发送特定格式的消息来完成登录、状态设置及消息发送等功能。文章详细展示了连接建立、身份验证及消息传递的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import java.net.URLEncoder;

public class MyMSN {

	public static void main(String[] args) throws Exception {
		String username = "fly.net.cn@126.com";
		String password = "";
		String remoteusername = "lzhfengyun@hotmail.com";
		String remoteusername2= "dongbin_23@hotmail.com";
		String instantmessage ="test";
		MSNServer server = new MSNServer(username, password);
		server.login();
		server.setStatus();
		server.send(remoteusername2, instantmessage);
		server.close();

	}
}
 
import java.io.*;
import java.net.*;
import java.util.*;
import java.security.*;
import javax.net.ssl.*;

public class MSNServer {
	public String username, password;
	private int command = 0;// ·ˮºÍ
	private String message;
	private Socket server;
	private PrintWriter out;
	private MSNFilterStream in;
	public String temp;
	private boolean flag ;

	public MSNServer(String username, String password) {
		this.username = username;
		this.password = password;
	}

	// µȂ¼
	public void login() throws Exception {
		server = new Socket("messenger.hotmail.com", 1863);
		server.setTrafficClass(0x10);
		out = new PrintWriter(server.getOutputStream(), true);
		in = new MSNFilterStream(new BufferedInputStream(server
				.getInputStream()));

		// ±¨¸琭өºÍ
		 message = "VER " + command + " MSN10 MSNP9 CVRO ";
		out.println(message);
		command++;
		temp = in.readLine();
		System.out.println(temp);

		// ±¨¸汾»�
		message = "CVR " + command
				+ " 0x0804 winnt 5.2 i386 MSNMSGR 7.5.0299 MSMSGS " + username
				+ " ";
		out.println(message);
		command++;
		temp = in.readLine();
		System.out.println(temp);

		// ͡½»µȂ¼ԃ»§Ļ
		message = "USR " + command + " TWN I " + username + " ";
		out.println(message);
		command++;
		temp = in.readLine();
		System.out.println(temp);

		// l½ӵ½ns·�
		StringTokenizer st = new StringTokenizer(temp);
		st.nextToken();
		st.nextToken();
		st.nextToken();
		String ns = st.nextToken();// NSµٖ·
		out.close();// ¹ر֓ꃓ·�٬½э
		in.close();
		server.close();
		String[] split = ns.split(":");
		server = new Socket(split[0], Integer.parseInt(split[1]));
		server.setTrafficClass(0x10);
		out = new PrintWriter(server.getOutputStream(), true);
		in = new MSNFilterStream(new BufferedInputStream(server
				.getInputStream()));
		message = "VER " + command + " MSN10 MSNP9 CVR0";
		command++;
		out.println(message);
		temp = in.readLine();
		System.out.println(temp);

		// ±¨¸汾»�
		message = "CVR " + command
				+ " 0x0804 winnt 5.2 i386 MSNMSGR 7.5.0299 MSMSGS " + username
				+ " ";
		out.println(message);
		command++;
		temp = in.readLine();

		// ·¢̍ԃ»§хϢ
		message = "USR " + command + " TWN I " + username + " ";
		out.println(message);
		command++;

		// £¡ҩ֤µȂ¼хϢ,˗Ј՚HTTPS¶˿ش43вnexus.passport.com·¢̍һ¸�ȫȳ£¬½«֋ºš¢Ĝëº̎S¸�һ³¤´®хϢ̍³
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值