日期:2014-05-20  浏览次数:20672 次

求网络编程代码
需求1:用户注册功能,具体要求如下:
1)提示用户通过键盘输入信息:用户名,密码,email地址
2)将用户信息传送到服务器
3)服务器接受用户信息并写入到users.txt文件中
4)返回注册成功信息


------解决方案--------------------
client:
Java code

package com.cn.socket;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class TCPClient {
    public static void main(String[] args) throws UnknownHostException, IOException {
        String name;
        String password;
        String email;
        Scanner sc = new Scanner(System.in);
        System.out.println("输入name:");
        name = sc.nextLine();
        System.out.println("输入password");
        password = sc.nextLine();
        System.out.println("输入email");
        email = sc.nextLine();
        Socket s = new Socket("127.0.0.1", 4444);
        DataOutputStream dos = new DataOutputStream(s.getOutputStream());
        dos.writeUTF(name + "&" + password + "&" + email);
        s.close();
    }
}