Socket Programming in ASP.Net using C#

// This a class having two metnods 1) Server 2)Client

// You Should both the method for get request and Sent response

// This is a Server Part

///Create Server For Socket Programming

This code use to create server in Socket Programming.

private static void Server()
{
try
{
String str = "";
TcpListener clientListener;
#region TcpServer Code
try
{
clientListener = new TcpListener(9060);
clientListener.Start();


if (!clientListener.Pending())
{
Socket mySocket = clientListener.AcceptSocket();
Byte[] recieveBuff = new Byte[255];
try
{
mySocket.Receive(recieveBuff, recieveBuff.Length, SocketFlags.None);
str = System.Text.Encoding.ASCII.GetString(recieveBuff, 0, recieveBuff.Length).Trim();
GlobleProperty.GetValueForServer += str;
}
catch (Exception ex)
{
str = ".";
}
clientListener.Stop();
mySocket.Disconnect(true);

}
clientListener.Stop();


}
catch (Exception ex)
{
//MessageBox.Show("not Find a new Connection", ex.Message);


}
#endregion
}
catch (Exception e)
{
}
}


If you many system connected in tcp/Ip Socket programming then we use this function to handle the many request.

public static void CallServer()
{
try
{
Thread newthread = new Thread(new ThreadStart(Server));
newthread.Start();

}
catch (Exception e)
{
MessageBox.Show(e.Message);

}

}

//Socket Client Code For Socket Programing


This code use to send to any string type data to another system which is connected through Socket programing.
public static string Client(string textvalue)

try
{

TcpClient serverListener;
DataSet ds = new DataSet();
cls_connection Con = new cls_connection();
//DataSet ds1 = new DataSet();
//ds1 = Con.select_with_SP("Get_Next_IP");
////GlobleProperty.NextIP =
string SelectQuery = "Select MemberSoftwareId from Table_status where TableId=1";
ds = Con.select_data_ds(SelectQuery);
if (ds.Tables[0].Rows.Count > 0)
{
int count = ds.Tables[0].Rows.Count;
for (int i = 0; i < ab =" Convert.ToString(ds.Tables[0].Rows[i][" serverlistener =" new" readstream =" serverListener.GetStream();" sendbuffersize =" 1;" str =" textvalue;" str =" str" str =" str" sendbuff =" System.Text.Encoding.ASCII.GetBytes(str);" str =" textvalue;" showcards = "N" id="gwProxy" type="hidden">

0 comments:

Check internet connection in your system

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.NetworkInformation;

namespace demoConnection
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void timer1_Tick(object sender, EventArgs e)
{
bool test = IsConnectedToInternet();
if (test == true)
{
label1.Text = " Connected";
}
else
{
label1.Text = "Not Connected";
}
}

private bool IsConnectedToInternet()
{
string host = "http://www.c-sharpcorner.com";
bool result = false;
Ping p = new Ping();
try
{
PingReply reply = p.Send(host, 3000);
if (reply.Status == IPStatus.Success)
return true;
}
catch { }
return result;
}
}
}

0 comments:

Upload Image into Target folder in Web application

===This C# Code is for Up load File in to specific Folder===
using System.IO; //Name Space is used


string image;

image = System.IO.Path.GetExtension(FileUpload2.FileName);

if (image == ".jpg" || image == ".jpeg" || image == ".JPG" || image == ".JPEG" || image == ".gif" || image == ".GIF")
{
FileUpload2.SaveAs(MapPath("~/Item_Picture/" + Add_Id.ToString() + ".jpg"));
string fn = "~/Item_Picture/" + System.IO.Path.GetFileName("~/Item_Picture/" + Add_Id.ToString() + ".jpg"); //Item_Picture is a folder in root

try
{
con.insert_data("insert into tbl_item values(" + Add_Id + ",'" + fn + "','" + txt_details.Text + "')");
//Image1.ImageUrl = fn;
txt_details.Text = "";
gridbing();
RMG.Functions.MsgBox("Added Successfully!!!");
}
catch (Exception ex)
{
}

=== HOPE IT HELP U -Raj

0 comments:

Sand SMS form any Web Site

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



// This are the name spaces We Are Used
using TestWeb;
using System.IO;
using System.Net.Mail;
using System.Web.Services;
using System.Net;

// SMS Method We ar Used

private void send_SMS()
{
string smsMessage = "Dear Customer," + "\r";
smsMessage += "Welcome to Rajesh Blog" + "\r";
smsMessage += "Your-UserID:" 123 "\r";
smsMessage += "Your-Password:"123"\r";
smsMessage += "Have a Nice Day!!!!";


string MobileNo = txt_telephone.Text.Trim(); // This is a text box having Phone No.
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
WebClient client = new WebClient();

if (MobileNo != "")
{
string baseurl = "http://sms.demo.in/demosms.phpusername=DEMO&password=DEMO&sender=TEST&to=" + MobileNo + "&message=" + smsMessage + ""; // This is a link to of SMS account (API) you have to purchase this account for sand SMS
Stream data = client.OpenRead(baseurl);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
}
}


// HOPE THIS WILL HELP YOU ,HAVE A NICE DAY - Raj
=======================================================

0 comments:

Microsoft Certified Technology Specialist.

MCTS stands for Microsoft Certified Technology Specialist.

Demonstrate your specialized technical expertise with a Microsoft Certified Technology Specialist (MCTS) certification. By earning this certification, you can prove your ability to successfully implement, build on, troubleshoot, and debug a particular Microsoft technology, such as a Windows operating system, Microsoft Exchange Server, Microsoft SQL Server, and Microsoft Visual Studio.
Level:
One or more years of experience implementing, troubleshooting, and debugging a specific technology
Audience:
IT professional
Type:
Microsoft Certification

It has sever papers,

Web based application(70-528)
Windows based application(70-526)
Web service (70-529)
SQL Server 2005(70-431)

just check the listed links by Microsoft 

0 comments: