VB.NET
* * Server 소스 *
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Winsock1.LocalPort = TextBox1.Text
Winsock1.Listen()
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent) Handles Winsock1.ConnectionRequest
Winsock1.Close()
Winsock1.Accept(e.requestID)
End Sub

Private Sub Winsock1_DataArrival(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles Winsock1.DataArrival
Dim data As String = ""
Dim opt() As String
Winsock1.GetData(data)
opt = Split(data, "||")

Select Case opt(0)
Case "connect"
Me.Text = "연결됨 !!"
Case "메세지"
MsgBox(opt(1), vbOKOnly, "Title")
End Select

End Sub
End Class


* Client 소스 *
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
On Error Resume Next
Winsock1.Close()
Winsock1.Connect("192.168.0.2", 1234)
End Sub

Private Sub Winsock1_ConnectEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles Winsock1.ConnectEvent
Me.Text = "연결 ! [192.168.0.2]"
Winsock1.SendData("connect" & "||")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
On Error Resume Next
Winsock1.SendData("메세지" & "||" & TextBox2.Text)
End Sub
End Class 

 

 

* Winsock을 사용한 간단한 연결및 메세지 전송 예제이다

* 소스에 오류가 있는데 해결해 보세요

 

1.png