You are on page 1of 10

E_Mail Application Using Windows

Socket Programming
Aim:-
To develop a visual basic program to perform an “E_Mail Application
Using Socket Control”.

Algorithm:-

Server:-

Step1: Winsocket & Data control is placed in the client and the server.
Step2: Winsocket just connect client and server machine using accept request -
method.
Step3: Here the local port number is specified and port wait for the response -
from client.
Step4: Here send data method is used to send data to the specified port and get-
data from the client.

Client:-

Step1: The name of the Remote Host should be specified.


Step2: By checking connet,the connection is established b/w server and the -
client.
Step3: Send Data ,Add New ,Update are as same as that used in server machine
to reciver.
E_Mail Application Using Windows
Socket Programming

Name :
Reg.No:
Sec :’B’

Source Code:-

Server Side:-

Private Sub CmdInbox_Click()


Info.Show
End Sub

Private Sub CmdSend_Click()


If SckServer.State = sckConnected Then
SckServer.SendData Text1.Text
vkListBox1.AddItem SckServer.RemoteHost & " Says: " & Text1.Text
Data1.Recordset.AddNew
Data1.Recordset.Fields(0) = Text1.Text
Data1.Recordset.Fields(1) = vkTextBox1.Text
Data1.Recordset.Fields(2) = vkTextBox3.Text
Data1.Recordset.Update
Text1.Text = ""
End If
End Sub

Private Sub vkTimer1_Timer()


vkTextBox1.Text = Format(Now, "dd-mm-yyyy")
vkTextBox3.Text = Time
End Sub
Private Sub Form_Load()
If App.PrevInstance Then End
Listen
End Sub

Private Sub Form_Unload(Cancel As Integer)


SckServer.Close
End Sub

Private Sub SckServer_Close()


If SckServer.State <> sckclose Then
SckServer.Close
Listen
End If
End Sub

Private Sub sckServer_ConnectionRequest(ByVal requestID As Long)


If SckServer.State <> sckClosed Then
SckServer.Close
End If
SckServer.Accept (requestID)
vkListBox1.AddItem "Connected"
End Sub

Private Sub sckServer_DataArrival(ByVal bytesTotal As Long)


Dim StrData As String
Dim Login As String
Dim Tim As String
Tim = Time
SckServer.GetData StrData
Login = Left$(StrData, 5)
LogName = Mid$(StrData, 6)
Select Case StrData
Case "Time!"
vkListBox1.AddItem Time
SckServer.SendData Tim

Case Else
vkListBox1.AddItem SckServer.RemoteHostIP & " Says: " & StrData
End Select
End Sub

Sub Listen()
SckServer.Close
SckServer.LocalPort = 1025
SckServer.Listen
vkListBox1.AddItem "Disconnected"
End Sub

Private Sub Txt1_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then
CmdSend_Click
KeyAscii = 0
End If
End Sub

Client Side:-

Private Sub CmdClear_Click()


Text1.Text = ""
Text1.SetFocus
End Sub

Private Sub CmdConnect_Click()


Winsock1.Close
Winsock1.RemoteHost = "192.168.1.10"
Winsock1.RemotePort = 1025
Winsock1.Connect
CmdConnect.Enabled = False
End Sub
Private Sub CmdDisConnect_Click()
Winsock1.Close
vkListBox1.AddItem "Logged Out"
End Sub

Private Sub CmdInbox_Click()


Info.Show
End Sub

Private Sub CmdSend_Click()


If Winsock1.State = sckConnected Then
Winsock1.SendData Text1.Text
vkListBox1.AddItem Winsock1.RemoteHost & " Says: " & Text1.Text
Data1.Recordset.AddNew
Data1.Recordset.Fields(0) = Text1.Text
Data1.Recordset.Fields(1) = vkTextBox1.Text
Data1.Recordset.Fields(2) = vkTextBox3.Text
Data1.Recordset.Update
Text1.Text = ""
End If
End Sub

Private Sub Form_Load()


Client.Show
If App.PrevInstance Then End
End Sub

Private Sub vkTimer1_Timer()


vkTextBox1.Text = Format(Now, "dd-mm-yyyy")
vkTextBox3.Text = Time
End Sub

Private Sub Winsock1_Close()


vkListBox1.AddItem "Logged Out"
End Sub

Private Sub Winsock1_Connect()


vkListBox1.AddItem "Logged In"
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)


Dim X As String
Winsock1.GetData X
vkListBox1.AddItem Winsock1.RemoteHostIP & " Says: " & X
End Sub
OutPut:-

Server Output:-
Client Output:-
Result:-

You might also like