This is the start of the server code

Similar documents
Classes in C# namespace classtest { public class myclass { public myclass() { } } }

The New Brew-CQ Synchronous Sockets and Threading

User-Defined Controls

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic

Tutorial 5 Completing the Inventory Application Introducing Programming

ListBox. Class ListBoxTest. Allows users to add and remove items from ListBox Uses event handlers to add to, remove from, and clear list

1. Windows Forms 2. Event-Handling Model 3. Basic Event Handling 4. Control Properties and Layout 5. Labels, TextBoxes and Buttons 6.

In order to create your proxy classes, we have provided a WSDL file. This can be located at the following URL:

Sub To Srt Converter. This is the source code of this program. It is made in C# with.net 2.0.

CALCULATOR APPLICATION

Lampiran B. Program pengendali

LISTING PROGRAM. //Find the maximum and minimum values in the array int maxvalue = integers[0]; //start with first element int minvalue = integers[0];

Inheriting Windows Forms with Visual C#.NET

Avoiding KeyStrokes in Windows Applications using C#

Blank Form. Industrial Programming. Discussion. First Form Code. Lecture 8: C# GUI Development

Your Company Name. Tel: Fax: Microsoft Visual Studio C# Project Source Code Output

namespace Tst_Form { private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components;

Web Services in.net (2)

C# and.net (1) cont d

Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects

CHAPTER 3. Writing Windows C# Programs. Objects in C#

Visual Studio Windows Form Application #1 Basic Form Properties

this.openfiledialog = new System.Windows.Forms.OpenFileDialog(); this.label4 = new System.Windows.Forms.Label(); this.

Convertor Binar -> Zecimal Rosu Alin, Calculatoare, An2 Mod de Functionare: Am creat un program, in Windows Form Application, care converteste un

Your Company Name. Tel: Fax: Microsoft Visual Studio C# Project Source Code Output

CIS 3260 Sample Final Exam Part II

and event handlers Murach's C# 2012, C6 2013, Mike Murach & Associates, Inc. Slide 1

Operatii pop si push-stiva

UNIT-3. Prepared by R.VINODINI 1

PS2 Random Walk Simulator

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at:

class Class1 { /// <summary> /// The main entry point for the application. /// </summary>

USB Logic Analyzer Shom Bandopadhaya Advisor: Dr. James H. Irwin

Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

SMITE API Developer Guide TABLE OF CONTENTS

if (say==0) { k.commandtext = "Insert into kullanici(k_adi,sifre) values('" + textbox3.text + "','" + textbox4.text + "')"; k.

Classes and Objects. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

CSIS 1624 CLASS TEST 6

UNIT III APPLICATION DEVELOPMENT ON.NET

Classes and Objects. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

Flag Quiz Application

Web Services in.net (7)

C:\homeworks\PenAttention_v13_src\PenAttention_v13_src\PenAttention4\PenAttention\PenAttention.cs 1 using System; 2 using System.Diagnostics; 3 using

Visual Basic/C# Programming (330)

Lucrare pentru colocviu de practică

XNA 4.0 RPG Tutorials. Part 11b. Game Editors

Web Services in.net (6) cont d

Main Game Code. //ok honestly im not sure, if i guess its a class ment for this page called methodtimer that //either uses the timer or set to timer..

CSC 330 Object-Oriented Programming. Encapsulation

#pragma comment(lib, "irrklang.lib") #include <windows.h> namespace SuperMetroidCraft {

Object oriented lab /second year / review/lecturer: yasmin maki

Class Test 4. Question 1. Use notepad to create a console application that displays a stick figure. See figure 1. Question 2

The Network. Multithreading. This tutorial can be found on -

BackgroundWorker Component Overview 1 Multithreading with the BackgroundWorker Component 3 Walkthrough Running an Operation in the Background 10 How

Start Visual Studio and create a new windows form application under C# programming language. Call this project YouTube Alarm Clock.

.NET XML Web Services

Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

Laboratorio di Ingegneria del Software

IBSDK Quick Start Tutorial for C# 2010

Laboratorio di Ingegneria del L-A

Brian Kiser November Vigilant C# 2.5. Commonwealth of Kentucky Frankfort, Kentucky

} } public void getir() { DataTable dt = vt.dtgetir("select* from stok order by stokadi");

Experiment 5 : Creating a Windows application to interface with 7-Segment LED display

CSC 211 Intermediate Programming

The contents of this document are directly taken from the EPiServer SDK. Please see the SDK for further technical information about EPiServer.

You can call the project anything you like I will be calling this one project slide show.

How to create a simple ASP.NET page to create/search data on baan using baan logic from the BOBS client sample.

First start a new Windows Form Application from C# and name it Interest Calculator. We need 3 text boxes. 4 labels. 1 button

Professional ASP.NET Web Services : Asynchronous Programming

DotNetProcessing Documentation

Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

The Payroll User Interface: MODEL VIEW PRESENTER

XNA 4.0 RPG Tutorials. Part 24. Level Editor Continued

Polymorphism. Polymorphism. CSC 330 Object Oriented Programming. What is Polymorphism? Why polymorphism? Class-Object to Base-Class.

LISTING PROGRAM. // // TODO: Add constructor code after the InitializeComponent()

Representing Recursive Relationships Using REP++ TreeView

Mainly three tables namely Teacher, Student and Class for small database of a school. are used. The snapshots of all three tables are shown below.

Click on the empty form and apply the following options to the properties Windows.

Visual Basic/C# Programming (330)

create database ABCD use ABCD create table bolumler ( bolumkodu int primary key, bolumadi varchar(20) )

Network Operation System. netstat. ipconfig/tracert/ping. nslookup EEE 448 Computer Networks

เว บแอพล เคช น. private void Back_Click(object sender, EventArgs e) { this.webbrowser2.goback(); }

Chapter 13 Working with Threads

Eyes of the Dragon - XNA Part 37 Map Editor Revisited

Writing Your First Autodesk Revit Model Review Plug-In

Huw Talliss Data Structures and Variables. Variables

Start Visual Studio, create a new project called Helicopter Game and press OK

Ether I/O 24 DIP R Datasheet

Start Visual Studio, start a new Windows Form project under the C# language, name the project BalloonPop MooICT and click OK.

Chapter 12 - Graphical User Interface Concepts: Part 1

Conventions in this tutorial

ETHER IO24 TCP DIP. Ether IO24 TCP DIP Datasheet. Module Features. Part Number: PRO EIO24 TCP DIP 2013 Elexol Pty Ltd Revision 1.5

Step 1: Start a GUI Project. Start->New Project->Visual C# ->Windows Forms Application. Name: Wack-A-Gopher. Step 2: Add Content

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer

Quick Guide for the ServoWorks.NET API 2010/7/13

string spath; string sedifile = "277_005010X228.X12"; string sseffile = "277_005010X228.SemRef.EVAL0.SEF";

JAYARAM. Department of Information Technology QUESTION BANK UNIT I BASICS OF C# Integer real single character string

Projects. Multiple Forms. Multiple forms. Part I. Multiple Forms

Arrays. Arrays: Declaration and Instantiation. Array: An Array of Simple Values

Chapter 12. Tool Strips, Status Strips, and Splitters

Transcription:

This is the start of the server code using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Net; using System.Net.Sockets; using System.Threading; using System.Text; namespace csharpserver / <summary> / Summary description for Form1. / </summary> public class Form1 : System.Windows.Forms.Form private System.Windows.Forms.ListBox conlist; private System.Windows.Forms.ListBox namelist; private System.Windows.Forms.Button exitbutton; / <summary> / Required designer variable. / </summary> private System.ComponentModel.Container components = null; public Form1() Required for Windows Form Designer support InitializeComponent(); TODO: Add any constructor code after InitializeComponent call / <summary> / Clean up any resources being used. / </summary> protected override void Dispose( bool disposing ) if( disposing )

if (components!= null) components.dispose(); base.dispose( disposing ); #region Windows Form Designer generated code / <summary> / Required method for Designer support - do not modify / the contents of this method with the code editor. / </summary> Thread listenthread; Thread[] clithread; int newcon; Socket[] ssock; Socket tcplist; private void InitializeComponent() this.conlist = new System.Windows.Forms.ListBox(); this.namelist = new System.Windows.Forms.ListBox(); this.exitbutton = new System.Windows.Forms.Button(); this.suspendlayout(); conlist this.conlist.items.addrange(new object[] "empty", 24); 24); 160); (152, 208); "empty"); this.conlist.location = new System.Drawing.Point(24, this.conlist.name = "conlist"; this.conlist.size = new System.Drawing.Size(160, 160); this.conlist.tabindex = 0; namelist this.namelist.location = new System.Drawing.Point(232, this.namelist.name = "namelist"; this.namelist.size = new System.Drawing.Size(176, this.namelist.tabindex = 1; exitbutton this.exitbutton.location = new System.Drawing.Point

this.exitbutton.name = "exitbutton"; this.exitbutton.size = new System.Drawing.Size(136, 40); this.exitbutton.tabindex = 2; this.exitbutton.text = "Exit"; this.exitbutton.click += new System.EventHandler (this.exitbutton_click); Form1 this.autoscalebasesize = new System.Drawing.Size(5, 13); this.clientsize = new System.Drawing.Size(440, 266); this.controls.addrange(new System.Windows.Forms.Control[] this.exitbutton, this.namelist, _Closing); this.conlist); this.name = "Form1"; this.text = "Form1"; this.load += new System.EventHandler(this.Form1_Load); this.closing += new CancelEventHandler(this.Form1 this.resumelayout(false); #endregion / <summary> / The main entry point for the application. / </summary> [STAThread] static void Main() Application.Run(new Form1()); private void Form1_Load(object sender, EventArgs e) int i; conlist.items.clear(); namelist.items.clear(); clithread = new Thread[50]; ssock = new Socket[50]; for (i=0;i<50;i++) conlist.items.add("no Connection"); namelist.items.add("");

(listenproc)); listenthread = new Thread(new ThreadStart listenthread.start(); private void Form1_Closing(object sender, CancelEventArgs e) int i; byte[] bytes; string byemessage; byemessage="bye@"; bytes=encoding.ascii.getbytes(byemessage); for (i=0;i<50;i++) if (namelist.items[i].tostring()!= "") ssock[i].send(bytes); clithread[i].abort(); tcplist.close(); listenthread.abort(); public void cliproc() int clientno; clientno = newcon; listenthread.resume(); string data,newdata; int bytesrec,dataptr; byte[] bytes; string towho,fromwho; string tempstring,message; int firstat,lendata,curlen,i; fromwho = namelist.items[clientno].tostring() + "@"; recvnext:

while(ssock[clientno].available == 0); bytesrec = ssock[clientno].receive(bytes); data = Encoding.ASCII.GetString(bytes); firstat = data.indexof("@"); tempstring = data.substring(0,firstat); lendata = Int32.Parse(tempstring); curlen = bytesrec; while (curlen<lendata) bytesrec = ssock[clientno].receive(bytes); data += Encoding.ASCII.GetString(bytes); curlen += bytesrec; dataptr = data.indexof("@",firstat+1); towho = data.substring(firstat+1,dataptr-firstat-1); if (towho=="bye") namelist.items.insert(clientno,""); namelist.items.removeat(clientno+1); conlist.items.insert(clientno,"no Connection"); conlist.items.removeat(clientno+1); data = "names@"; (); for (i=0;i<50;i++) if (namelist.items[i].tostring()!= "") data += namelist.items[i].tostring data += "@"; for (i=0;i<50;i++) if (namelist.items[i].tostring()!= "") ssock[i].send (Encoding.ASCII.GetBytes(data));

clithread[clientno].abort(); if (towho!= "bye") message = data.substring(dataptr+1,lendatadataptr-1); i = 0; while (namelist.items[i].tostring()!= towho) i++; newdata = fromwho + message; bytes = Encoding.ASCII.GetBytes(newdata); ssock[i].send(bytes); goto recvnext; public void listenproc() IPHostEntry iphostinfo = Dns.Resolve(Dns.GetHostName ()); IPAddress ipaddress = iphostinfo.addresslist[0]; IPEndPoint localendpoint = new IPEndPoint(ipAddress, 13); tcplist = new Socket (AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); keeplistening: tcplist.blocking=true; tcplist.bind(localendpoint); tcplist.listen(10); Connection") newcon=0; while( conlist.items[newcon].tostring()!= "No

; newcon++; ssock[newcon]=tcplist.accept(); conlist.items.remove(newcon); conlist.items.insert(newcon,((ipendpoint)ssock [newcon].remoteendpoint).address.tostring()); byte[] bytes; int bytesrec; string data; bytesrec = ssock[newcon].receive(bytes); data = Encoding.ASCII.GetString(bytes,0,bytesrec); namelist.items.remove(newcon); namelist.items.insert(newcon,data); int i; data = "names@"; for (i=0;i<50;i++) if (namelist.items[i].tostring()!= "") data += namelist.items[i].tostring()+"@"; bytes = Encoding.ASCII.GetBytes(data); for (i=0;i<50;i++) if (namelist.items[i].tostring()!= "") ssock[i].send(bytes); (cliproc)); clithread[newcon] = new Thread(new ThreadStart clithread[newcon].start(); listenthread.suspend(); goto keeplistening; private void exitbutton_click(object sender, System.EventArgs e)

int i; byte[] bytes; string byemessage; byemessage="bye@"; bytes=encoding.ascii.getbytes(byemessage); for (i=0;i<50;i++) if (namelist.items[i].tostring()!= "") ssock[i].send(bytes); clithread[i].abort(); tcplist.close(); listenthread.abort(); Application.Exit(); This is where the client code begins using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Net; using System.Net.Sockets; using System.Threading; using System.Text; namespace csharpclient

/ <summary> / Summary description for Form1. / </summary> public class Form1 : System.Windows.Forms.Form / <summary> / Required designer variable. / </summary> private System.ComponentModel.Container components = null; public Form1() Required for Windows Form Designer support InitializeComponent(); TODO: Add any constructor code after InitializeComponent call / <summary> / Clean up any resources being used. / </summary> protected override void Dispose( bool disposing ) if( disposing ) if (components!= null) components.dispose(); base.dispose( disposing ); #region Windows Form Designer generated code / <summary> / Required method for Designer support - do not modify / the contents of this method with the code editor. / </summary> / Socket csock; Thread recvthread; IPEndPoint endpoint; private System.Windows.Forms.TextBox yourname; private System.Windows.Forms.Button cbut; private System.Windows.Forms.TextBox sendbox; private System.Windows.Forms.Button sendbut;

private System.Windows.Forms.TextBox recbox; private System.Windows.Forms.ListBox theirnames; 40); private void InitializeComponent() this.yourname = new System.Windows.Forms.TextBox(); this.cbut = new System.Windows.Forms.Button(); this.sendbox = new System.Windows.Forms.TextBox(); this.sendbut = new System.Windows.Forms.Button(); this.recbox = new System.Windows.Forms.TextBox(); this.theirnames = new System.Windows.Forms.ListBox(); this.suspendlayout(); yourname this.yourname.location = new System.Drawing.Point(40, this.yourname.name = "yourname"; this.yourname.size = new System.Drawing.Size(248, 20); this.yourname.tabindex = 0; this.yourname.text = "bruce"; cbut this.cbut.location = new System.Drawing.Point(328, 32); this.cbut.name = "cbut"; this.cbut.size = new System.Drawing.Size(152, 48); this.cbut.tabindex = 1; this.cbut.text = "button1"; this.cbut.click += new System.EventHandler (this.cbut_click); sendbox this.sendbox.location = new System.Drawing.Point(24, 176); this.sendbox.multiline = true; this.sendbox.name = "sendbox"; this.sendbox.size = new System.Drawing.Size(512, 184); this.sendbox.tabindex = 2; this.sendbox.text = "textbox2"; sendbut this.sendbut.location = new System.Drawing.Point(32, 368); this.sendbut.name = "sendbut"; this.sendbut.size = new System.Drawing.Size(496, 32); this.sendbut.tabindex = 3; this.sendbut.text = "button2"; this.sendbut.click += new System.EventHandler (this.sendbut_click);

416); (32, 80); 56); recbox this.recbox.acceptsreturn = true; this.recbox.location = new System.Drawing.Point(32, this.recbox.multiline = true; this.recbox.name = "recbox"; this.recbox.size = new System.Drawing.Size(488, 184); this.recbox.tabindex = 4; this.recbox.text = "textbox3"; theirnames this.theirnames.location = new System.Drawing.Point this.theirnames.name = "theirnames"; this.theirnames.size = new System.Drawing.Size(272, this.theirnames.tabindex = 5; Form1 this.autoscalebasesize = new System.Drawing.Size(5, 13); this.clientsize = new System.Drawing.Size(568, 629); this.controls.addrange(new System.Windows.Forms.Control[] #endregion this.theirnames, this.recbox, this.sendbut, this.sendbox, this.cbut, this.yourname); this.name = "Form1"; this.text = "Form1"; this.load += new System.EventHandler(this.Form1_Load); this.resumelayout(false); / <summary> / The main entry point for the application. / </summary> [STAThread] static void Main()

Application.Run(new Form1()); private void Form1_Load(object sender, System.EventArgs e) cbut.text = "Connect"; yourname.text = "bruce"; recbox.text = ""; sendbox.text = ""; sendbut.text = "Send"; theirnames.items.clear(); endpoint = new IPEndPoint(Dns.Resolve ("Newdig1").AddressList[0],13); public void recvproc() int recbytes,tpoint,npoint; byte[] bytes; string data,tempstring,crstring; int atptr; byte[] cr; cr = new byte[2]; cr[0] = 10; cr[1] = 13; cr = Encoding.ASCII.GetBytes("\n"); crstring = Encoding.ASCII.GetString(cr); recvloop: while (csock.available==0); recbytes = csock.receive(bytes); data = Encoding.ASCII.GetString(bytes); atptr = data.indexof("@"); tempstring = data.substring(0,atptr); MessageBox.Show(data); if (tempstring == "names") tpoint = 6; theirnames.items.clear(); while (tpoint<recbytes)

- tpoint); endnameget: npoint = 1; npoint = data.indexof("@",tpoint+1); if (npoint == -1) tpoint = recbytes; goto recvloop; tempstring = data.substring(tpoint,npoint theirnames.items.add(tempstring); tpoint=npoint+1; goto recvloop; if (tempstring == "bye") MessageBox.Show("The Server has Left"); csock.shutdown(socketshutdown.both); csock.close(); theirnames.items.clear(); cbut.text = "Connect"; recvthread.abort(); if (tempstring!="bye" tempstring!="names") atptr = data.indexof("@"); tempstring = data.substring(0,atptr); "+tempstring+"\r\n"); recbox.appendtext("received from : tempstring = data.substring(atptr+1,recbytesatptr-1); recbox.appendtext(tempstring+"\r\n\r\n"); goto recvloop; private void cbut_click(object sender, System.EventArgs e) int recbytes; byte[] bytes; string data;

if (yourname.text == "") MessageBox.Show("You Must Specify a Username"); goto endcbutsub; if (cbut.text == "Connect") cbut.text = "Disconnect"; csock = new Socket (AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); csock.connect(endpoint); bytes = Encoding.ASCII.GetBytes(yourname.Text); csock.send(bytes); recvthread = new Thread(new ThreadStart (recvproc)); recvthread.isbackground = true; recvthread.start(); goto endcbutsub; if (cbut.text == "Disconnect") endcbutsub: data = "6@bye@"; bytes = Encoding.ASCII.GetBytes(data); csock.send(bytes); csock.shutdown(socketshutdown.both); cbut.text = "Connect"; recvthread.abort(); theirnames.items.clear(); ; MessageBox.Show("LOgged In"); e) private void sendbut_click(object sender, System.EventArgs string towho,lendata,message,data; int lenint; byte[] bytes; To"); if (theirnames.selectedindex == -1) MessageBox.Show("You Must Select a User to Send

goto endsend; towho = theirnames.items [theirnames.selectedindex].tostring()+"@"; message = towho+sendbox.text; lenint = message.length; if (lenint<7) lenint = lenint+2; goto nextstep; if (lenint<96 ) lenint = lenint+3; goto nextstep; if (lenint<995) lenint = lenint + 4; goto nextstep; nextstep: lendata = lenint.tostring()+"@"; data = lendata+message; MessageBox.Show(data); bytes = Encoding.ASCII.GetBytes(data); csock.send(bytes); endsend: ;