(2005-01-26) (2005-01-26) (2005-02-27) PIC_SERVER (9) VB TCP/UDP Visual Basic Microsoft Winsock Control (MSWINSCK.OCX) UDP TCP Client Server Visual Basic UDP/TCP PIC_SERVER UDP/TCP 1. Microsoft Winsock Control Microsoft Winsock Control UDP(User Datagram Protocol) TCP(Transmission Control Protocol) UDP IP Port TCP UDP TCP timeout UDP TCP TCP Visual Basic Microsoft Winsock Control (MSWINSCK.OCX) UDP TCP (Properties) (Events) 1
(Methods) Client Server Microsoft Winsock Control VB 1 VB Microsoft Winsock Control 6.0 Microsoft Winsock Control 6.0 1(a). 2
1(b). Microsoft Winsock Control 6.0 3
1(c). Client/Server 2 (1) 2(a) Server Client Listen Client Client Connect Server (2) Server Client (Connection Request) Server Microsoft Winsock Control ConnectionRequest Accept Client 2(b) (3) 2(c) Client Server Client Server (SendData) Server Microsoft Winsock Control DataArrival GetData Client (4) 2(d) Server Client (Response) (3) 4
Client Connect Server Accept 2(a). Client Connect Server Accept 2(b). Client DataArrival SendData Server GetData 2(c). Client Server Client DataArrival GetData Server SendData 2(d). 2. VB UDP UDP UDP IP Port UDP VB UDP Client C:\YZ_PIC\Samples\pic_SERVER\VB\TCP_UDP\UDP_Client\UDP_Client.vbp Server C:\YZ_PIC\Samples\pic_SERVER\VB\TCP_UDP\UDP_Client\UDP_Server.vbp 5
2.1 Client Client 3 Host_IP Port Msg Server Send 1 Client 4 4 remote_udp_server_ip remote_port Msg Server_reply Command_button Send_button Winsock WskClient Protocal 1-sckUDPProtocol 3. Client 6
1. UDP_Client Form frmclient UDP_Client Frame Frame1 1 Host_IP 2 Port 3 Msg Msg Text Hi, there. remote_port Text 1055 remote_udp_server_ip Text 140.138.139.41 Server_reply Text CommandButton Send_button Send Winsock WskClient Protocol 1-sckUDPProtocol 4 Client Send_button (Send_button_Click()) WskClient.RemoteHost Winsock Client IP remote_udp_server_ip remote_udp_server_ip IP WskClient.RemotePort Winsock Client Port remote_port remote_port Port SendData Msg UDP_Client Microsoft Winsock Control DataArrival (WskClient_DataArrival()) strdata GetData strdata Server_reply 7
4. UDP_Client 2.2 Server Server 5 Local_IP Server IP Port Server Port Msg Client debug_info Update 2 Server 4 4 ServerIP ServerPort Msg debug_info Command_button Update_button Winsock WskServer Protocal 1-sckUDPProtocol 5. Server 8
2. UDP_Server Form frmserver UDP_Server Frame Frame1 CommandButton Winsock Text Text 1 Local_IP 2 Port 3 Msg debug_info Msg ServerIP Text 192.11.79.158 ServerPort Text 1055 Protocol Update_button Update WskServer 1-sckUDPProtocol 6 UDP_Server From_Load Server IP Update_button_Click Update_button_Click Update_button Microsoft Winsock Control Bind Server Port Msg debug_info msg_count Client Microsoft Winsock Control DataArrival (WskServer_DataArrival()) strdata GetData Msg debug_info Client Port SendData Client 9
6. UDP_Server 2.3 UDP C:\YZ_PIC\Samples\pic_SERVER\VB\TCP_UDP UDP_Client.exe UDP_Server.exe (IP:140.138.*.*) 7(a) 7(b) UDP_Client Host_IP (140.138.*.*) Port 1055 Msg Hi, there. Send IP Port Server UDP_Server Server IP Local_IP Port 1055 UDP_Server UDP_Client Msg UDP_Client UDP_Server Updata Msg debug_info UDP_Server msg_count 1 10
7(a). UDP_Client.exe UDP_Server.exe 7(b). UDP_Client UDP_Server 3. VB TCP TCP TCP Server Client 11
VB TCP Client C:\YZ_PIC\Samples\pic_SERVER\VB\TCP_UDP\TCP_Client\TCP_Client.vbp Server C:\YZ_PIC\Samples\pic_SERVER\VB\TCP_UDP\TCP_Server\TCP_Server.vbp 3.1 Client Client 8 Host_IP Port Msg Server Send Status Microsoft Winsock Control 6.0 Timer 3 Client 4 4 remote_ip remote_port Msg Message_from_Server Command_button Send_button Winsock WskClient Protocal 0-sckTCPProtocol Timer Timer1 8. Client 12
3. TCP_Client Form frmclient TCP_Client Frame Frame1 ClientStatus Not Connected 1 Host_IP 2 Port 3 Status : 4 Msg 5 Message_from_Server Text Msg Text Anybody home? remote_ip Text 140.138.139.41 remote_port Text 83 CommandButton Send_button Send Timer Timer1 Enable False Winsock WskClient Protocol 0-sckTCPProtocol 9 TCP_Client Send_button Timer1 3000ms Message_from_Server WskClient State 6 Server 6 Server IP Port WskClient_Connect ClientStatus Connecting 13
WskClient_Connect ClientStatus Connected. Msg Microsoft Winsock Control SendData Client DataArrival strdata GetData strdata Message_from_Server ClientStatus Disconnected. Timer1 Timer1_Timer Timer1 3000ms Server ClientStatus Not Connected. (MsgBox) Failed to send message in 3 sec. 9. TCP_Client 3.2 Server Client 10 Local_IP Server IP Port Server Port Msg Client 14
debug_info Update Status Microsoft Winsock Control 6.0 Timer 4 Server 4 4 ServerIP ServerPort Msg debug_info Command_button Update_button Winsock WskServer Protocal 0-sckTCPProtocol Timer Timer1 10. Server 15
4. TCP_Server Form frmserver TCP_Server Frame Frame1 1 Local_IP 2 Port 3 Status : 4 Msg ServerStatus Server is Idle debug_info Text Msg Text ServerIP Text 192.11.79.158 ServerPort Text 83 CommandButton Update_button Update Timer Timer1 Enable True Winsock WskServer Protocol 0-sckTCPProtocol 11 TCP_Client Server IP WskServer_Listen() WskServer_Listen() Timer1 Close Winsock LocalPort ServerPort IP Listen Client ServerStatus Listening... 16
Client Winsock ConnectionRequest Winsock State State sckconnected Server Client Server already connected! Close Accept Client ID ServerStatus connected Timer1 Timer1 10000ms debug_info Timer1 10000ms WskServer_Listen() (listen) Client Winsock DataArrival strdata GetData strdata Msg debug_info Client Port SendData Client Update Msg debug_info WskServer_Listen() (listen) 17
11. TCP_Server 3.3 TCP C:\YZ_PIC\Samples\pic_SERVER\VB\TCP_UDP TCP_Client.exe TCP_Server.exe (IP:140.138.*.*) 12(a) 18
TCP_Client Status Not Connected TCP_Server Status Listening 12(b) Client Server IP Port Send Msg Server TCP_Server Server IP Local_IP Port 83 TCP_Server TCP_Client Msg TCP_Client TCP_Server Updata Msg debug_info TCP_Server msg_count 1 12(c) TCP_Client IP TCP_Server 3 12(a). TCP_Client.exe TCP_Server.exe 19
12(b). TCP_Client TCP_Server 12(c). 4. TCP PIC_SERVER client Server PIC_SERVER PC UDP TCP C:\YZ_PIC\Samples\pic_SERVER\Beginner\ 20
ex_4_udp_client.c ex_5_udp_server.c ex_6_tcp_server.c ex_8_tcp_client.c VB PIC_SERVER Server PC client TCP PIC_SERVER C:\YZ_PIC\Samples\pic_SERVER\Beginner\ex_6_tcp_server.c PIC_SERVER ICP local TCP server port 3423 HTTP port 80 13 Client PC VB TCPclient.exe Host_IP Port pic_server IP local TCP server port PIC Msg I am superman Send PIC_SERVER TCP_Client 14 ex_6_tcp_server.c PIC C ex_6_tcp_server.c TCP call back callback_tcpclientdataarrival() client data callback VB TCP_Server.vbp Private Sub WskServer_DataArrival(ByVal bytestotal As Long) VB WskServer.GetData strdata WskServer.SendData (reply_msg) pic_server BIOS nic_getc nic_putc (byte) printf( nic_putc, ) call back callback_tcpserverdataarrival() callback_udpserverdataarrival() callback_udpclientdataarrival() VB VB PIC_SERVER VB UDP/TCP PIC_SERVER 21
13. PIC_SERVER 22
14. TCP_Client PIC_SERVER Port 80 Msg GET/index.htm PIC_SERVER TCP_Client 15 15. TCP_Client 23
6 UDP_Client.exe UDP_Server.exe TCP_Client.exe TCP_Server.exe (1) PC PC UDP PC (2) PC PC UDP PC (3) PC PC TCP PC (4) PC PC TCP PC (5) VB PC PC TCP_client PC TCP_server PC PC UDP PC (6) PC PIC_SERVER UDP TCP 2002 Visual Basic -TCP/IP Internet Programming 24