線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1867
推到 Plurk!
推到 Facebook!

ServerSocket 如何得到client 送來的訊息且顯示訊息!

尚未結案
pyusi
一般會員


發表:6
回覆:2
積分:1
註冊:2004-10-22

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-10-29 10:34:52 IP:210.202.xxx.xxx 未訂閱
RaynorPao大哥及各位前輩你好: Environment:One PC is Linux to be client and one PC is MS Windows to be server.(only 1 to 1) Server UI有SDRAM,Flash等,當勾選SDRAM(In BCB using checkBOX)會送message給client,在client已有如下(最下面)的code做假回傳pass給server告知已test pass,server會show出test pass的message. 請問Server code需增加哪些完成: 1)Server /client create connection 2)Server send check item(SDRAM,etc) message to client //client message from server 3)Server get message and show 小妹我是BCB新手,發問蠢問題,敬請見諒。 感謝各位! Server code如下: //Server //-------------------------------------------------------------- void __fastcall TForm1::chkSDRAMClick(TObject *Sender) { int i=chkSDRAM->Checked; ServerSocket1->Port=9999; ServerSocket1->Active=true; } //--------------------------------------------------------------- void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender, TCustomWinSocket *Socket) { ediSDRAM->Text=Socket->ReceiveText(); //以下不確定 //int client_sockfd; //TransferProtocol pMSG; //String receive=client_sockfd, &pMSG, sizeof(TransferProtocol); //String receive=client_sockfd; //receive=Socket->ReceiveText(); } //------------------------------------------------------------------ //client..... int main( void ) { char Item; char YsNo; pid_t pid; int status,i; TransferProtocol pMSG; DiagStatusProtocol *pDiagBoard = &DiagBoard; clean(); openfb(); lcm_lineadd( 1,"Diag", C4 , 3, 0); display(); keypad_init(do_key); #if 1 client_sockfd=OpenSocket(); if ( client_sockfd == -1 ) { printf("\n open socket is error !!"); return -1; } pMSG.Msg = CLIENT_SAY_HELLO ; pMSG.BufSize = sizeof(DiagStatusProtocol); printf("\n Write Say Hello to server"); printf("\n socket fd : %d", client_sockfd); write( client_sockfd , &pMSG , 5 ); printf("\n Wait Read pkt .."); read( client_sockfd , &pMSG , sizeof(TransferProtocol) ); printf("\n read pkt complete !"); if ( pMSG.Msg == USER_DEF_DIAG ) { printf("\n Recv USR_DEF_DIAG"); //DumpBuf( &pMSG.buffer[0] , sizeof(DiagStatusProtocol) ); memcpy( pDiagBoard , &pMSG.buffer[0] , sizeof (DiagStatusProtocol) ); if ( pDiagBoard->SDRAM.EnableDiag == Enable ) pDiagBoard->SDRAM.Result = PASS; if ( pDiagBoard->FLASH.EnableDiag == Enable ) pDiagBoard->FLASH.Result = PASS; memcpy( &pMSG.buffer[0] , pDiagBoard , sizeof (DiagStatusProtocol) ); pMSG.Msg = USER_DEF_DIAG ; pMSG.BufSize = sizeof(DiagStatusProtocol); write( client_sockfd , &pMSG , sizeof (TransferProtocol) ); } close( client_sockfd ); //--------------------------------------------------
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-01 20:59:03 IP:211.20.xxx.xxx 未訂閱
引言: RaynorPao大哥及各位前輩你好: Environment:One PC is Linux to be client and one PC is MS Windows to be server.(only 1 to 1) Server UI有SDRAM,Flash等,當勾選SDRAM(In BCB using checkBOX)會送message給client,在client已有如下(最下面)的code做假回傳pass給server告知已test pass,server會show出test pass的message. 請問Server code需增加哪些完成: 1)Server /client create connection 2)Server send check item(SDRAM,etc) message to client //client message from server 3)Server get message and show 小妹我是BCB新手,發問蠢問題,敬請見諒。 感謝各位! Server code如下: //Server //-------------------------------------------------------------- void __fastcall TForm1::chkSDRAMClick(TObject *Sender) { int i=chkSDRAM->Checked; ServerSocket1->Port=9999; ServerSocket1->Active=true; } //--------------------------------------------------------------- void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender, TCustomWinSocket *Socket) { ediSDRAM->Text=Socket->ReceiveText(); //以下不確定 //int client_sockfd; //TransferProtocol pMSG; //String receive=client_sockfd, &pMSG, sizeof(TransferProtocol); //String receive=client_sockfd; //receive=Socket->ReceiveText(); } //------------------------------------------------------------------ //client..... int main( void ) { char Item; char YsNo; pid_t pid; int status,i; TransferProtocol pMSG; DiagStatusProtocol *pDiagBoard = &DiagBoard; clean(); openfb(); lcm_lineadd( 1,"Diag", C4 , 3, 0); display(); keypad_init(do_key); #if 1 client_sockfd=OpenSocket(); if ( client_sockfd == -1 ) { printf("\n open socket is error !!"); return -1; } pMSG.Msg = CLIENT_SAY_HELLO ; pMSG.BufSize = sizeof(DiagStatusProtocol); printf("\n Write Say Hello to server"); printf("\n socket fd : %d", client_sockfd); write( client_sockfd , &pMSG , 5 ); printf("\n Wait Read pkt .."); read( client_sockfd , &pMSG , sizeof(TransferProtocol) ); printf("\n read pkt complete !"); if ( pMSG.Msg == USER_DEF_DIAG ) { printf("\n Recv USR_DEF_DIAG"); //DumpBuf( &pMSG.buffer[0] , sizeof(DiagStatusProtocol) ); memcpy( pDiagBoard , &pMSG.buffer[0] , sizeof (DiagStatusProtocol) ); if ( pDiagBoard->SDRAM.EnableDiag == Enable ) pDiagBoard->SDRAM.Result = PASS; if ( pDiagBoard->FLASH.EnableDiag == Enable ) pDiagBoard->FLASH.Result = PASS; memcpy( &pMSG.buffer[0] , pDiagBoard , sizeof (DiagStatusProtocol) ); pMSG.Msg = USER_DEF_DIAG ; pMSG.BufSize = sizeof(DiagStatusProtocol); write( client_sockfd , &pMSG , sizeof (TransferProtocol) ); } close( client_sockfd ); //--------------------------------------------------
pyusi 你好:
(1)依照你的環境條件開來,Client/Server 分別執行在不同的作業系統
   (Windows/Linux)
