user.cs
资源名称:类似QQ聊天程序.rar [点击查看]
上传用户:yan_wy
上传日期:2007-06-09
资源大小:112k
文件大小:2k
源码类别:
ICQ/即时通讯
开发平台:
C#
- using System;
- using System.Windows .Forms ;
- using System.Net.Sockets;
- using System.IO;
- using System.Threading ;
- namespace qq
- {
- /// <summary>
- /// user 的摘要说明。
- /// </summary>
- public class user
- {
- System.Net .Sockets .TcpClient client;
- System.Net.Sockets .NetworkStream socketstream;
- Form1 server;
- BinaryWriter writer;
- BinaryReader reader;
- Thread outputThread;
- public int isline;
- public user(Form1 servervalue)
- {
- //
- // TODO: 在此处添加构造函数逻辑
- //
- try
- {
- server=servervalue;
- isline=1;
- client=new TcpClient (this.server.ip,5000);
- socketstream=client.GetStream();
- writer=new BinaryWriter (socketstream);
- reader=new BinaryReader(socketstream);
- this.outputThread =new Thread (new ThreadStart (run));
- outputThread.Start ();
- }
- catch(Exception ee)
- {
- MessageBox.Show(ee.ToString());
- isline=0;
- }
- }
- public void run()
- {
- while(true)
- {
- string s1=reader.ReadString();
- string s2=reader.ReadString();
- string s3=reader.ReadString();
- foreach(UserControl1 dt in server.userlist)
- {
- if(dt.uid==s1)
- {
- if(s3.Trim()=="上线通知")
- {
- dt.setm(0);
- dt.timer.Start();
- }
- else if(s3.Trim()=="下线通知")
- {
- dt.setm(2);
- }
- else if(s3.Trim()=="发送文件")
- {
- dt.setup();
- }
- else
- {
- dt.tempxiao+=(s3+"n");
- dt.xiaoxi=true;
- dt.timer.Start();
- }
- break;
- }
- }
- }
- }
- public void close()
- {
- writer.Close();
- reader.Close();
- this.socketstream.Close();
- this.client.Close();
- }
- public void startset()
- {
- writer.Write(server.userid);
- }
- public void sendmessage(string ab)
- {
- writer.Write(ab);
- }
- }
- }