JAVA 프로그램 호출 비 JAVA 프로그램-C 소스 코드(조작 목록),JAVA(서버)
4637 단어 자바
// NameCollector.java
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BSIZE 250 //
// email
int alreadyInList(FILE* list ,char* name){
char buf[BSIZE];// buf
fseek(list , 0 , SEEK_SET);//
// buf
while(fgets(buf , BSIZE , list)){
char * newline = strchr(buf,'
');//
if(newline != 0){
*newline = '\0';//
}
if(strcmp(buf,name) == 0){
return 1;
}
}
return 0;
}
//
int main(){
char buf[BSIZE];
FILE* list = fopen("emlist.txt","a+t");// ( )
if(list == 0){
perror("could not open emlist.txt");//
exit(1);
}
while(1){
gets(buf);// ( )
if(alreadyInList(list,buf)){
//
printf("Already in list:%s",buf);
fflush(stdout); //
}else{
fseek(list , 0 ,SEEK_END);//
fprintf(list,"%s
",buf);// email list
fflush(list);//
printf("%s added to list",buf);//
fflush(stdout); //
}
}
}
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
public class NameCollector {
public static final int COLLECTOR_PORT = 8080;//
public static final int BUFFER_SIZE = 1000;//
byte[] buf = new byte[BUFFER_SIZE];
DatagramPacket dbPacket = new DatagramPacket(buf, buf.length);// 1000
DatagramSocket socket;//
Process listmgr; //
PrintStream nameList;
DataInputStream addResult;
public NameCollector(){
/**
*
*/
try {
listmgr = Runtime.getRuntime().exec("listmgr.exe");//java , ---- c
nameList = new PrintStream(new BufferedOutputStream(listmgr.getOutputStream()));//
addResult = new DataInputStream(new BufferedInputStream(listmgr.getInputStream()));
} catch (Exception e) {
System.out.println("Can not start listmgr.exe");
e.printStackTrace();
System.exit(1);
}
/**
*
*/
try {
socket = new DatagramSocket(COLLECTOR_PORT);//
System.out.println("NameCollector Server started");
while(true){
socket.receive(dbPacket);//
String addStr = new String(dbPacket.getData(),0,dbPacket.getLength());
nameList.println(addStr);//
nameList.flush();// ( )
byte[] resultBuf = new byte[BUFFER_SIZE];
int byteCount = addResult.read(resultBuf);//
if(byteCount != -1){
String result = new String(resultBuf,0,resultBuf.length).trim();//
InetAddress senderAddress = dbPacket.getAddress();//
int senderPort = dbPacket.getPort();//
byte[] echoBuf = new byte[BUFFER_SIZE];
echoBuf = result.getBytes();//
DatagramPacket echo = new DatagramPacket(echoBuf, echoBuf.length,senderAddress,senderPort);//
socket.send(echo);//
}else{
System.out.println("Unexpected lack of result from" + "listmgr.exe");
}
}
} catch (SocketException e) {
System.out.println("Can not open socket");
System.exit(1);
}catch (IOException e) {
System.out.println("Coummunication error");
e.printStackTrace();
}
}
/**
*
* @param args
*/
public static void main(String[] args) {
new NameCollector();
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.