⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 telephoneteller.java

📁 这是一个用jsp+Oracle开发的联系人客户关系管理系统!
💻 JAVA
字号:
package com.ideas.communicate;

import java.net.*;
import java.io.*;
import com.ideas.util.Configuration;

/**
 *Tcp Protocol client
 */
public class TelephoneTeller {
  // private Socket clientsock;
  public static void send(String content) {
    Socket clientsock = null;
    try {
      InetAddress target = InetAddress.getByName(Configuration.
                                                 TelephoneTellerListenerAddress);
      clientsock = new Socket(target, Configuration.TelephoneTellerListenerPort);

    }
    catch (Exception e) {
      System.err.println("电话报警程序不能连接主机:" +
                         Configuration.TelephoneTellerListenerAddress + "/" +
                         Configuration.TelephoneTellerListenerPort);
      return;
    }
    try {
      DataOutputStream dos = new DataOutputStream(clientsock.getOutputStream());

      dos.write(content.getBytes());
      dos.close();
      clientsock.close();
      //System.out.println("电话报警消息发送成功,消息内容:"+content);

    }
    catch (Exception e) {
      System.err.println("报警消息发送失败");
      e.printStackTrace();
    }
  }

  public static void main(String[] args) {
    TelephoneTeller.send("{192.168.2.117}{rs6000}{101}{102}{103}{104}{201}{301}");
  }
}
/*UDP protocol client
  public class TelephoneTeller {
  private DatagramSocket teller;
  public TelephoneTeller() {
    try {
      teller = new DatagramSocket();
    }
    catch (SocketException se) {
      se.printStackTrace();
    }
  }
  public boolean send(String destaddress, int destport, String content) {
    boolean success = false;
    try {
      InetAddress target = InetAddress.getByName(destaddress);
      byte[] buffer;
      buffer = content.getBytes();
      DatagramPacket dgp = new DatagramPacket(buffer, buffer.length, target,
                                              10000);
      dgp.setPort(destport);
      teller.send(dgp);
      success = true;
    }
    catch (UnknownHostException uhe) {
      System.err.println("没有找到" + destaddress + "对应的主机!\n");
    }
    catch (IOException ioe) {
      ioe.printStackTrace();
    }
    return success;
  }
  public static void main(String args[]) {
    if (new TelephoneTeller().send("192.168.2.63", 5000, "Hello world!")) {
      System.out.println("success!");
    }
  }
 }*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -