Comments (6)
@hishambakr
do you use this library as client or server?
UDPClient(swift) --> connect--> java server
or java client -->connect--> UDPClient(swift) ?
from swiftsocket.
Thanks for reply,
I use library as server
java client -->connect--> UDPClient(swift)
I receive message but null.
I switched now to another library called "CocoaAsyncSocket" it is objective c but I used in in Swift and now I receive string message correctly
from swiftsocket.
@hishambakr thanks for your feedback, i will check it.
from swiftsocket.
Hi, i seemed to found a line of code that prevents UdpServer from working properly, in yudpsocket.c line 60:
memset( &serv_addr, '\0', sizeof(serv_addr));
here you are wiping out all the data in ser_addr, which makes the socket bind to an address of 0.0.0.0
UdpServer is working fine for me once i removed that line.
Thanks a lot for this library!
from swiftsocket.
Yeah got the same problem here. The tests even written (testudpserver, testudpclient) don't work.
@yamiyukiharu Looked that up and made a few adjustments to the "yudpsocket_server" function that made it work:
`
int yudpsocket_server(const char *addr,int port){
//create socket
int socketfd=socket(AF_INET, SOCK_DGRAM, 0);
int reuseon = 1;
int r = -1;
//bind
struct sockaddr_in serv_addr;
serv_addr.sin_len = sizeof(struct sockaddr_in);
serv_addr.sin_family = AF_INET;
if(addr == NULL ||
strlen(addr) == 0 ||
strcmp(addr, "loopback") == 0 ||
strcmp(addr, "127.0.0.1") == 0 ||
strcmp(addr, "localhost") == 0 ||
strcmp(addr, "255.255.255.255") == 0)
{
r = setsockopt( socketfd, SOL_SOCKET, SO_BROADCAST, &reuseon, sizeof(reuseon) );
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
}else{
r = setsockopt( socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon) );
serv_addr.sin_addr.s_addr = inet_addr(addr);
memset( &serv_addr, '\0', sizeof(serv_addr));
}
serv_addr.sin_port = htons(port);
if(r==-1){
return -1;
}
r=bind(socketfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
if(r==0){
return socketfd;
}else{
return -1;
}
}
`
from swiftsocket.
I can confirm the fix above works. @iain17 thanks!
from swiftsocket.
Related Issues (20)
- An existing connection was forcibly closed by the remote host
- How to listen the message from server
- Module compiled with Swift 5.1.3 cannot be imported by the Swift 5.2 HOT 3
- Build for macOSX error: SWIFT_VERSION '3.0' is unsupported HOT 5
- can you make it available for swift package manager? HOT 1
- CocoaPods
- Getting corrupted data in server side
- maximum concurrent open connections? HOT 2
- can I send message from TCPServer to client?
- SwiftSocket doesn't execute on iOS device HOT 1
- Semantic Issue
- how to set tcp_nodelay
- From real device cannot able to send bytes HOT 1
- how can i read data in string formate HOT 1
- [!] Unknown command: `SwiftSocket`
- If using DNS name, how to get the IP Address after using TCPClient?
- I don't understand the point of this library. HOT 3
- Package.swift has no Package.swift manifest for version 2.1.0 in https://github.com/swiftsocket/SwiftSocket
- Read Video file using TCPClient
- Privacy Manifest
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftsocket.