Changeset 3907 in Sophya for trunk/AddOn/TAcq/swrapsock.cc
- Timestamp:
- Nov 5, 2010, 7:58:07 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/AddOn/TAcq/swrapsock.cc
r3897 r3907 166 166 : Socket() 167 167 { 168 Initialize(NULL, port, nconmax); 169 } 170 171 /* --Methode-- */ 172 ServerSocket::ServerSocket(const char* inadr, int port, int nconmax) 173 : Socket() 174 { 175 Initialize(inadr, port, nconmax); 176 } 177 178 /* --Methode-- */ 179 ServerSocket::ServerSocket(string const& inadr, int port, int nconmax) 180 : Socket() 181 { 182 Initialize(inadr.c_str(), port, nconmax); 183 } 184 185 186 /* --Methode-- */ 187 void ServerSocket::Initialize(const char* str_inadr, int port, int nconmax) 188 { 168 189 int s,rc; 169 190 s = socket(AF_INET, SOCK_STREAM, 0); 170 191 if (s < 0) { 171 cout << "ServerSocket () Pb socket()ErrNo=" << errno << endl;172 throw SocketException("ServerSocket () Pb socket()");192 cout << "ServerSocket::Initialize() Pb socketErrNo=" << errno << endl; 193 throw SocketException("ServerSocket::Initialize() Pb socket()"); 173 194 } 174 195 skt = s; … … 180 201 ipskt.sin_family = AF_INET; 181 202 ipskt.sin_port = htons(port); 182 ipskt.sin_addr.s_addr = INADDR_ANY; 203 if (str_inadr==NULL) { // pas d'adresse IP specifie 204 ipskt.sin_addr.s_addr = INADDR_ANY; 205 } 206 else { // adresse IP specifie sous la forme uuu.xxx.yyy.zzz. 207 ipskt.sin_addr.s_addr = inet_addr(str_inadr); 208 } 183 209 /* Je fais un cast explicit de sockaddr_in * (Internet) en sockaddr * */ 184 210 rc = bind(skt, (struct sockaddr *)(&ipskt), sizeof(ipskt)); 185 211 if (rc < 0) { 186 212 Close(); 187 cout << "ServerSocket () Pb bind() ErrNo=" << errno << endl;188 throw SocketException("ServerSocket () Pb bind()");213 cout << "ServerSocket::Initialize() Pb bind() ErrNo=" << errno << endl; 214 throw SocketException("ServerSocket::Initialize() Pb bind()"); 189 215 } 190 216 }
Note:
See TracChangeset
for help on using the changeset viewer.