HOME 首页
SERVICE 服务产品
XINMEITI 新媒体代运营
CASE 服务案例
NEWS 热点资讯
ABOUT 关于我们
CONTACT 联系我们
创意岭
让品牌有温度、有情感
专注品牌策划15年

    chatter和chat

    发布时间:2023-03-13 05:33:33     稿源: 创意岭    阅读: 139        问大家

    大家好!今天让创意岭的小编来大家介绍下关于chatter和chat的问题,以下是小编对此问题的归纳整理,让我们一起来看看吧。

    ChatGPT国内免费在线使用,能给你生成想要的原创文章、方案、文案、工作计划、工作报告、论文、代码、作文、做题和对话答疑等等

    你只需要给出你的关键词,它就能返回你想要的内容,越精准,写出的就越详细,有微信小程序端、在线网页版、PC客户端,官网:https://ai.de1919.com

    本文目录:

    chatter和chat

    一、JAVA聊天室 客户端 和 服务器 完整代码

    CS模式的QQ这是服务器:ChatServer.javaimport java.net.*;

    import java.io.*;

    public class ChatServer

    {

    final static int thePort=8189;

    ServerSocket theServer;

    ChatHandler[] chatters;

    int numbers=0;

    public static void main(String args[])

    {

    ChatServer app=new ChatServer();

    app.run();

    }

    public ChatServer()

    {

    try

    {

    theServer=new ServerSocket(thePort);

    chatters=new ChatHandler[10];

    }

    catch(IOException io){}

    }

    public void run()

    {

    try

    {

    System.out.println("服务器已经建立!");

    while(numbers<10)

    {

    Socket theSocket=theServer.accept();

    ChatHandler chatHandler=new ChatHandler(theSocket,this);

    chatters[numbers]=chatHandler;

    numbers++;

    }

    }catch(IOException io){}

    }

    public synchronized void removeConnectionList(ChatHandler c)

    {

    int index=0;

    for(int i=0;i<=numbers-1;i++)

    if(chatters[i]==c)index=i;

    for(int i=index;i<numbers-1;i++)

    chatters[i]=chatters[i+1];

    chatters[numbers-1]=null;

    numbers--;

    }

    public synchronized String returnUsernameList()

    {

    String line="";

    for(int i=0;i<=numbers-1;i++)

    line=line+chatters[i].user+":";

    return line;

    }

    public void broadcastMessage(String line)

    {

    System.out.println("发布信息:"+line);

    for(int i=0;i<=numbers-1;i++)

    chatters[i].sendMessage(line);

    }

    }====================================================这是客户端:ChatClient.javaimport java.awt.*;

    import java.awt.event.*;

    import javax.swing.*;

    import java.net.*;

    import java.io.*;

    public class ChatClient extends Thread implements ActionListener

    {

    JTextField messageField,IDField,ipField,portField;

    JTextArea message,users;

    JButton connect,disconnect;

    String user="";

    String userList[]=new String[10];

    Socket theSocket;

    BufferedReader in;

    PrintWriter out;

    boolean connected=false;

    Thread thread;

    public static void main(String args[])

    {

    JFrame frame=new JFrame("聊天室");

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ChatClient cc=new ChatClient();

    JPanel content=cc.createComponents();

    frame.getContentPane().add(content);

    frame.setSize(550,310);

    frame.setVisible(true);

    }

    public JPanel createComponents()

    {

    JPanel pane=new JPanel(new BorderLayout());

    message=new JTextArea(10,35);

    message.setEditable(false);

    JPanel paneMsg=new JPanel();

    paneMsg.setBorder(BorderFactory.createTitledBorder("聊天内容"));

    paneMsg.add(message);

    users=new JTextArea(10,10);

    JPanel listPanel=new JPanel();

    listPanel.setBorder(BorderFactory.createTitledBorder("在线用户:"));

    listPanel.add(users);

    messageField=new JTextField(50);

    IDField=new JTextField(5);

    ipField=new JTextField("LocalHost");

    portField=new JTextField("8189");

    connect=new JButton("连 接");

    disconnect=new JButton("断 开");

    disconnect.setEnabled(false);

    JPanel buttonPanel=new JPanel();

    buttonPanel.add(new Label("服务器IP:"));

    buttonPanel.add(ipField);

    buttonPanel.add(new Label("端口:"));buttonPanel.add(portField);

    buttonPanel.add(new Label("用户名:"));

    buttonPanel.add(IDField);

    buttonPanel.add(connect);

    buttonPanel.add(disconnect);

    pane.add(messageField,"South");

    pane.add(buttonPanel,"North");

    pane.add(paneMsg,"Center");

    pane.add(listPanel,"West");

    connect.addActionListener(this);

    disconnect.addActionListener(this);

    messageField.addActionListener(this);

    IDField.addActionListener(this);

    ipField.addActionListener(this);

    return pane;

    }

    public void actionPerformed(ActionEvent e)

    {

    if(e.getSource()==connect){

    user=IDField.getText();

    String ip=ipField.getText();

    int port =Integer.parseInt(portField.getText());

    if(!user.equals("")&&connectToServer(ip,port,user))

    {

    disconnect.setEnabled(true);

    connect.setEnabled(false);

    }

    }

    if(e.getSource()==disconnect)disconnectFromServer();

    if(e.getSource()==messageField)

    if(theSocket!=null)

    {

    out.println("MESSAGE:"+messageField.getText());

    messageField.setText("");

    }

    }

    public void disconnectFromServer()

    {

    if(theSocket!=null)

    {

    try

    {

    connected=false;

    out.println("LEAVE:"+user);

    disconnect.setEnabled(false);

    connect.setEnabled(true);

    thread=null;

    theSocket.close();

    }catch(IOException io){}

    theSocket=null;

    message.setText("");

    users.setText("");

    }

    }

    public boolean connectToServer(String ip,int port,String ID)

    {

    if(theSocket!=null)

    return false;

    try

    {

    theSocket=new Socket(ip,port);

    in=new BufferedReader(new InputStreamReader(theSocket.getInputStream()));

    out=new PrintWriter(new OutputStreamWriter(theSocket.getOutputStream()),true);

    out.println("USER:"+user);

    message.setText("");

    connected=true;

    thread=new Thread(this);

    thread.start();

    }catch(Exception e){return false;}

    return true;

    }

    public void extractMessage(String line)

    {

    System.out.println(line);

    Message messageline;

    messageline=new Message(line);

    if(messageline.isValid())

    {

    if(messageline.getType().equals("JOIN"))

    {

    user=messageline.getBody();

    message.append(user+"进入了聊天室\n");

    }

    else if(messageline.getType().equals("LIST"))

    updateList(messageline.getBody());

    else if(messageline.getType().equals("MESSAGE"))

    message.append(messageline.getBody()+"\n");

    else if(messageline.getType().equals("REMOVE"))

    message.append(messageline.getBody()+"离开了聊天室\n");

    }

    else

    message.append("出现问题:"+line+"\n");

    }

    public void updateList(String line)

    {

    users.setText("");

    String str=line;

    for(int i=0;i<10;i++)

    userList[i]="";

    int index=str.indexOf(":");

    int a=0;

    while(index!=-1){

    userList[a]=str.substring(0,index);

    str=str.substring(index+1);

    a++;

    index=str.indexOf(":");

    }

    for(int i=0;i<10;i++)

    users.append(userList[i]+"\n");

    }

    public void run(){

    try{

    String line="";

    while(connected && line!=null){

    line=in.readLine();

    if(line!=null) extractMessage(line);

    }

    }catch(IOException e){}

    }

    } =======================================================import java.net.*;

    import java.io.*;

    class ChatHandler extends Thread{

    Socket theSocket;

    BufferedReader in;

    PrintWriter out;

    int thePort;

    ChatServer parent;

    String user="";

    boolean disconnect=false;

    public ChatHandler(Socket socket,ChatServer parent){

    try{

    theSocket=socket;

    this.parent=parent;

    in=new BufferedReader(new InputStreamReader(theSocket.getInputStream()));

    out=new PrintWriter(new OutputStreamWriter(theSocket.getOutputStream()),true);

    thePort=theSocket.getPort();

    start();

    }catch(IOException io){}

    }

    public void sendMessage(String line){

    out.println(line);

    }

    public void setupUserName(String setname){

    user=setname;

    //System.out.print(user+"参加");

    parent.broadcastMessage("JOIN:"+user);

    }

    public void extractMessage(String line){

    Message messageline;

    messageline = new Message(line);

    if(messageline.isValid()){

    if(messageline.getType().equals("USER")){

    setupUserName(messageline.getBody());

    parent.broadcastMessage("LIST:"+parent.returnUsernameList());

    }

    else if(messageline.getType().equals("MESSAGE")){

    parent.broadcastMessage("MESSAGE:"+user+"说: "+messageline.getBody());

    }

    else if(messageline.getType().equals("LEAVE")){

    String c=disconnectClient();

    parent.broadcastMessage("REMOVE:"+c);

    parent.broadcastMessage("LIST:"+parent.returnUsernameList());

    }

    }

    else

    sendMessage("命令不存在!");

    }

    public String disconnectClient(){

    try{

    in.close();

    out.close();

    theSocket.close();

    parent.removeConnectionList(this);

    disconnect=true;

    }catch(Exception ex){}

    return user;

    }

    public void run(){

    String line,name;

    boolean valid=false;

    try{

    while((line=in.readLine())!=null){

    System.out.println("收到:"+line);

    extractMessage(line);

    }

    }catch(IOException io){}

    }

    }

    =========================================================

    Message.javapublic class Message{

    private String type;

    private String body;

    private boolean valid;

    public Message(String messageLine){

    valid=false;

    type=body=null;

    int pos=messageLine.indexOf(":");

    if(pos>=0){

    type=messageLine.substring(0,pos).toUpperCase();

    body=messageLine.substring(pos+1);

    valid=true;

    }

    }

    public Message(String type,String body){

    valid=true;

    this.type=type;

    this.body=body;

    }

    public String getType(){

    return type;

    }

    public String getBody(){

    return body;

    }

    public boolean isValid(){

    return valid;

    }

    } ==================================================共有4个文件,先运行服务段端。。。 这是我以前学的时候写过的!希望能帮的上你

    二、chatbar插件是不是看不到自己的话?

    你弄错聊天窗口了吧?分聊天窗口跟战斗信息窗口的……

    三、谢谢了!!!!我是真的解决不了!!我将书上的程序打上去的:::结果就这样了我就25分

    这个只是你的程序提示出错,跟系统没关系啊,建议你装一个MSDN,对着检查错误,C++里的各种错误提示都可以去网上找答案,方法很简单,把错误号就是 "ERROR C2653"然后注明你的语言种类,丢在搜索引擎里搜下,看看别人遇到你这样的错误怎么解决的,挨个儿来就行了,编程很需要耐心的,当然不能看到这么多错误就吓到了。

    四、他有时和我一起玩游戏或讲笑话逗我笑。 译英语

    请采纳我的问题 1、一个女生前一天晚上得到男朋友的订婚戒指,但竟没有一个同学注意到,令她忿忿不平。到下午大家坐着谈天的时候,她突然站起来大声说:“哎呀,这里真热呀,我看我还是把戒指脱下来吧。”2、女主人把女佣叫到面前问她:“你是否怀孕了?”“是啊!”女佣回道。“亏你还说得出口,你还没有结婚,难道不觉得害羞吗?”女主人再次训。“我为什么要害羞,女主人你自己不也怀孕了吗?”“可是我怀的是我丈夫的!”女主人生气地反驳。“我也是啊!”女佣高兴地附和。3、一个人骑摩托车喜欢反穿衣服,就是把口子在后面扣上,可以挡风。一天他酒后驾驶, 翻了,一头栽在路旁。警察赶到:警察甲:好严重的车祸。警察乙:是啊,脑袋都撞到后面去了。警察甲:嗯,还有呼吸,我们帮他把头转回来吧。警察乙:好.....一、二使劲,转回来了。警察甲:嗯,没有呼吸了.......4、在一条七拐八拐的乡村公路上,因为时常发生车祸,所以常常有一些鬼故事发生,有一天晚上,有一个出租车司机看见路边有一个长发披肩,身着白衣的女人向他招手,因为这个司机没有见过鬼,所以大胆的停下来让她上车了,这一路上,司机虽然不信有鬼,心里也毛毛的,所以时常从后视镜看后面的女人,开着开着,突然司机发现那个女人不见了!司机吓了一大跳,赶紧踩了一个刹车!只见那个女人满脸是血,表情狰狞。司机吓的牙直打颤。突然那女人开口了:“你会不会开车啊!我低头系个鞋带你突然一刹车我把鼻子都撞破了……”5、一个病人去看病,医生检查了他,皱着眉头说:“您病得太严重了,恐怕不会活多久了。” 病人:“求您告诉我我还能活多久?” 医生:“十……” 病人着急地问:“十什么?十年??十个月???十天?????” 医生:“十,九,八,七,六,五……”6、老师:“你能说一些18世纪科学家共同特点吗?”学生:“能,他们都死了。”7、犀粪蜣和蚊子谈恋爱,蜣问蚊子是做什么工作的,蚊子说:“护士,打针的。”蜣一拍大腿:“缘分呐,我是中药局搓药丸的…”8、一非洲人住在某一宾馆。夜半,起火,不明原因。非洲人见状顾不了那么许多,光着身子就跑出去了。消防员见状惊呼:“我的妈呀!都烧的糊了吧区的了还能跑那么快!”9、一个人想出国考察,但必须得到老总批准。于是他向老总请示,老总给了他一张字条,上面写着:“Go ahead”。 那人想:“Go ahead=前进,老总是批准了。”于是他开始打点行李。 一个同事见到了他问:“你在做什啊??”他说:“我准备出国考察,老总批准了,给我写了‘Go ahead’。” 同事一见条就乐了:“咱们老总根本就没批准!!咱老总的英语水平你还不知道,他这是在说去个头!”10、牧师对买了他马和马车的农夫说:“这匹马只能听懂教会的语言,叫"感谢上帝"它就跑;叫"赞美上帝"它才停下。”农夫将信将疑,他试着喊了一声感谢上帝,那匹马立刻飞奔起来,越跑越快。一只跑到悬崖边上惊恐的农夫才想起让它停下来的口令“赞美上帝”。果然,马停下来了。死里逃生的农夫长出一口气:“感谢上帝………”我打了很久,请采纳1 the night before, a girl get boyfriend engagement ring, but no one noticed the classmate, make her antics. You sit and chat in the afternoon, she suddenly stood up and shouted: \"oh, it's really hot in here, I think I'd better take off your ring.\" 2, the mistress called the maid to ask her: \"are you pregnant?\" \"Yes!\" The maid answered. Export \"kui you still say, you are not married, don't you feel shy?\" The hostess training again. \"Why should I be shy, you don't the hostess also pregnant?\" \"But I conceive is my husband!\" The hostess retorted angrily. \"Me too!\" The maid happy to echo. 3, a man riding a motorcycle like the dress, is to cut on the back, can the wind. Drunk driving one day, he turned over, a planted on the road. Police: police a: a good serious car accident. Policeman b: yes, his head hit the back. Po1: well, still breathing, let's help him turn his head back. Po2: good... One, two, turn back. Policeman a: well, not breathing... 4, turn in a curvy country road, because often in a car accident, so often have some ghost story, one night, there's a taxi driver saw the side of the road have a long hair shawls, dressed in a white woman waved to him, because the driver didn't see a ghost, so bold stopped to let her get on the bus, along the way, the driver doesn't believe in ghosts, the in the mind also maomao, so often the woman behind the rearview mirror to see, open open, the driver found the woman suddenly disappeared! The driver startled, hurriedly stepped on a brake! I saw the woman face is blood, grim expression. The driver frighten of teeth chatter. Suddenly the woman spoke: \"would you drive! I bow to fasten shoelaces are you smashed through a sudden brake my nose...\" 5, a patient to see a doctor, the doctor examined him, frowning said: \"you too serious ill, I'm afraid I won't live much longer.\" Patient: \"please tell me how long will I live?\" Doctor: \"ten...\" Patient anxiously asked: \"what? Ten years?? Ten months??? Ten days?????\" Doctor: \"ten, nine, eight, seven, six, five...\" 6, teacher: \"can you say some 18 th-century scientists common characteristics?\" Student: \"yes, they are all dead.\" 7, rhino poop Qiang and mosquito fall in love, Qiang asked a mosquito is to do what work, the mosquito said: \"nurse, give or take an injection.\" Qiang a clap a thigh: \"the fate, I am a traditional Chinese medicine bureau rub pills...\" 8, the africans live in a hotel. In the midnight, a fire, unknown reason. Before rushing so many africans, naked and ran out. Firefighters said exclaimed: \"my mama ah! All paste the burned area can run so fast!\" 9, a person wants to go abroad, but it must be approved by boss. So he to the manager for instructions, the boss gave him a note, it read: \"Go ahead\". The man thought, \"Go ahead = progress, boss is approved.\" So he started to packing. A colleague to see he asked: \"what are you doing?\" He said: \"I'm ready to Go abroad investigation, boss approved, wrote me 'Go ahead'.\" Colleague of joy at the sight of article: \"let's boss haven't approved!!!!! Our boss English don't you know, he is said to head!\" 10, priests to buy his horse and carriage of the farmer said, \"this horse can only understand the language of the church, call\" thank god \"it ran; called\" praise god \"it didn't stop.\" Farmer track, he tried to thank god gave a cry, the horse gallop, immediately ran faster and faster. A run to the edge of the cliff frightened farmer remembered that let it stop password \"praise god\". Sure enough, the horse stopped. Close the farmer grows a sigh: \"thank god.........\"I played for a long time, please

    以上就是关于chatter和chat相关问题的回答。希望能帮到你,如有更多相关问题,您也可以联系我们的客服进行咨询,客服也会为您讲解更多精彩的知识和内容。


    推荐阅读:

    ChatGPT缺点

    ChatGPT写论文怎么样

    chatGPT如何下载安装(chat怎么下载)_1

    直播带货的平台(直播卖货平台)

    声控主播文案(声控主播文案是读书吗)