Socket Programming using c# with database

Socket programming is a way of connecting two nodes on a network to communicate with each other. One socket(node) listens on a particular port at an IP, while other socket reaches out to the other to form a connection.

Here I will make two application one for Server and another is Client Application.

Here I’m using visual studio 2008 and make Windows CE device application for client Application.here I’m using Windows CE Application because it will execute wifi barcode scanner device.

Prerequisite

Visual studio 2008 for Client Application windows CE Device

Visual Studio 2015 for Server Application.

Sql Server

Client Application

Process to create Windows CE device Application Click This Link

Go to solution Explorer -> Right Click on Project -> Add -> Windows Form .

Provide form Name as you want I have provided “checkconnection”  and design the form As –

Here I have taken four text box for enter server Application IP Address.

Two button one for Exit Application and another to text Connection and if connection Success then open Next Page.

In this application All data send and receive will work on byte Formate.

Complete Code of above Form are below –

Now create another Form As Form1 and design the Form As –

Here I have created two text box and one button to check login from database table.

Form1 Complete Code are below-

We can not directly execute our Application because I have develop as Windows CE Device Application.

Note – If you want to Execute Directly then you will have to Attached Device from your System.

OtherWise

build your Application and Go to your Exe Folder to execute your Application.

Now Execute your exe then window will open As-

 

Server Application

Open Visual studio 2015 and create Project.

Now Go to Solution Explorer -> Right Click on Project -> Add -> Window Form the Form will be Added

Design form As-

Here I have place a label so when I will execute this application IP Address will be display.

Same IP will write on Client TestConnection Form Textboxes to check Connection if Connection established then will be proceed for Next Page

In This form place timer Control form toolbox.

I have placed Timer control so my server application will execute continuous and if any request will come then start to perform action.

Write Connection in App.Config File As-

<connectionStrings>
    <add name="sqlconnection" connectionString="Data Source=DESKTOP-I6QIQ9N;Password=Shashi;User ID=sa;Database=Test_DB" providerName="System.Data.SqlClient"/>
  </connectionStrings>

 

Now Execute your Application then form will display As -

Sql server process

Open sql server create database and create table As-

CREATE TABLE [dbo].[tblUserMaster](

       [Id] [int] NULL,

       [UserName] [varchar](50) NULL,

       [Email] [varchar](50) NOT NULL,

       [Password] [varchar](50) NULL,

       [IsActive] [int] NULL,

 CONSTRAINT [PK_tblUserMaster] PRIMARY KEY CLUSTERED

)

Here I have created for demo purpose you can create as per your requirements

 

Testing Process screen shoot are below –

Click on connect Button then form will open As-

Here Enter your userId and Password and click on Login button then data will go to server Application method and their it will check from Database if success then return success message other wise not success. As below screen

Leave a Comment