(2)小弟我曾經寫過類似的應用程式,Server 端的程式在 Linux 執行,Client
   端的程式在 Windows 執行,而且這兩者都有做到 Multi-Thread,不過,我
   並不是使用 BCB 所提供的 ClientSocket/ServerSocket 元件來寫,而是使
   用最原始的 WinSock API 來寫這個程式
(3)有關這部分,我沒有辦法在此一步一步的教你如何去做,也只能夠建議你該
   去看哪些書,例如:
   (a)Winsock 網路程式設計之鑰 (黃俊堯,黃耀文,許景華,陳孝忠)
   (b)Microsoft Windows 網路程式設計 (Anthony Jones, Jim ohlund)
   (c)Linux C/C++ 網路程式設計 (金禾)
-- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
Eminem
一般會員


發表:0
回覆:4
積分:0
註冊:2004-12-03

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-12-03 10:18:36 IP:210.5.xxx.xxx 未訂閱
你不要用ReceiveText()来接受数据,用ReceiveBuf()来接受数据。 要不然,你再服务端里接受代码那里设一个断点,来调试。
Ktop_Robot
站務副站長


發表:0
回覆:3511
積分:0
註冊:2007-04-17

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-04-18 17:33:28 IP:000.000.xxx.xxx 未訂閱
提問者您好:


以上回應是否已得到滿意的答覆?


若已得到滿意的答覆,請在一週內結案,否則請在一週內回覆還有什麼未盡事宜,不然,
將由版主(尚無版主之區域將由副站長或站長)自由心證,選擇較合適之解答予以結案處理,
被選上之答題者同樣會有加分獎勵同時發問者將受到扣 1 分的處分。不便之處,請見諒。


有問有答有結案,才能有良性的互動,良好的討論環境需要大家共同維護,感謝您的配合。

------
我是機器人,我不接受簡訊.
系統時間:2024-05-05 23:12:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!