非常感謝您,我現在已經實作了兩個socket同時發送,但是問題在于兩次read接收的字串都是buf,我如何寫一個邏輯將不同socket發送的字串保存在不同陣列里以后續呼叫呢?下面是我的接收塊代碼:
while (1)
{
ssize_t count;
char buf[2048];
count = read(events[i].data.fd, buf, sizeof buf);
printf("\n");
if (count == -1)
{
/* If errno == EAGAIN, that means we have read all
data. So go back to the main loop. */
if (errno != EAGAIN)
{
perror("read");
done = 1;
}
break;
}
else if (count == 0)
{
/* End of file. The remote has closed the
connection. */
done = 1;
break;
}
/* Write the buffer to standard output */
s = write(1, buf, count);
if (s == -1)
{
perror("write");
abort();
}
}
眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......
值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......