Giter Club home page Giter Club logo

Comments (6)

pengyunchou avatar pengyunchou commented on May 19, 2024

@hishambakr
do you use this library as client or server?
UDPClient(swift) --> connect--> java server
or java client -->connect--> UDPClient(swift) ?

from swiftsocket.

 avatar commented on May 19, 2024

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.

pengyunchou avatar pengyunchou commented on May 19, 2024

@hishambakr thanks for your feedback, i will check it.

from swiftsocket.

yamiyukiharu avatar yamiyukiharu commented on May 19, 2024

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.

iain17 avatar iain17 commented on May 19, 2024

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.

segabor avatar segabor commented on May 19, 2024

I can confirm the fix above works. @iain17 thanks!

from swiftsocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.