流套接字=通过服务器IP+port连接的通道 最直接用途传输单个 eg.Object.int.string等客户端 new DataOutputStream(socket.getOutputStream()).write(Object)//写入到流中 服务器端DataInputStream(ServerSocket.accept().getInputStream()).read();//接收数据 accept有点像迭代器简单的例子:/** *这里假设的例子是普通的登录功能 */ //客户端通过socket发送ID和pass Socket socket = new socket(ip,port); DataOutputStream dos=new DataOutputStream(socket.getOutputStream()); DataInputStream dis=new DataInputStream(socket.getInputStream()); dos.writeInt(ID); dos.writeUTF(pass); String Name = dis.readUTF();//读取 System.out.println(teamName); //服务器端返回用户名字 ServerSocket serverSocket=new ServerSocket(port);//服务器的监听端口 Socket socket = new Socket(); socket = serverSocket.accept();//accept()类似迭代器作用的获取 DataOutputStream dos=new DataOutputStream(socket.getOutputStream()); DataInputStream dis=new DataInputStream(socket.getInputStream()); int ID = dis.readInt(); String pass = dis.readUTF(); dos.writeUTF(Name);//name是数据库查询得到的结果
string input = "Hello World!"; char[] values = input.ToCharArray(); foreach (char letter in values) { // Get the integral value of the character. int value = Convert.ToInt32(letter); // Convert the decimal value to a hexadecimal value in string form. string hexOutput = String.Format("{0:X}", value); Console.WriteLine("Hexadecimal value of {0} is {1}", letter, hexOutput);
Socket socket = new socket(ip,port); 这边是错的吧,socket 没有这样的用法的
最直接用途传输单个 eg.Object.int.string等客户端 new DataOutputStream(socket.getOutputStream()).write(Object)//写入到流中 服务器端DataInputStream(ServerSocket.accept().getInputStream()).read();//接收数据 accept有点像迭代器简单的例子:/**
*这里假设的例子是普通的登录功能
*/
//客户端通过socket发送ID和pass
Socket socket = new socket(ip,port);
DataOutputStream dos=new DataOutputStream(socket.getOutputStream());
DataInputStream dis=new DataInputStream(socket.getInputStream());
dos.writeInt(ID);
dos.writeUTF(pass);
String Name = dis.readUTF();//读取
System.out.println(teamName);
//服务器端返回用户名字
ServerSocket serverSocket=new ServerSocket(port);//服务器的监听端口
Socket socket = new Socket();
socket = serverSocket.accept();//accept()类似迭代器作用的获取
DataOutputStream dos=new DataOutputStream(socket.getOutputStream());
DataInputStream dis=new DataInputStream(socket.getInputStream());
int ID = dis.readInt();
String pass = dis.readUTF();
dos.writeUTF(Name);//name是数据库查询得到的结果
string input = "Hello World!";
char[] values = input.ToCharArray();
foreach (char letter in values)
{
// Get the integral value of the character.
int value = Convert.ToInt32(letter);
// Convert the decimal value to a hexadecimal value in string form.
string hexOutput = String.Format("{0:X}", value);
Console.WriteLine("Hexadecimal value of {0} is {1}", letter, hexOutput);
这边是错的吧,socket 没有这样的用法的