javaSocket客户端与C服务端通信
转自:http://hi.baidu.com/ssrt_hanbing/blog/item/62e3b934598eeb82a71e1238.html
通过高低位转换。
package com.commnt;
import java.net.*;
import java.io.*;
public class Client {
public String send(String address, int port, String str) {
OutputStream os = null;
DataInputStream is = null;
String look = "";
Socket socket = null;
try {
socket = new Socket(address, port);
os = socket.getOutputStream();
byte[] phone = new byte[str.length()];
phone = ByteUtil.StringtoBytes(phone, str);
os.write(phone);
os.flush();
is = new DataInputStream(socket.getInputStream());
byte[] phone1 = new byte[str.length()];
is.read(phone1);
String strBype = new String(phone1);
look = strBype.toString();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
close(socket, is, os);
}
return look;
}
public void close(Socket socket, DataInputStream is, OutputStream os) {
if (os != null)
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
if (is != null)
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
if (socket != null)
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public class ByteUtil
相关文档:
第二章 数据类型
一、数据类型分类
1 联合类型
2 函数类型
3 数量类型
3.1算术类型
① 基本数据类型
整型(包括char)
浮点型 ......
大家好,这里有IBM的三个长期需求:均是需要2年以上相关工作经验,其中Java以及Testing需要英语可以交流,C/Unix不需要语言。
Java 大连
描述:Java programming, knowledge in J2SE, SWT/JFace, XML. Eclipse programming, knowledge in eclipse architecture. Clear understanding of plugin development. Hands-on exp ......
extern是C/C++语言中表明函数和全局变量作用范围(可见性).
它告诉编译器,其声明的函数和变量可以在本模块或其它模块中使用。
1。对于extern变量来说,仅仅是一个变量的声明,其并不是在定义分配内存空间。如果该变量定义多次,会有连接错误
2。通常,在模块的头文件中对本模块提供给其它模块引用的函数和 ......
已经知道的,不说了...大家都知道的,可以问问,查查资料。这里又放些附加建议:
1.基本算数运算:
既然计算机里没有真正的整数,那么计算机里也没有真正的算数运算。
取值范围:
设a和b是两个占一样位宽的无符号整数,这种整数可取到最大值M ......