引用 | 編輯
rockman326
2007-02-28 18:48 |
樓主
▼ |
||
x0
下面程式片段是Server端接收Client端的四則運算做處理之後再回傳Client端我想再做一個接收字串的值,類似聊天室的功能,之前都是卡在開始服務後就 沒有處理了,請問我應該怎麼做才能接收到Client端的字串值呢 try Log('開始服務'); while not self.Terminated do begin // 讀取 i:=uuTCPSocket.ReadData(FSocket,mStr,0,0,#13); if i<0 then begin Log('讀取失敗: '+uuTCPSocket.GetErrorStr(i)); exit; end; delete(mStr,1,1); // 處理 i:=0; j:=0; n1:=0; n2:=0; while true do begin j:=0; i:=Pos(& .. 訪客只能看到部份內容,免費 加入會員 x0
|
引用 | 編輯
cmovies
2007-03-01 00:28 |
1樓
▲ ▼ |
while true do
begin j:=0; i:=Pos('+',mStr); if i>0 then break; inc(j); i:=Pos('-',mStr); if i>0 then break; inc(j); i:=Pos('*',mStr); if i>0 then break; inc(j); i:=Pos('/',mStr); if i>0 then break; inc(j); end; 上面程式如果Client沒有送+-*/不就變成無限迴圈了嗎? 只要再加一個 break; 在 end; 就好了, 那麼字串就是 j=4 只是你輸入的字串不能包含 +-*/ 不然就變成計算了 x0 |
引用 | 編輯
rockman326
2007-03-02 12:28 |
2樓
▲ ▼ |
是的,Client端要送出+-*/ Server端才會處理,參數mStr是從Client端所得到的字串,目前字串已經能接收到了,卡在最後的"回覆"Log,請問要怎麼改才能將四則運算和接收訊息的Log分離呢?
x0 |
引用 | 編輯
rockman326
2007-03-02 16:46 |
4樓
▲ ▼ |
j=4會跳到else mRes:='ERROR'
我修改了一下原程式,請問如果POS第五行i:=Pos(' ',mStr); if i>0 then break;(這行是Client端接收到的字串),要怎麼修改才能跳到case j of 4: mRes:=mStr; 假設我從Client發了一個字串"How are you?"那麼"How are you?"這個字串就會存在mStr裡 x0 |
引用 | 編輯
rockman326
2007-03-02 18:16 |
5樓
▲ |
謝謝cmovies大大的回答,已解決,我再修改原程式
x0 |