Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have the following program written with VS2013: Imports System.Net Imports Sys

ID: 655980 • Letter: I

Question

I have the following program written with VS2013:

Imports System.Net
Imports System.Text
Imports System.Net.Sockets
Imports System.Threading

Public Class Form1
Dim udpClient As New UdpClient

Public receiningUdpClient As UdpClient
Public RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Public ThreadReceive As Thread
Public ReceivedMessage As String
' A Flag to check if a new message comes
Public Recieved As Boolean
Public ListenPort As Integer
Public run_thread As Boolean = True

Private Sub ReceiveMessages()
' Creates a UdpClient for rreading incoming data
Dim receivingUdpClient As New UdpClient(ListenPort)

' Loop forever in order to recieve messages from Internet
Do While run_thread
Try
' Blocks until a message returns on this socket from remote host
' Creates an IPEndPoint to record the IP address and port of the sender
' The IPEndPoint will allow you to read the datagrams sent from any source
Dim receiveBytes As [Byte]() = receivingUdpClient.Receive(RemoteIpEndPoint)
' Conevert the received message to human readable format
Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
' RemoteIpEndPoint is your buddy's IP address
ReceivedMessage = RemoteIpEndPoint.Address.ToString() + " says:" + returnData.ToString()
' A message is received to update the output
Me.Invalidate()
Catch e As Exception
ReceivedMessage = e.ToString()
Me.Invalidate()
End Try
Loop

End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
' We will update the list box only when a new message comes in
If (Recieved) Then
' rest the recieved message to false after we display it
Recieved = False
Conversation_ListBox.Items.Add(ReceivedMessage)
End If
End Sub

Private Sub Send_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send_Button.Click
Dim GLOIP As IPAddress
Dim GLOINTPORT As Integer
Dim bytCommand As Byte() = New Byte() {}

' Get Buddy's IP address
GLOIP = IPAddress.Parse(BuddyIPBox.Text)
' Default port is 12345
GLOINTPORT = BuddyPort.Text
' Connect
udpClient.Connect(GLOIP, GLOINTPORT)
' Get message from I say box, encode it
bytCommand = Encoding.ASCII.GetBytes(ISay_Box.Text)
' send
udpClient.Send(bytCommand, bytCommand.Length)
' add your message to the conversation box
Conversation_ListBox.Items.Add("I Say: " + ISay_Box.Text)
' Clear the I Say box
ISay_Box.Text = ""

End Sub

Private Sub Set_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Set_Button.Click
If (ListenPortBox.Text <> "") Then
ListenPort = ListenPortBox.Text
' Create a receive thread
ThreadReceive = New Thread(AddressOf ReceiveMessages)
Recieved = False
ThreadReceive.Start()
Set_Button.Enabled = False
Else
Conversation_ListBox.Items.Add("Must set proper listening port!!")
End If
End Sub
End Class

This program creates a basic instant chat messenger between 2 computers. For the second part I need to add an automatic response. SO that when computer1 says "Monkey" (or "monkey"), computer2 running this same program will respond automatically with "Banana". Can I at least get a push in the right direction?

Overall the keywords are: Monkey, Elephant, Flower, House, and Car. With the response being Banana, Mouse, Beautifull, Safe, and Fast.

I know there has got to be a simple solution, I am just not seeing it.

Thank you.

Buddy's IP Address: Buddy's Port: My Listening Port: Conversation Conversation List Box Set I say: Send

Explanation / Answer

We have to make change in form_paint method and send_button codding

public msg1 as string

Private Sub Send_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send_Button.Click
Dim GLOIP As IPAddress
Dim GLOINTPORT As Integer
Dim bytCommand As Byte() = New Byte() {}

' Get Buddy's IP address
GLOIP = IPAddress.Parse(BuddyIPBox.Text)
' Default port is 12345
GLOINTPORT = BuddyPort.Text
' Connect
udpClient.Connect(GLOIP, GLOINTPORT)
' Get message from I say box, encode it
bytCommand = Encoding.ASCII.GetBytes(ISay_Box.Text)
' send
udpClient.Send(bytCommand, bytCommand.Length)
' add your message to the conversation box
Conversation_ListBox.Items.Add("I Say: " + ISay_Box.Text)
' Clear the I Say box

msg1=ISay_Box.Text
ISay_Box.Text = ""

End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
' We will update the list box only when a new message comes in
If (Recieved) Then

    if msg1="Monkey" then

msg="Banana"
   else if msg1="Elephant" then
       msg = "Mouse"
   else if msg1="Flower" then
       msg="Beautiful"
   else if msg1="House" then
       msg="Safe"
   else if msg1 = "Car" then
       msg="Fast"
   else
       msg=ReceivedMessage
   end if


' rest the recieved message to false after we display it
Recieved = False
Conversation_ListBox.Items.Add(msg)
End If
End Sub