1.跪求一个Java编写的聊天聊天多人聊天程序源代码
2.求聊天系统中客户端通信C/C++源代码!!网站网站!系统系统缠论中枢幅图公式源码
跪求一个Java编写的源码源码用多人聊天程序源代码
import java.io.InputStream;
import java.io.DataInputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.DataOutputStream;
import java.io.BufferedReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;
import java.util.Date;
class Server
{
public Server()
{
try
{
ServerSocket s=new ServerSocket();
Socket ss=s.accept();
OutputStream out=ss.getOutputStream();
DataOutputStream dout=new DataOutputStream(out);
InputStream in=ss.getInputStream();
DataInputStream din=new DataInputStream(in);
System.out.print(din.readUTF()+"!");
dout.writeUTF("你已经连接到服务器"+"\t"+"你的地址:"+ss.getInetAddress()+"\t"
+"你的链接端口:"+ss.getLocalPort()+"\n");
new ReadMessage(din).start();
new SendMessage(dout).start();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new Server();
}
}
//接受客户端信息
class ReadMessage extends Thread
{
private DataInputStream din;
public ReadMessage(DataInputStream din)
{
this.din=din;
}
public void run()
{
String str;
try
{
while (true)
{
str=din.readUTF();
System.out.println(new Date().toLocaleString()+"客户端说:"+str);
if (str.equals("bye"))
{
System.out.println("客户端下线!");
break;
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
// 发出服务器信息
class SendMessage extends Thread
{
private DataOutputStream dout;
public SendMessage(DataOutputStream dout)
{
this.dout=dout;
}
public void run()
{
InputStreamReader inr=new InputStreamReader(System.in);
BufferedReader buf=new BufferedReader(inr);
String str;
try
{
while(true)
{
str=buf.readLine();
dout.writeUTF(str);
if (str.equals("bye"))
{
System.out.println("服务器退出!聊天聊天91论坛源码");
System.exit(1);
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
import java.io.InputStream;
import java.io.DataInputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.DataOutputStream;
import java.io.BufferedReader;
import java.net.Socket;
import java.io.IOException;
import java.util.Date;
class Client
{
public Client()
{
try
{
Socket s=new Socket("..1.2",网站网站离线同步 源码);
InputStream in=s.getInputStream();
DataInputStream din=new DataInputStream(in);
OutputStream out=s.getOutputStream();
DataOutputStream dout=new DataOutputStream(out);
dout.writeUTF("服务器你好!我是系统系统客户端");
System.out.println(din.readUTF());
new Thread(new SenderMessage(dout)).start();
new Thread(new ReaderMessage(din)).start();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new Client();
}
}
class ReaderMessage implements Runnable
{
private DataInputStream din;
public ReaderMessage(DataInputStream din)
{
this.din=din;
}
public void run()
{
String str;
try
{
while(true)
{
str=din.readUTF();
System.out.println(new Date().toLocaleString()+"服务器说:"+str);
if (str.equals("bye"))
{
System.out.println("服务器已经关闭,此程序自动退出!源码源码用");
break;
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
class SenderMessage implements Runnable
{
private DataOutputStream dout;
public SenderMessage(DataOutputStream dout)
{
this.dout=dout;
}
public void run()
{
String str;
InputStreamReader inf=new InputStreamReader(System.in);
BufferedReader buf=new BufferedReader(inf);
try
{
while (true)
{
str=buf.readLine();
dout.writeUTF(str);
if (str.equals("bye"))
{
System.out.println("客户端自己退出!聊天聊天");
System.exit(1);
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
求聊天系统中客户端通信C/C++源代码!网站网站!系统系统!源码源码用
#include "stdafx.h"
#include <Winsock2.h>
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
#pragma comment (lib,聊天聊天皇冠足球 源码"ws2_.lib")
int _tmain(int argc, _TCHAR* argv[])
{
WORD wVersionRequested;//版本号
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 1 );//1.1版本的套接字
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return 0;
}//加载套接字库,加裁失败则返回
if ( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 1 ) {
WSACleanup( );
return 0;
}//如果不是网站网站1.1的则退出
SOCKET sockClient = socket(AF_INET,SOCK_STREAM,0);//创建socket SOCK_STREAM表示TCP
if (sockClient==INVALID_SOCKET)
{
cout<<"INVALID_SOCKET"<<endl;
}
SOCKADDR_IN addrClient; //设置相关地址结构
cout<<"ip"<<endl;
char ip[]=".0.0.1";
cin>>ip;
addrClient.sin_addr.s_addr=inet_addr(ip);
addrClient.sin_family=AF_INET;
addrClient.sin_port=htons();//设置server端端口号,你可以随便设置
//连接
int x=connect(sockClient,系统系统网校类 源码(SOCKADDR*)&addrClient,sizeof(SOCKADDR));
if (x==SOCKET_ERROR)
{
cout<<"连接出错"<<endl;
return 0;
}
while(1)
{
char ddb_send[]="\0";
cin>>ddb_send;
if (strcmp(ddb_send,"exit")==0)
break;
char * buf=ddb_send;
int y=send(sockClient,buf,,0);
if (y==SOCKET_ERROR)
cout<<"SOCKET_ERROR"<<endl;
}
closesocket(sockClient);//关闭
WSACleanup();
return 0;
}