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
相关文档:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.spri ......
转自:http://dev.yesky.com/12/3067012.shtml
动态连接库的创建步骤:
一、创建Non-MFC DLL动态链接库
1、打开File —> New —> Project选项,选择Win32 Dynamic-Link Library —>sample project
—>工程名:DllDemo
2、新建一个.h文件DllDemo.h
以下是引用片段:
......
汉诺塔算法的递归与非递归的C以及C++源代码
By Minidxer | January 30, 2008
汉诺塔(又称河内塔)问题其实是印度的一个古老的传说。
开天辟地的神勃拉玛(和中国的盘古差不多的神吧)在一个庙里留下了三根金刚石的棒,第一根上面套着64个圆的金片,最大的一个在底下,其余一个比一个小,依次叠上 ......