Have you followed this tutorial?
http://www.theballthegame.com/tutorialudk.htm
Then you add these tcplink scripts in your project.
In my project I've another c++ program that can send messages to udk via tcp/ip.
Here's the code that send message to udk via tcp/ip.
Code:
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
#ifdef _EiC
#define WIN32
#endif
//using namespace std;
#define HISTORY_LENGTH 5
#define DEFAULT_BUFLEN 512
#define DEFAULT_PORT "3742"
#define DEFAULT_SERVER_IP "127.0.0.1"
WSADATA wsaData;
SOCKET ConnectSocket = INVALID_SOCKET;
int SocketInit();
int main(int argc, char** argv )
{
SocketInit();
int iResult = 0;
char sendbuf[512] = "CuteValue;1.0";
iResult = send(ConnectSocket, sendbuf, (int) strlen(sendbuf), 0);
if (iResult == SOCKET_ERROR) {
printf("send failed: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
}
return 0;
}
int SocketInit()
{
int iResult;
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0) {
printf("WSAStartup failed: %d\n", iResult);
return 0;
}
else
{
printf("WSAStartup succeeded: %d\n", iResult);
}
struct addrinfo *result = NULL,
*ptr = NULL,
hints;
ZeroMemory( &hints, sizeof(hints) );
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
// Resolve the server address and port
iResult = getaddrinfo(DEFAULT_SERVER_IP, DEFAULT_PORT, &hints, &result);
if (iResult != 0) {
printf("getaddrinfo failed: %d\n", iResult);
WSACleanup();
return 0;
}
else
printf("getaddrinfo succeeded: %d\n", iResult);
// Attempt to connect to the first address returned by
// the call to getaddrinfo
ptr=result;
// Create a SOCKET for connecting to server
ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype,
ptr->ai_protocol);
if (ConnectSocket == INVALID_SOCKET) {
printf("Error at socket(): %ld\n", WSAGetLastError());
freeaddrinfo(result);
WSACleanup();
return 1;
}
// Connect to server.
iResult = connect( ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
if (iResult == SOCKET_ERROR) {
closesocket(ConnectSocket);
ConnectSocket = INVALID_SOCKET;
}
// Should really try the next address returned by getaddrinfo
// if the connect call failed
// But for this simple example we just free the resources
// returned by getaddrinfo and print an error message
freeaddrinfo(result);
if (ConnectSocket == INVALID_SOCKET) {
printf("Unable to connect to server!\n");
WSACleanup();
getchar();
return 1;
}
//int recvbuflen = DEFAULT_BUFLEN;
return 1;
}
change default port to the one specified in tcpserver script under default properties section and server ip to the ip of the pc running udk server.
u will also need to put WS2_32.lib odbc32.lib odbccp32.lib those static libs to linker input section.
and somewhere in your udk playercontroller script or some initialization script, spawn that tcp server class to start listening incoming message.
Code:
//declare TcpLinkServer
var TcpLinkServer tcpLinkServer;
simulated function PostBeginPlay()
{
//spawn and init the class
tcpLinkServer = spawn(class'TcpLinkServer');
tcpLinkServer.TcpLinkInit();
}
Bookmarks