Java Socket Udp协议实时在线云消费机服务器端开发示例,本示例展示了Java监听UDP通讯端口,向端口发送信息,只需在本示例上加上数据库的增、删、查、改等操作就可快速完成实时一卡通消费系统。
package ChatRoomTCPQQ聊天室; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; import java.net.UnknownHostException; import javax.swing.JOptionPane; public class ChatRoomClent { private Socket s; public ChatRoomClent(String host,int port){ try { s=new Socket(host,port); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void sendMessage(String str){ PrintWriter pw=null; try { pw=new PrintWriter(s.getOutputStream()); pw.println(str); pw.flush(); } catch (IOException e) { e.printStackTrace(); } } public String reciveMessage(){ BufferedReader br=null; String str=""; try { br=new BufferedReader(new InputStreamReader(s.getInputStream())); str = br.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return str; } }
2019-12-21 22:09:31 15KB SocketTCP javaSocket java javaQQ聊天室 javaQQ
1