user.cs
资源名称:类似QQ聊天程序.rar [点击查看]
上传用户:yan_wy
上传日期:2007-06-09
资源大小:112k
文件大小:1k
源码类别:
ICQ/即时通讯
开发平台:
C#
- using System;
- using System.Net.Sockets;
- using System.IO;
- namespace qqserver
- {
- /// <summary>
- /// user 的摘要说明。
- /// </summary>
- public class user
- {
- public string id;
- int mima;
- string name;
- string jianjie;
- int state;
- string ip;
- string friends;
- Socket connection;
- System.Net.Sockets .NetworkStream socketstream;
- Form1 server;
- BinaryWriter writer;
- BinaryReader reader;
- public user(Socket socket,Form1 servervalue)
- {
- //
- // TODO: 在此处添加构造函数逻辑
- //
- mima=-1;
- name=null;
- jianjie=null;
- state=-1;
- ip=null;
- friends=null;
- connection=socket;
- server=servervalue;
- socketstream=new NetworkStream(connection);
- writer=new BinaryWriter (socketstream);
- reader=new BinaryReader(socketstream);
- }
- public void run()
- {
- id=reader.ReadString();
- this.server.richTextBox1.Text+="user"+id+"comingn";
- while(true)
- {
- string s1=reader.ReadString();
- string s2=reader.ReadString();
- string s3=reader.ReadString();
- this.server.richTextBox1.Text+=(s1+"n"+s2+"n"+s3+"n");
- foreach(user i in server.userlist)
- {
- if(i.id==s2)
- {
- i.sendmessage(s1);
- i.sendmessage(s2);
- i.sendmessage(s3);
- break;
- }
- }
- }
- }
- public int sendmessage(string a)
- {
- try
- {
- writer.Write(a);
- }
- catch(Exception e)
- {
- return 0;
- }
- return 1;
- }
- }
- }