ServerSocket 如何得到client 送來的訊息且顯示訊息! |
尚未結案
|
pyusi
一般會員 發表:6 回覆:2 積分:1 註冊:2004-10-22 發送簡訊給我 |
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 發送簡訊給我 |
引言: 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 發送簡訊給我 |
|
Ktop_Robot
站務副站長 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |