socket client 使用特定網絡卡

2021-10-04 03:12:00 字數 988 閱讀 7927

unix網路程式設計(卷1)

在多網絡卡的機器上,假設兩張網絡卡,分別連線到不同的區域網內,他們有不同的ip 

網絡卡1:192.168.1.100 

網絡卡2:10.101.151.100 

假設使用192.168.1.100執行connect(2)呼叫,則需要先進行bind(2)操作:

// error checking omitted for expository purposes

int sockfd = socket(af_inet, sock_stream, 0);

// bind to a specific network inte***ce (and optionally a specific local port)

struct sockaddr_in localaddr;

localaddr.sin_family = af_inet;

localaddr.sin_addr.s_addr = inet_addr("192.168.1.100");

localaddr.sin_port = 0; // any local port will do

bind(sockfd, (struct sockaddr *)&localaddr, sizeof(localaddr));

// connect to the remote server

struct sockaddr_in remoteaddr;

remoteaddr.sin_family = af_inet;

remoteaddr.sin_addr.s_addr = inet_addr(server_ip);

remoteaddr.sin_port = htons(server_port);

connect(sockfd, (struct sockaddr *)&remoteaddr, sizeof(remoteaddr));

android使用shape使元件呈現特殊效果

android radius 10dp android startcolor 33cc00 android endcolor 666600 android angle 45 android left 5dp android top 5dp android right 5dp android bott...

RecyclerView的特簡單使用 狸菇涼

recycleview的特簡單使用,資料是本地的 瀑布流 recyclerview 的使用 上拉重新整理,下拉載入更多 本地資料 分割線。public class mainactivity extends implements swiperefreshlayout.onrefreshlistener...

使用sklearn提取文字的tfidf特徵

from sklearn.feature extraction.text import countvectorizer,tfidfvectorizer,tfidftransformercorpus this is the first document.this is the second secon...