Visual Basic 2010 Winsock 2010 Winsock Microsoft Winsock
Visual Basic 2010 Winsock이용
2010에서 Winsock 사용 • Microsoft Winsock Control Version 6. 0 설치 1. Libraryfiles. exe down 후 설치 (http: //www. ascentive. com/support/new/libraryfiles. exe) 2. 메뉴 도구 도구 상자 항목 선택에서 [다시설정] 눌러 초기화 3. 도구 상자 항목 선택 COM 구성요소 “Microsoft Win. Sock Control, version 6. 0″을 체크 4. 우측 도구상자 메뉴에 Winsock Control Icon이 보이게 된다. check Libraryfiles. exe 실행하여 MSWINSCK. OCX 설치후 다시 설정 눌러준다
Visual Basic Socket Programming • Ax. Winsock 사용
Ax. Winsock 사용 Public Class Form 1 Private Sub Form 1_Activated(By. Val sender As Object, By. Val e As System. Event. Args) Handles Me. Activated Text. Box 1. Focus() End Sub Private Sub Button 1_Click(By. Val sender As System. Object, By. Val e As System. Event. Args) Handles Button 1. Click On Error Go. To Connecterror If Text. Box 1. Text = "" Or Text. Box 2. Text = "" Or Text. Box 3. Text = "" Then Msg. Box("Enter ip, port, nickname", , "확인") Exit Sub End If Ax. Winsock 1. Connect(Text. Box 1. Text, Text. Box 2. Text) Exit Sub Connecterror: Msg. Box("Cant' connect " & Text. Box 1. Text, , "Connect error") End Sub Private Sub Text. Box 5_Key. Press(By. Val Key. Ascii As Integer) Dim str. Data As String If Key. Ascii = vb. Cr Then str. Data = "[" & Text. Box 3. Text & "]" & ": " & Text. Box 5. Text Ax. Winsock 1. Send. Data(str. Data) Text. Box 5. Selection. Start = 0 Text. Box 5. Selection. Length = Len(Text. Box 5. Text) End If End Sub Private Sub Button 2_Click(By. Val sender As System. Object, By. Val e As System. Event. Args) Handles Button 2. Click Ax. Winsock 1. Close() End Sub
Private Sub Ax. Winsock 1_Close. Event(By. Val sender As Object, By. Val e As System. Event. Args) Handles Ax. Winsock 1. Close. Event Msg. Box("서버로부터 접속이 끊어졌습니다. ") End Sub Private Sub Ax. Winsock 1_Connect. Event(By. Val sender As Object, By. Val e As System. Event. Args) Handles Ax. Winsock 1. Connect. Event Button 1. Text = "Connected" Button 1. Enabled = False Text. Box 5. Focus() Text. Box 4. Text = "Connected to " & Text. Box 1. Text End Sub Private Sub Ax. Winsock 1_Data. Arrival(By. Val sender As Object, By. Val e As Ax. MSWinsock. Lib. DMSWinsock. Control. Events_Data. Arrival. Event) Handles Ax. Winsock 1. Data. Arrival Dim str. Data As String Dim byte. Data() As Byte byte. Data = Nothing ' Warning을 없애기 위하여. . . Ax. Winsock 1. Get. Data(byte. Data) str. Data = System. Text. Encoding. ASCII. Get. String(byte. Data) Text. Box 4. Text = Text. Box 4. Text + vb. Cr. Lf + str. Data Text. Box 4. Selection. Start = Len(Text. Box 4. Text) End Sub Private Sub Text. Box 5_Got. Focus(By. Val sender As Object, By. Val e As System. Event. Args) Handles Text. Box 5. Got. Focus Text. Box 5. Selection. Start = 0 Text. Box 5. Selection. Length = Len(Text. Box 4. Text) End Sub Private Sub Text. Box 5_Key. Press(By. Val sender As Object, By. Val e As System. Windows. Forms. Key. Press. Event. Args) Handles Text. Box 5. Key. Press Dim str. Data As String If e. Key. Char = vb. Cr Then If Text. Box 5. Text = "exit" Then Button 2_Click(sender, e) 'exit End If str. Data = "[" & Text. Box 3. Text & "]" & ": " & Text. Box 5. Text Ax. Winsock 1. Send. Data(str. Data) Text. Box 5. Selection. Start = 0 Text. Box 5. Selection. Length = Len(Text. Box 5. Text) End If End Sub Private Sub Text. Box 3_Key. Press(By. Val sender As Object, By. Val e As System. Windows. Forms. Key. Press. Event. Args) Handles Text. Box 3. Key. Press If e. Key. Char = vb. Cr Then Button 1_Click(sender, e) End If End Sub End Class
- Slides: 5