Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TCP/IP server and client
#2
Is there a way for the server to output the content that is send from the client.
To be more specific, if the CLIENT sends the string "test" to the SERVER, then let the SERVER render a messagebox with contents "test" if the received string is "test".

SERVER CODE
Function dialog_TcpSocket_server
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

#compile "__TcpSocket"

str controls = "5 15"
str e5por e15res
e5por=5033
e15res="from server"
if(!ShowDialog("dialog_TcpSocket_server" &dialog_TcpSocket_server &controls win("" "QM_Editor"))) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 231 64 "TCP server"
;4 Static 0x54000000 0x0 170 8 22 12 "Port"
;5 Edit 0x54032000 0x200 196 6 32 14 "port"
;6 Button 0x54032000 0x0 6 6 48 14 "Start"
;7 Button 0x5C032000 0x0 58 6 48 14 "Stop"
;14 Static 0x54000000 0x0 6 30 36 12 "Response"
;15 Edit 0x54231044 0x200 46 28 182 30 "res"
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "*" "" ""

ret
;messages
TcpSocket- t_server
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,t_server.Close
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 6 ;;Start
,t_server.ServerStart(GetDlgItemInt(hDlg 5 0 0) &test_TcpSocket_func2 hDlg 1)
,EnableWindow lParam 0
,EnableWindow id(7 hDlg) 1
,
,case 7 ;;Stop
,t_server.Close
,EnableWindow lParam 0
,EnableWindow id(6 hDlg) 1
ret 1

err+ out _error.description


CLIENT CODE
Function dialog_TcpSocket_client
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

#compile "__TcpSocket"

str controls = "5 10 12"
str e5por e10ser e12dat
e5por=5033
e10ser="localhost"
e12dat="from client"
if(!ShowDialog("dialog_TcpSocket_client" &dialog_TcpSocket_client &controls win("" "QM_Editor"))) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 231 74 "TCP client"
;4 Static 0x54000000 0x0 170 8 22 12 "Port"
;5 Edit 0x54032000 0x200 196 6 32 14 "port"
;9 Static 0x54000000 0x0 4 6 26 13 "Server"
;10 Edit 0x54030080 0x200 32 4 124 14 "server"
;11 Static 0x54000000 0x0 4 26 26 13 "Data"
;12 Edit 0x54231044 0x200 32 22 196 30 "data"
;13 Button 0x54032000 0x0 4 56 48 14 "Send"
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "*" "" ""

ret
;messages
TcpSocket- t_server
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 13 ;;Send
,TcpSocket x.ClientConnect(_s.getwintext(id(10 hDlg)) GetDlgItemInt(hDlg 5 0 0))
,x.Send(_s.getwintext(id(12 hDlg)))
,if(x.Receive(_s 1000 1000)=2 and !_s.len) _s="<timeout>"
,out F"client: {_s}"
ret 1

err+ out _error.description


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)